Skip to content

Commit e6e5481

Browse files
committed
Fix nitpicks for new way to find current script
Related: #496
1 parent 153448d commit e6e5481

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

client/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ var SockJS = require("sockjs-client");
33
var stripAnsi = require('strip-ansi');
44

55
function getCurrentScriptSource() {
6-
// try to get the current script
7-
if (document.currentScript) {
6+
// `document.currentScript` is the most accurate way to find the current script,
7+
// but is not supported in all browsers.
8+
if(document.currentScript)
89
return document.currentScript.getAttribute("src");
9-
}
10-
// fall back to getting all scripts in the document
11-
var scriptElements = document.scripts || [],
12-
currentScript = scriptElements[scriptElements.length - 1];
13-
if (currentScript) {
10+
// Fall back to getting all scripts in the document.
11+
var scriptElements = document.scripts || [];
12+
var currentScript = scriptElements[scriptElements.length - 1];
13+
if (currentScript)
1414
return currentScript.getAttribute("src");
15-
}
16-
// fail as there was no script to use
17-
throw new Error("Failed to get current script source");
15+
// Fail as there was no script to use.
16+
throw new Error("[WDS] Failed to get current script source");
1817
}
1918

2019
var urlParts;

0 commit comments

Comments
 (0)