UNPKG

658 BJavaScriptView Raw
1'use strict';
2
3function getCurrentScriptSource() {
4 // `document.currentScript` is the most accurate way to find the current script,
5 // but is not supported in all browsers.
6 if (document.currentScript) {
7 return document.currentScript.getAttribute('src');
8 } // Fall back to getting all scripts in the document.
9
10
11 var scriptElements = document.scripts || [];
12 var currentScript = scriptElements[scriptElements.length - 1];
13
14 if (currentScript) {
15 return currentScript.getAttribute('src');
16 } // Fail as there was no script to use.
17
18
19 throw new Error('[WDS] Failed to get current script source.');
20}
21
22module.exports = getCurrentScriptSource;
\No newline at end of file