wxt 0.20.13 → 0.20.15
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.
- package/dist/browser.d.mts +20 -0
- package/dist/browser.mjs +18 -3
- package/dist/builtin-modules/index.mjs +7 -2
- package/dist/builtin-modules/unimport.mjs +69 -75
- package/dist/cli/cli-utils.mjs +54 -50
- package/dist/cli/commands.mjs +78 -103
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +9 -4
- package/dist/core/{build.d.ts → build.d.mts} +6 -2
- package/dist/core/build.mjs +23 -4
- package/dist/core/builders/vite/index.mjs +293 -343
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +11 -12
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +27 -20
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +17 -12
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +105 -136
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -14
- package/dist/core/builders/vite/plugins/download.mjs +23 -12
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +18 -14
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +31 -33
- package/dist/core/builders/vite/plugins/globals.mjs +14 -13
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +17 -11
- package/dist/core/builders/vite/plugins/index.mjs +18 -16
- package/dist/core/builders/vite/plugins/noopBackground.mjs +21 -15
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +26 -23
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -24
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +28 -26
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +11 -11
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +42 -47
- package/dist/core/{clean.d.ts → clean.d.mts} +7 -3
- package/dist/core/clean.mjs +38 -35
- package/dist/core/{create-server.d.ts → create-server.d.mts} +6 -2
- package/dist/core/create-server.mjs +236 -247
- package/dist/core/define-config.d.mts +6 -0
- package/dist/core/define-config.mjs +6 -2
- package/dist/core/define-web-ext-config.d.mts +13 -0
- package/dist/core/define-web-ext-config.mjs +16 -7
- package/dist/core/generate-wxt-dir.mjs +110 -148
- package/dist/core/index.d.mts +9 -0
- package/dist/core/index.mjs +12 -8
- package/dist/core/initialize.d.mts +8 -0
- package/dist/core/initialize.mjs +110 -124
- package/dist/core/keyboard-shortcuts.mjs +30 -28
- package/dist/core/package-managers/bun.mjs +18 -16
- package/dist/core/package-managers/deno.mjs +12 -8
- package/dist/core/package-managers/index.mjs +52 -60
- package/dist/core/package-managers/npm.mjs +51 -52
- package/dist/core/package-managers/pnpm.mjs +21 -18
- package/dist/core/package-managers/yarn.mjs +31 -28
- package/dist/core/prepare.d.mts +6 -0
- package/dist/core/prepare.mjs +12 -7
- package/dist/core/resolve-config.mjs +393 -462
- package/dist/core/runners/index.mjs +15 -10
- package/dist/core/runners/manual.mjs +13 -14
- package/dist/core/runners/safari.mjs +13 -14
- package/dist/core/runners/web-ext.mjs +62 -83
- package/dist/core/runners/wsl.mjs +13 -14
- package/dist/core/utils/arrays.mjs +23 -12
- package/dist/core/utils/building/build-entrypoints.mjs +44 -40
- package/dist/core/utils/building/detect-dev-changes.mjs +84 -105
- package/dist/core/utils/building/find-entrypoints.mjs +278 -359
- package/dist/core/utils/building/group-entrypoints.mjs +42 -35
- package/dist/core/utils/building/index.mjs +8 -6
- package/dist/core/utils/building/internal-build.mjs +86 -102
- package/dist/core/utils/building/rebuild.mjs +50 -30
- package/dist/core/utils/cache.mjs +29 -18
- package/dist/core/utils/constants.mjs +9 -1
- package/dist/core/utils/content-scripts.mjs +56 -54
- package/dist/core/utils/content-security-policy.mjs +36 -39
- package/dist/core/utils/entrypoints.mjs +51 -28
- package/dist/core/utils/env.mjs +22 -17
- package/dist/core/utils/environments/browser-environment.mjs +13 -12
- package/dist/core/utils/environments/environment.mjs +36 -33
- package/dist/core/utils/environments/extension-environment.mjs +15 -10
- package/dist/core/utils/environments/index.mjs +4 -2
- package/dist/core/utils/eslint.mjs +11 -10
- package/dist/core/utils/fs.mjs +23 -11
- package/dist/core/utils/globals.mjs +53 -51
- package/dist/core/utils/i18n.mjs +41 -32
- package/dist/core/utils/index.mjs +3 -0
- package/dist/core/utils/log/index.mjs +6 -4
- package/dist/core/utils/log/printBuildSummary.mjs +20 -25
- package/dist/core/utils/log/printFileList.mjs +30 -33
- package/dist/core/utils/log/printHeader.mjs +9 -5
- package/dist/core/utils/log/printTable.mjs +19 -21
- package/dist/core/utils/manifest.mjs +366 -479
- package/dist/core/utils/minimatch-multiple.mjs +26 -15
- package/dist/core/utils/network.mjs +27 -33
- package/dist/core/utils/number.mjs +7 -3
- package/dist/core/utils/package.mjs +20 -13
- package/dist/core/utils/paths.d.mts +8 -0
- package/dist/core/utils/paths.mjs +26 -7
- package/dist/core/utils/strings.mjs +19 -14
- package/dist/core/utils/syntax-errors.mjs +14 -16
- package/dist/core/utils/time.mjs +19 -15
- package/dist/core/utils/transform.mjs +129 -160
- package/dist/core/utils/types.d.mts +6 -0
- package/dist/core/utils/validation.mjs +43 -50
- package/dist/core/utils/virtual-modules.mjs +20 -12
- package/dist/core/utils/wsl.mjs +11 -3
- package/dist/core/wxt.mjs +65 -60
- package/dist/core/{zip.d.ts → zip.d.mts} +6 -2
- package/dist/core/zip.mjs +118 -140
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +13 -3
- package/dist/{modules.d.ts → modules.d.mts} +14 -16
- package/dist/modules.mjs +179 -51
- package/dist/testing/fake-browser.d.mts +2 -0
- package/dist/testing/fake-browser.mjs +3 -1
- package/dist/testing/index.d.mts +3 -0
- package/dist/testing/index.mjs +4 -2
- package/dist/testing/{wxt-vitest-plugin.d.ts → wxt-vitest-plugin.d.mts} +7 -9
- package/dist/testing/wxt-vitest-plugin.mjs +38 -19
- package/dist/types.d.mts +1475 -0
- package/dist/utils/app-config.d.mts +6 -0
- package/dist/utils/app-config.mjs +8 -2
- package/dist/utils/content-script-context.d.mts +134 -0
- package/dist/utils/content-script-context.mjs +187 -175
- package/dist/utils/content-script-ui/iframe.d.mts +42 -0
- package/dist/utils/content-script-ui/iframe.mjs +42 -27
- package/dist/utils/content-script-ui/integrated.d.mts +37 -0
- package/dist/utils/content-script-ui/integrated.mjs +36 -29
- package/dist/utils/content-script-ui/shadow-root.d.mts +80 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +75 -82
- package/dist/utils/content-script-ui/shared.mjs +115 -150
- package/dist/utils/content-script-ui/types.d.mts +107 -0
- package/dist/utils/content-script-ui/types.mjs +1 -0
- package/dist/utils/{define-app-config.d.ts → define-app-config.d.mts} +5 -3
- package/dist/utils/define-app-config.mjs +22 -2
- package/dist/utils/define-background.d.mts +7 -0
- package/dist/utils/define-background.mjs +7 -3
- package/dist/utils/define-content-script.d.mts +6 -0
- package/dist/utils/define-content-script.mjs +6 -2
- package/dist/utils/define-unlisted-script.d.mts +7 -0
- package/dist/utils/define-unlisted-script.mjs +7 -3
- package/dist/utils/define-wxt-plugin.d.mts +6 -0
- package/dist/utils/define-wxt-plugin.mjs +6 -2
- package/dist/utils/inject-script.d.mts +41 -0
- package/dist/utils/inject-script.mjs +44 -34
- package/dist/utils/internal/custom-events.d.mts +9 -0
- package/dist/utils/internal/custom-events.mjs +18 -10
- package/dist/utils/internal/location-watcher.mjs +23 -20
- package/dist/utils/internal/logger.mjs +15 -12
- package/dist/utils/match-patterns.d.mts +1 -0
- package/dist/utils/match-patterns.mjs +3 -1
- package/dist/utils/{split-shadow-root-css.d.ts → split-shadow-root-css.d.mts} +6 -3
- package/dist/utils/split-shadow-root-css.mjs +16 -7
- package/dist/utils/storage.d.mts +1 -0
- package/dist/utils/storage.mjs +3 -1
- package/dist/version.d.mts +4 -0
- package/dist/version.mjs +5 -1
- package/dist/virtual/background-entrypoint.d.mts +4 -0
- package/dist/virtual/background-entrypoint.mjs +143 -161
- package/dist/virtual/content-script-isolated-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +26 -27
- package/dist/virtual/content-script-main-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-main-world-entrypoint.mjs +24 -24
- package/dist/virtual/mock-browser.d.mts +6 -0
- package/dist/virtual/mock-browser.mjs +5 -3
- package/dist/virtual/reload-html.d.mts +1 -0
- package/dist/virtual/reload-html.mjs +57 -53
- package/dist/virtual/unlisted-script-entrypoint.d.mts +4 -0
- package/dist/virtual/unlisted-script-entrypoint.mjs +35 -43
- package/package.json +56 -50
- package/dist/browser.d.ts +0 -30
- package/dist/builtin-modules/index.d.ts +0 -2
- package/dist/builtin-modules/unimport.d.ts +0 -5
- package/dist/cli/cli-utils.d.ts +0 -25
- package/dist/cli/commands.d.ts +0 -2
- package/dist/cli/index.d.ts +0 -1
- package/dist/core/builders/vite/index.d.ts +0 -7
- package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +0 -7
- package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +0 -13
- package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +0 -14
- package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +0 -7
- package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/download.d.ts +0 -10
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +0 -6
- package/dist/core/builders/vite/plugins/globals.d.ts +0 -3
- package/dist/core/builders/vite/plugins/iifeFooter.d.ts +0 -8
- package/dist/core/builders/vite/plugins/index.d.ts +0 -16
- package/dist/core/builders/vite/plugins/noopBackground.d.ts +0 -6
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +0 -6
- package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +0 -3
- package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +0 -6
- package/dist/core/define-config.d.ts +0 -2
- package/dist/core/define-web-ext-config.d.ts +0 -9
- package/dist/core/generate-wxt-dir.d.ts +0 -5
- package/dist/core/index.d.ts +0 -8
- package/dist/core/initialize.d.ts +0 -5
- package/dist/core/keyboard-shortcuts.d.ts +0 -12
- package/dist/core/package-managers/bun.d.ts +0 -2
- package/dist/core/package-managers/deno.d.ts +0 -2
- package/dist/core/package-managers/index.d.ts +0 -2
- package/dist/core/package-managers/npm.d.ts +0 -17
- package/dist/core/package-managers/pnpm.d.ts +0 -2
- package/dist/core/package-managers/types.d.ts +0 -2
- package/dist/core/package-managers/types.mjs +0 -0
- package/dist/core/package-managers/yarn.d.ts +0 -2
- package/dist/core/prepare.d.ts +0 -2
- package/dist/core/resolve-config.d.ts +0 -11
- package/dist/core/runners/index.d.ts +0 -2
- package/dist/core/runners/manual.d.ts +0 -5
- package/dist/core/runners/safari.d.ts +0 -5
- package/dist/core/runners/web-ext.d.ts +0 -5
- package/dist/core/runners/wsl.d.ts +0 -5
- package/dist/core/utils/arrays.d.ts +0 -13
- package/dist/core/utils/building/build-entrypoints.d.ts +0 -3
- package/dist/core/utils/building/detect-dev-changes.d.ts +0 -61
- package/dist/core/utils/building/find-entrypoints.d.ts +0 -5
- package/dist/core/utils/building/group-entrypoints.d.ts +0 -8
- package/dist/core/utils/building/index.d.ts +0 -6
- package/dist/core/utils/building/internal-build.d.ts +0 -12
- package/dist/core/utils/building/rebuild.d.ts +0 -23
- package/dist/core/utils/cache.d.ts +0 -8
- package/dist/core/utils/cli.d.ts +0 -3
- package/dist/core/utils/cli.mjs +0 -26
- package/dist/core/utils/constants.d.ts +0 -5
- package/dist/core/utils/content-scripts.d.ts +0 -12
- package/dist/core/utils/content-security-policy.d.ts +0 -14
- package/dist/core/utils/entrypoints.d.ts +0 -31
- package/dist/core/utils/env.d.ts +0 -5
- package/dist/core/utils/environments/browser-environment.d.ts +0 -3
- package/dist/core/utils/environments/environment.d.ts +0 -8
- package/dist/core/utils/environments/extension-environment.d.ts +0 -6
- package/dist/core/utils/environments/index.d.ts +0 -2
- package/dist/core/utils/eslint.d.ts +0 -1
- package/dist/core/utils/fs.d.ts +0 -13
- package/dist/core/utils/globals.d.ts +0 -11
- package/dist/core/utils/i18n.d.ts +0 -11
- package/dist/core/utils/log/index.d.ts +0 -4
- package/dist/core/utils/log/printBuildSummary.d.ts +0 -2
- package/dist/core/utils/log/printFileList.d.ts +0 -1
- package/dist/core/utils/log/printHeader.d.ts +0 -1
- package/dist/core/utils/log/printTable.d.ts +0 -1
- package/dist/core/utils/manifest.d.ts +0 -40
- package/dist/core/utils/minimatch-multiple.d.ts +0 -15
- package/dist/core/utils/network.d.ts +0 -7
- package/dist/core/utils/number.d.ts +0 -1
- package/dist/core/utils/package.d.ts +0 -6
- package/dist/core/utils/paths.d.ts +0 -11
- package/dist/core/utils/strings.d.ts +0 -14
- package/dist/core/utils/syntax-errors.d.ts +0 -11
- package/dist/core/utils/testing/fake-objects.d.ts +0 -11665
- package/dist/core/utils/testing/fake-objects.mjs +0 -326
- package/dist/core/utils/time.d.ts +0 -9
- package/dist/core/utils/transform.d.ts +0 -11
- package/dist/core/utils/types.d.ts +0 -13
- package/dist/core/utils/types.mjs +0 -0
- package/dist/core/utils/validation.d.ts +0 -15
- package/dist/core/utils/virtual-modules.d.ts +0 -22
- package/dist/core/utils/wsl.d.ts +0 -4
- package/dist/core/wxt.d.ts +0 -24
- package/dist/index.d.ts +0 -11
- package/dist/testing/fake-browser.d.ts +0 -10
- package/dist/testing/index.d.ts +0 -10
- package/dist/types.d.ts +0 -1459
- package/dist/types.mjs +0 -0
- package/dist/utils/app-config.d.ts +0 -2
- package/dist/utils/content-script-context.d.ts +0 -134
- package/dist/utils/content-script-ui/iframe.d.ts +0 -32
- package/dist/utils/content-script-ui/integrated.d.ts +0 -34
- package/dist/utils/content-script-ui/shadow-root.d.ts +0 -76
- package/dist/utils/content-script-ui/shared.d.ts +0 -5
- package/dist/utils/content-script-ui/types.d.ts +0 -104
- package/dist/utils/define-background.d.ts +0 -4
- package/dist/utils/define-content-script.d.ts +0 -3
- package/dist/utils/define-unlisted-script.d.ts +0 -4
- package/dist/utils/define-wxt-plugin.d.ts +0 -3
- package/dist/utils/inject-script.d.ts +0 -36
- package/dist/utils/internal/custom-events.d.ts +0 -10
- package/dist/utils/internal/dev-server-websocket.d.ts +0 -21
- package/dist/utils/internal/dev-server-websocket.mjs +0 -37
- package/dist/utils/internal/location-watcher.d.ts +0 -12
- package/dist/utils/internal/logger.d.ts +0 -9
- package/dist/utils/match-patterns.d.ts +0 -5
- package/dist/utils/storage.d.ts +0 -5
- package/dist/version.d.ts +0 -1
|
@@ -1,193 +1,175 @@
|
|
|
1
|
-
import definition from
|
|
2
|
-
import { initPlugins } from
|
|
3
|
-
import { browser } from
|
|
4
|
-
import { MatchPattern } from
|
|
1
|
+
import definition from "virtual:user-background-entrypoint";
|
|
2
|
+
import { initPlugins } from "virtual:wxt-plugins";
|
|
3
|
+
import { browser } from "wxt/browser";
|
|
4
|
+
import { MatchPattern } from "wxt/utils/match-patterns";
|
|
5
5
|
|
|
6
|
+
//#region src/utils/internal/logger.ts
|
|
6
7
|
function print(method, ...args) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
method(`[wxt] ${message}`, ...args);
|
|
11
|
-
} else {
|
|
12
|
-
method("[wxt]", ...args);
|
|
13
|
-
}
|
|
8
|
+
if (import.meta.env.MODE === "production") return;
|
|
9
|
+
if (typeof args[0] === "string") method(`[wxt] ${args.shift()}`, ...args);
|
|
10
|
+
else method("[wxt]", ...args);
|
|
14
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper around `console` with a "[wxt]" prefix
|
|
14
|
+
*/
|
|
15
15
|
const logger = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
debug: (...args) => print(console.debug, ...args),
|
|
17
|
+
log: (...args) => print(console.log, ...args),
|
|
18
|
+
warn: (...args) => print(console.warn, ...args),
|
|
19
|
+
error: (...args) => print(console.error, ...args)
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/utils/internal/dev-server-websocket.ts
|
|
22
24
|
let ws;
|
|
25
|
+
/**
|
|
26
|
+
* Connect to the websocket and listen for messages.
|
|
27
|
+
*/
|
|
23
28
|
function getDevServerWebSocket() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return ws;
|
|
29
|
+
if (import.meta.env.COMMAND !== "serve") throw Error("Must be running WXT dev command to connect to call getDevServerWebSocket()");
|
|
30
|
+
if (ws == null) {
|
|
31
|
+
const serverUrl = __DEV_SERVER_ORIGIN__;
|
|
32
|
+
logger.debug("Connecting to dev server @", serverUrl);
|
|
33
|
+
ws = new WebSocket(serverUrl, "vite-hmr");
|
|
34
|
+
ws.addWxtEventListener = ws.addEventListener.bind(ws);
|
|
35
|
+
ws.sendCustom = (event, payload) => ws?.send(JSON.stringify({
|
|
36
|
+
type: "custom",
|
|
37
|
+
event,
|
|
38
|
+
payload
|
|
39
|
+
}));
|
|
40
|
+
ws.addEventListener("open", () => {
|
|
41
|
+
logger.debug("Connected to dev server");
|
|
42
|
+
});
|
|
43
|
+
ws.addEventListener("close", () => {
|
|
44
|
+
logger.debug("Disconnected from dev server");
|
|
45
|
+
});
|
|
46
|
+
ws.addEventListener("error", (event) => {
|
|
47
|
+
logger.error("Failed to connect to dev server", event);
|
|
48
|
+
});
|
|
49
|
+
ws.addEventListener("message", (e) => {
|
|
50
|
+
try {
|
|
51
|
+
const message = JSON.parse(e.data);
|
|
52
|
+
if (message.type === "custom") ws?.dispatchEvent(new CustomEvent(message.event, { detail: message.data }));
|
|
53
|
+
} catch (err) {
|
|
54
|
+
logger.error("Failed to handle message", err);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return ws;
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/virtual/utils/keep-service-worker-alive.ts
|
|
63
|
+
/**
|
|
64
|
+
* https://developer.chrome.com/blog/longer-esw-lifetimes/
|
|
65
|
+
*/
|
|
59
66
|
function keepServiceWorkerAlive() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
setInterval(async () => {
|
|
68
|
+
await browser.runtime.getPlatformInfo();
|
|
69
|
+
}, 5e3);
|
|
63
70
|
}
|
|
64
71
|
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/virtual/utils/reload-content-scripts.ts
|
|
65
74
|
function reloadContentScript(payload) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
void reloadContentScriptMv2();
|
|
69
|
-
} else {
|
|
70
|
-
void reloadContentScriptMv3(payload);
|
|
71
|
-
}
|
|
75
|
+
if (browser.runtime.getManifest().manifest_version == 2) reloadContentScriptMv2(payload);
|
|
76
|
+
else reloadContentScriptMv3(payload);
|
|
72
77
|
}
|
|
73
|
-
async function reloadContentScriptMv3({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}) {
|
|
77
|
-
if (registration === "runtime") {
|
|
78
|
-
await reloadRuntimeContentScriptMv3(contentScript);
|
|
79
|
-
} else {
|
|
80
|
-
await reloadManifestContentScriptMv3(contentScript);
|
|
81
|
-
}
|
|
78
|
+
async function reloadContentScriptMv3({ registration, contentScript }) {
|
|
79
|
+
if (registration === "runtime") await reloadRuntimeContentScriptMv3(contentScript);
|
|
80
|
+
else await reloadManifestContentScriptMv3(contentScript);
|
|
82
81
|
}
|
|
83
82
|
async function reloadManifestContentScriptMv3(contentScript) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
]);
|
|
107
|
-
}
|
|
108
|
-
await reloadTabsForContentScript(contentScript);
|
|
83
|
+
const id = `wxt:${contentScript.js[0]}`;
|
|
84
|
+
logger.log("Reloading content script:", contentScript);
|
|
85
|
+
const registered = await browser.scripting.getRegisteredContentScripts();
|
|
86
|
+
logger.debug("Existing scripts:", registered);
|
|
87
|
+
const existing = registered.find((cs) => cs.id === id);
|
|
88
|
+
if (existing) {
|
|
89
|
+
logger.debug("Updating content script", existing);
|
|
90
|
+
await browser.scripting.updateContentScripts([{
|
|
91
|
+
...contentScript,
|
|
92
|
+
id,
|
|
93
|
+
css: contentScript.css ?? []
|
|
94
|
+
}]);
|
|
95
|
+
} else {
|
|
96
|
+
logger.debug("Registering new content script...");
|
|
97
|
+
await browser.scripting.registerContentScripts([{
|
|
98
|
+
...contentScript,
|
|
99
|
+
id,
|
|
100
|
+
css: contentScript.css ?? []
|
|
101
|
+
}]);
|
|
102
|
+
}
|
|
103
|
+
await reloadTabsForContentScript(contentScript);
|
|
109
104
|
}
|
|
110
105
|
async function reloadRuntimeContentScriptMv3(contentScript) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
await browser.scripting.updateContentScripts(matches);
|
|
127
|
-
await reloadTabsForContentScript(contentScript);
|
|
106
|
+
logger.log("Reloading content script:", contentScript);
|
|
107
|
+
const registered = await browser.scripting.getRegisteredContentScripts();
|
|
108
|
+
logger.debug("Existing scripts:", registered);
|
|
109
|
+
const matches = registered.filter((cs) => {
|
|
110
|
+
const hasJs = contentScript.js?.find((js) => cs.js?.includes(js));
|
|
111
|
+
const hasCss = contentScript.css?.find((css) => cs.css?.includes(css));
|
|
112
|
+
return hasJs || hasCss;
|
|
113
|
+
});
|
|
114
|
+
if (matches.length === 0) {
|
|
115
|
+
logger.log("Content script is not registered yet, nothing to reload", contentScript);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
await browser.scripting.updateContentScripts(matches);
|
|
119
|
+
await reloadTabsForContentScript(contentScript);
|
|
128
120
|
}
|
|
129
121
|
async function reloadTabsForContentScript(contentScript) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
logger.warn("Failed to reload tab:", err);
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
);
|
|
122
|
+
const allTabs = await browser.tabs.query({});
|
|
123
|
+
const matchPatterns = contentScript.matches.map((match) => new MatchPattern(match));
|
|
124
|
+
const matchingTabs = allTabs.filter((tab) => {
|
|
125
|
+
const url = tab.url;
|
|
126
|
+
if (!url) return false;
|
|
127
|
+
return !!matchPatterns.find((pattern) => pattern.includes(url));
|
|
128
|
+
});
|
|
129
|
+
await Promise.all(matchingTabs.map(async (tab) => {
|
|
130
|
+
try {
|
|
131
|
+
await browser.tabs.reload(tab.id);
|
|
132
|
+
} catch (err) {
|
|
133
|
+
logger.warn("Failed to reload tab:", err);
|
|
134
|
+
}
|
|
135
|
+
}));
|
|
148
136
|
}
|
|
149
137
|
async function reloadContentScriptMv2(_payload) {
|
|
150
|
-
|
|
138
|
+
throw Error("TODO: reloadContentScriptMv2");
|
|
151
139
|
}
|
|
152
140
|
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/virtual/background-entrypoint.ts
|
|
153
143
|
if (import.meta.env.COMMAND === "serve") {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
browser.commands.onCommand.addListener((command) => {
|
|
173
|
-
if (command === "wxt:reload-extension") {
|
|
174
|
-
browser.runtime.reload();
|
|
175
|
-
}
|
|
176
|
-
});
|
|
144
|
+
try {
|
|
145
|
+
const ws = getDevServerWebSocket();
|
|
146
|
+
ws.addWxtEventListener("wxt:reload-extension", () => {
|
|
147
|
+
browser.runtime.reload();
|
|
148
|
+
});
|
|
149
|
+
ws.addWxtEventListener("wxt:reload-content-script", (event) => {
|
|
150
|
+
reloadContentScript(event.detail);
|
|
151
|
+
});
|
|
152
|
+
if (import.meta.env.MANIFEST_VERSION === 3) {
|
|
153
|
+
ws.addEventListener("open", () => ws.sendCustom("wxt:background-initialized"));
|
|
154
|
+
keepServiceWorkerAlive();
|
|
155
|
+
}
|
|
156
|
+
} catch (err) {
|
|
157
|
+
logger.error("Failed to setup web socket connection with dev server", err);
|
|
158
|
+
}
|
|
159
|
+
browser.commands.onCommand.addListener((command) => {
|
|
160
|
+
if (command === "wxt:reload-extension") browser.runtime.reload();
|
|
161
|
+
});
|
|
177
162
|
}
|
|
178
163
|
let result;
|
|
179
164
|
try {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
console.warn(
|
|
184
|
-
"The background's main() function return a promise, but it must be synchronous"
|
|
185
|
-
);
|
|
186
|
-
}
|
|
165
|
+
initPlugins();
|
|
166
|
+
result = definition.main();
|
|
167
|
+
if (result instanceof Promise) console.warn("The background's main() function return a promise, but it must be synchronous");
|
|
187
168
|
} catch (err) {
|
|
188
|
-
|
|
189
|
-
|
|
169
|
+
logger.error("The background crashed on startup!");
|
|
170
|
+
throw err;
|
|
190
171
|
}
|
|
191
|
-
|
|
172
|
+
var background_entrypoint_default = result;
|
|
192
173
|
|
|
193
|
-
|
|
174
|
+
//#endregion
|
|
175
|
+
export { background_entrypoint_default as default };
|
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import definition from
|
|
2
|
-
import { ContentScriptContext } from
|
|
3
|
-
import { initPlugins } from
|
|
1
|
+
import definition from "virtual:user-content-script-isolated-world-entrypoint";
|
|
2
|
+
import { ContentScriptContext } from "wxt/utils/content-script-context";
|
|
3
|
+
import { initPlugins } from "virtual:wxt-plugins";
|
|
4
4
|
|
|
5
|
+
//#region src/utils/internal/logger.ts
|
|
5
6
|
function print(method, ...args) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
method(`[wxt] ${message}`, ...args);
|
|
10
|
-
} else {
|
|
11
|
-
method("[wxt]", ...args);
|
|
12
|
-
}
|
|
7
|
+
if (import.meta.env.MODE === "production") return;
|
|
8
|
+
if (typeof args[0] === "string") method(`[wxt] ${args.shift()}`, ...args);
|
|
9
|
+
else method("[wxt]", ...args);
|
|
13
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Wrapper around `console` with a "[wxt]" prefix
|
|
13
|
+
*/
|
|
14
14
|
const logger = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
debug: (...args) => print(console.debug, ...args),
|
|
16
|
+
log: (...args) => print(console.log, ...args),
|
|
17
|
+
warn: (...args) => print(console.warn, ...args),
|
|
18
|
+
error: (...args) => print(console.error, ...args)
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/virtual/content-script-isolated-world-entrypoint.ts
|
|
21
23
|
const result = (async () => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
err
|
|
31
|
-
);
|
|
32
|
-
throw err;
|
|
33
|
-
}
|
|
24
|
+
try {
|
|
25
|
+
initPlugins();
|
|
26
|
+
const { main, ...options } = definition;
|
|
27
|
+
return await main(new ContentScriptContext(import.meta.env.ENTRYPOINT, options));
|
|
28
|
+
} catch (err) {
|
|
29
|
+
logger.error(`The content script "${import.meta.env.ENTRYPOINT}" crashed on startup!`, err);
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
34
32
|
})();
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
export { result as default };
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import definition from
|
|
2
|
-
import { initPlugins } from
|
|
1
|
+
import definition from "virtual:user-content-script-main-world-entrypoint";
|
|
2
|
+
import { initPlugins } from "virtual:wxt-plugins";
|
|
3
3
|
|
|
4
|
+
//#region src/utils/internal/logger.ts
|
|
4
5
|
function print(method, ...args) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
method(`[wxt] ${message}`, ...args);
|
|
9
|
-
} else {
|
|
10
|
-
method("[wxt]", ...args);
|
|
11
|
-
}
|
|
6
|
+
if (import.meta.env.MODE === "production") return;
|
|
7
|
+
if (typeof args[0] === "string") method(`[wxt] ${args.shift()}`, ...args);
|
|
8
|
+
else method("[wxt]", ...args);
|
|
12
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Wrapper around `console` with a "[wxt]" prefix
|
|
12
|
+
*/
|
|
13
13
|
const logger = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
debug: (...args) => print(console.debug, ...args),
|
|
15
|
+
log: (...args) => print(console.log, ...args),
|
|
16
|
+
warn: (...args) => print(console.warn, ...args),
|
|
17
|
+
error: (...args) => print(console.error, ...args)
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/virtual/content-script-main-world-entrypoint.ts
|
|
20
22
|
const result = (async () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
throw err;
|
|
30
|
-
}
|
|
23
|
+
try {
|
|
24
|
+
initPlugins();
|
|
25
|
+
return await definition.main();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
logger.error(`The content script "${import.meta.env.ENTRYPOINT}" crashed on startup!`, err);
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
31
30
|
})();
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
//#endregion
|
|
33
|
+
export { result as default };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { fakeBrowser } from
|
|
2
|
-
export { fakeBrowser as default } from 'wxt/testing';
|
|
1
|
+
import { fakeBrowser } from "wxt/testing";
|
|
3
2
|
|
|
3
|
+
//#region src/virtual/mock-browser.ts
|
|
4
4
|
const browser = fakeBrowser;
|
|
5
|
+
var mock_browser_default = fakeBrowser;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { browser, mock_browser_default as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,63 +1,67 @@
|
|
|
1
|
+
//#region src/utils/internal/logger.ts
|
|
1
2
|
function print(method, ...args) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
method(`[wxt] ${message}`, ...args);
|
|
6
|
-
} else {
|
|
7
|
-
method("[wxt]", ...args);
|
|
8
|
-
}
|
|
3
|
+
if (import.meta.env.MODE === "production") return;
|
|
4
|
+
if (typeof args[0] === "string") method(`[wxt] ${args.shift()}`, ...args);
|
|
5
|
+
else method("[wxt]", ...args);
|
|
9
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper around `console` with a "[wxt]" prefix
|
|
9
|
+
*/
|
|
10
10
|
const logger = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
debug: (...args) => print(console.debug, ...args),
|
|
12
|
+
log: (...args) => print(console.log, ...args),
|
|
13
|
+
warn: (...args) => print(console.warn, ...args),
|
|
14
|
+
error: (...args) => print(console.error, ...args)
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/utils/internal/dev-server-websocket.ts
|
|
17
19
|
let ws;
|
|
20
|
+
/**
|
|
21
|
+
* Connect to the websocket and listen for messages.
|
|
22
|
+
*/
|
|
18
23
|
function getDevServerWebSocket() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return ws;
|
|
24
|
+
if (import.meta.env.COMMAND !== "serve") throw Error("Must be running WXT dev command to connect to call getDevServerWebSocket()");
|
|
25
|
+
if (ws == null) {
|
|
26
|
+
const serverUrl = __DEV_SERVER_ORIGIN__;
|
|
27
|
+
logger.debug("Connecting to dev server @", serverUrl);
|
|
28
|
+
ws = new WebSocket(serverUrl, "vite-hmr");
|
|
29
|
+
ws.addWxtEventListener = ws.addEventListener.bind(ws);
|
|
30
|
+
ws.sendCustom = (event, payload) => ws?.send(JSON.stringify({
|
|
31
|
+
type: "custom",
|
|
32
|
+
event,
|
|
33
|
+
payload
|
|
34
|
+
}));
|
|
35
|
+
ws.addEventListener("open", () => {
|
|
36
|
+
logger.debug("Connected to dev server");
|
|
37
|
+
});
|
|
38
|
+
ws.addEventListener("close", () => {
|
|
39
|
+
logger.debug("Disconnected from dev server");
|
|
40
|
+
});
|
|
41
|
+
ws.addEventListener("error", (event) => {
|
|
42
|
+
logger.error("Failed to connect to dev server", event);
|
|
43
|
+
});
|
|
44
|
+
ws.addEventListener("message", (e) => {
|
|
45
|
+
try {
|
|
46
|
+
const message = JSON.parse(e.data);
|
|
47
|
+
if (message.type === "custom") ws?.dispatchEvent(new CustomEvent(message.event, { detail: message.data }));
|
|
48
|
+
} catch (err) {
|
|
49
|
+
logger.error("Failed to handle message", err);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return ws;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/virtual/reload-html.ts
|
|
58
|
+
if (import.meta.env.COMMAND === "serve") try {
|
|
59
|
+
getDevServerWebSocket().addWxtEventListener("wxt:reload-page", (event) => {
|
|
60
|
+
if (event.detail === location.pathname.substring(1)) location.reload();
|
|
61
|
+
});
|
|
62
|
+
} catch (err) {
|
|
63
|
+
logger.error("Failed to setup web socket connection with dev server", err);
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { };
|