MCPcopy
hub / github.com/webpack/webpack-dev-server / getCurrentScriptSource

Function getCurrentScriptSource

client-src/index.js:92–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

90 * @returns {string} current script source
91 */
92const getCurrentScriptSource = () => {
93 // `document.currentScript` is the most accurate way to find the current script,
94 // but is not supported in all browsers.
95 if (document.currentScript) {
96 return /** @type {string} */ (document.currentScript.getAttribute("src"));
97 }
98
99 // Fallback to getting all scripts running in the document.
100 const scriptElements = document.scripts || [];
101 const scriptElementsWithSrc = Array.prototype.filter.call(
102 scriptElements,
103 (element) => element.getAttribute("src"),
104 );
105
106 if (scriptElementsWithSrc.length > 0) {
107 const currentScript =
108 scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
109
110 return currentScript.getAttribute("src");
111 }
112
113 // Fail as there was no script to use.
114 throw new Error("[webpack-dev-server] Failed to get current script source.");
115};
116
117/** @typedef {{ hot?: string, ["live-reload"]?: string, progress?: string, reconnect?: string, logging?: LogLevel, overlay?: string, fromCurrentScript?: boolean }} AdditionalParsedURL */
118/** @typedef {Partial<URL> & AdditionalParsedURL} ParsedURL */

Callers 2

parseURLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…