You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
658 B

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