wxt 0.20.12 → 0.20.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -20,12 +20,8 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
20
20
|
const { config: loadedConfig, ...metadata } = await loadConfig({
|
|
21
21
|
configFile: inlineConfig.configFile,
|
|
22
22
|
name: "wxt",
|
|
23
|
-
cwd: inlineConfig.root ?? process.cwd()
|
|
24
|
-
rcFile: false
|
|
23
|
+
cwd: inlineConfig.root ?? process.cwd()
|
|
25
24
|
});
|
|
26
|
-
if (inlineConfig.configFile && metadata.layers?.length === 0) {
|
|
27
|
-
throw Error(`Config file "${inlineConfig.configFile}" not found`);
|
|
28
|
-
}
|
|
29
25
|
userConfig = loadedConfig ?? {};
|
|
30
26
|
userConfigMetadata = metadata;
|
|
31
27
|
}
|
|
@@ -7,12 +7,30 @@ export type ScriptPublicPath = Extract<import('wxt/browser').PublicPath, `${stri
|
|
|
7
7
|
*
|
|
8
8
|
* Make sure to add the injected script to your manifest's
|
|
9
9
|
* `web_accessible_resources`.
|
|
10
|
+
*
|
|
11
|
+
* @returns A result object containing the created script element.
|
|
10
12
|
*/
|
|
11
|
-
export declare function injectScript(path: ScriptPublicPath, options?: InjectScriptOptions): Promise<
|
|
13
|
+
export declare function injectScript(path: ScriptPublicPath, options?: InjectScriptOptions): Promise<InjectScriptResult>;
|
|
12
14
|
export interface InjectScriptOptions {
|
|
13
15
|
/**
|
|
14
16
|
* By default, the injected script is removed from the DOM after being
|
|
15
17
|
* injected. To disable this behavior, set this flag to true.
|
|
16
18
|
*/
|
|
17
19
|
keepInDom?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Modify the script element just before it is added to the DOM.
|
|
22
|
+
*
|
|
23
|
+
* It can be used to e.g. modify `script.async`/`script.defer`, add event
|
|
24
|
+
* listeners to the element, or pass data to the script via `script.dataset`
|
|
25
|
+
* (which can be accessed by the script via `document.currentScript`).
|
|
26
|
+
*/
|
|
27
|
+
modifyScript?: (script: HTMLScriptElement) => Promise<void> | void;
|
|
28
|
+
}
|
|
29
|
+
export interface InjectScriptResult {
|
|
30
|
+
/**
|
|
31
|
+
* The created script element. It can be used to e.g. send messages to the
|
|
32
|
+
* script in the form of custom events. The script can add an event listener
|
|
33
|
+
* for them via `document.currentScript`.
|
|
34
|
+
*/
|
|
35
|
+
script: HTMLScriptElement;
|
|
18
36
|
}
|
|
@@ -3,12 +3,36 @@ export async function injectScript(path, options) {
|
|
|
3
3
|
const url = browser.runtime.getURL(path);
|
|
4
4
|
const script = document.createElement("script");
|
|
5
5
|
if (browser.runtime.getManifest().manifest_version === 2) {
|
|
6
|
-
script.
|
|
6
|
+
script.text = await fetch(url).then((res) => res.text());
|
|
7
7
|
} else {
|
|
8
8
|
script.src = url;
|
|
9
9
|
}
|
|
10
|
+
const loadedPromise = makeLoadedPromise(script);
|
|
11
|
+
await options?.modifyScript?.(script);
|
|
12
|
+
(document.head ?? document.documentElement).append(script);
|
|
10
13
|
if (!options?.keepInDom) {
|
|
11
|
-
script.
|
|
14
|
+
script.remove();
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
await loadedPromise;
|
|
17
|
+
return {
|
|
18
|
+
script
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function makeLoadedPromise(script) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const onload = () => {
|
|
24
|
+
resolve();
|
|
25
|
+
cleanup();
|
|
26
|
+
};
|
|
27
|
+
const onerror = () => {
|
|
28
|
+
reject(new Error(`Failed to load script: ${script.src}`));
|
|
29
|
+
cleanup();
|
|
30
|
+
};
|
|
31
|
+
const cleanup = () => {
|
|
32
|
+
script.removeEventListener("load", onload);
|
|
33
|
+
script.removeEventListener("error", onerror);
|
|
34
|
+
};
|
|
35
|
+
script.addEventListener("load", onload);
|
|
36
|
+
script.addEventListener("error", onerror);
|
|
37
|
+
});
|
|
14
38
|
}
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.20.
|
|
1
|
+
export const version = "0.20.13";
|
|
@@ -17,10 +17,28 @@ const logger = {
|
|
|
17
17
|
error: (...args) => print(console.error, ...args)
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const result = (
|
|
20
|
+
const result = (() => {
|
|
21
21
|
try {
|
|
22
22
|
initPlugins();
|
|
23
|
-
|
|
23
|
+
} catch (err) {
|
|
24
|
+
logger.error(
|
|
25
|
+
`Failed to initialize plugins for "${import.meta.env.ENTRYPOINT}"`,
|
|
26
|
+
err
|
|
27
|
+
);
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
let result2;
|
|
31
|
+
try {
|
|
32
|
+
result2 = definition.main();
|
|
33
|
+
if (result2 instanceof Promise) {
|
|
34
|
+
result2 = result2.catch((err) => {
|
|
35
|
+
logger.error(
|
|
36
|
+
`The unlisted script "${import.meta.env.ENTRYPOINT}" crashed on startup!`,
|
|
37
|
+
err
|
|
38
|
+
);
|
|
39
|
+
throw err;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
24
42
|
} catch (err) {
|
|
25
43
|
logger.error(
|
|
26
44
|
`The unlisted script "${import.meta.env.ENTRYPOINT}" crashed on startup!`,
|
|
@@ -28,6 +46,7 @@ const result = (async () => {
|
|
|
28
46
|
);
|
|
29
47
|
throw err;
|
|
30
48
|
}
|
|
49
|
+
return result2;
|
|
31
50
|
})();
|
|
32
51
|
|
|
33
52
|
export { result as default };
|