Archived
1
0
This repository has been archived on 2023-05-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
home-page/node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/utils/getCurrentScriptSource.js
Sean Edmunds 0584430b5c First commit
2021-12-13 17:00:40 -06:00

23 lines
744 B
JavaScript

/**
* Gets the source (i.e. host) of the script currently running.
* @returns {string}
*/
function getCurrentScriptSource() {
// `document.currentScript` is the most accurate way to get the current running script,
// but is not supported in all browsers (most notably, IE).
if (document.currentScript) {
return document.currentScript.getAttribute('src');
}
// Fallback to getting all scripts running in the document.
const scriptElements = document.scripts || [];
const currentScript = scriptElements[scriptElements.length - 1];
if (currentScript) {
return currentScript.getAttribute('src');
}
throw new Error('[React Refresh] Failed to get current script source!');
}
module.exports = getCurrentScriptSource;