extension-develop 4.0.11 → 4.0.12
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/0~dev-server.mjs +1 -1
- package/dist/0~rspack-config.mjs +107 -3154
- package/dist/101.mjs +32 -4
- package/dist/266.mjs +1 -4
- package/dist/839.mjs +3156 -59
- package/dist/bridge-entry.d.ts +5 -0
- package/dist/command-build.d.ts +3 -0
- package/dist/command-dev.d.ts +5 -0
- package/dist/command-preview.d.ts +30 -0
- package/dist/dev-server/auto-exit.d.ts +1 -0
- package/dist/dev-server/cleanup.d.ts +11 -0
- package/dist/dev-server/compiler-hooks.d.ts +9 -0
- package/dist/dev-server/connectable-host.d.ts +2 -0
- package/dist/dev-server/control-bridge/actions-file.d.ts +38 -0
- package/dist/dev-server/control-bridge/broker.d.ts +122 -0
- package/dist/dev-server/control-bridge/consumer-client.d.ts +43 -0
- package/dist/dev-server/control-bridge/contracts.d.ts +164 -0
- package/dist/dev-server/control-bridge/control-port-store.d.ts +25 -0
- package/dist/dev-server/control-bridge/controller-client.d.ts +30 -0
- package/dist/dev-server/control-bridge/logs-file.d.ts +30 -0
- package/dist/dev-server/control-bridge/producer-runtime.d.ts +30 -0
- package/dist/dev-server/control-bridge/ring-buffer.d.ts +21 -0
- package/dist/dev-server/control-bridge/session-token.d.ts +18 -0
- package/dist/dev-server/control-bridge/ws-control-server.d.ts +13 -0
- package/dist/dev-server/frameworks.d.ts +2 -0
- package/dist/dev-server/index.d.ts +3 -0
- package/dist/dev-server/messages.d.ts +17 -0
- package/dist/dev-server/port-manager.d.ts +17 -0
- package/dist/extension-js-devtools/extension-js/chrome/events.ndjson +2 -6
- package/dist/extension-js-devtools/extension-js/chrome/ready.json +9 -6
- package/dist/extension-js-devtools/extension-js/chromium/events.ndjson +2 -6
- package/dist/extension-js-devtools/extension-js/chromium/ready.json +9 -6
- package/dist/extension-js-devtools/extension-js/edge/events.ndjson +2 -6
- package/dist/extension-js-devtools/extension-js/edge/ready.json +9 -6
- package/dist/extension-js-devtools/extension-js/firefox/events.ndjson +2 -6
- package/dist/extension-js-devtools/extension-js/firefox/ready.json +9 -6
- package/dist/extension-js-theme/extension-js/chrome/events.ndjson +2 -6
- package/dist/extension-js-theme/extension-js/chrome/ready.json +9 -6
- package/dist/extension-js-theme/extension-js/chromium/events.ndjson +2 -6
- package/dist/extension-js-theme/extension-js/chromium/ready.json +9 -6
- package/dist/extension-js-theme/extension-js/edge/events.ndjson +2 -6
- package/dist/extension-js-theme/extension-js/edge/ready.json +9 -6
- package/dist/extension-js-theme/extension-js/firefox/events.ndjson +2 -8
- package/dist/extension-js-theme/extension-js/firefox/ready.json +9 -6
- package/dist/lib/branding.d.ts +7 -0
- package/dist/lib/build-summary.d.ts +9 -0
- package/dist/lib/config-loader.d.ts +38 -0
- package/dist/lib/constants.d.ts +11 -0
- package/dist/lib/dark-mode.d.ts +9 -0
- package/dist/lib/dev-server-client-import.d.ts +4 -0
- package/dist/lib/develop-context.d.ts +3 -0
- package/dist/lib/ensure-develop-artifacts.d.ts +10 -0
- package/dist/lib/extensions-to-load.d.ts +1 -0
- package/dist/lib/generate-extension-types.d.ts +1 -0
- package/dist/lib/has-dependency.d.ts +6 -0
- package/dist/lib/manifest-utils.d.ts +2 -0
- package/dist/lib/messages.d.ts +55 -0
- package/dist/lib/optional-dependency-types.d.ts +14 -0
- package/dist/lib/optional-deps-contracts.d.ts +13 -0
- package/dist/lib/optional-deps-resolver.d.ts +41 -0
- package/dist/lib/package-json.d.ts +3 -0
- package/dist/lib/package-manager.d.ts +61 -0
- package/dist/lib/parse-json-safe.d.ts +13 -0
- package/dist/lib/paths.d.ts +19 -0
- package/dist/lib/project-manifest.d.ts +60 -0
- package/dist/lib/project.d.ts +7 -0
- package/dist/lib/resource-path.d.ts +4 -0
- package/dist/lib/rust-min-stack.d.ts +2 -0
- package/dist/lib/sanitize.d.ts +1 -0
- package/dist/lib/session-paths.d.ts +39 -0
- package/dist/lib/stats-handler.d.ts +1 -0
- package/dist/lib/transpile-packages.d.ts +7 -0
- package/dist/lib/validate-user-dependencies.d.ts +1 -0
- package/dist/lib/zip.d.ts +2 -0
- package/dist/module.d.ts +8 -0
- package/dist/plugin-browsers/index.d.ts +108 -0
- package/dist/plugin-browsers/safari-dev-plugin.d.ts +19 -0
- package/dist/plugin-compatibility/compatibility-lib/messages.d.ts +5 -0
- package/dist/plugin-compatibility/feature-polyfill.d.ts +11 -0
- package/dist/plugin-compatibility/index.d.ts +12 -0
- package/dist/plugin-compilation/boring.d.ts +11 -0
- package/dist/plugin-compilation/clean-dist.d.ts +8 -0
- package/dist/plugin-compilation/compilation-lib/messages.d.ts +11 -0
- package/dist/plugin-compilation/compilation-lib/shared-state.d.ts +7 -0
- package/dist/plugin-compilation/env.d.ts +17 -0
- package/dist/plugin-compilation/index.d.ts +22 -0
- package/dist/plugin-compilation/zip.d.ts +18 -0
- package/dist/plugin-css/common-style-loaders.d.ts +8 -0
- package/dist/plugin-css/css-in-content-script-loader.d.ts +4 -0
- package/dist/plugin-css/css-in-html-loader.d.ts +4 -0
- package/dist/plugin-css/css-lib/build-css-rules.d.ts +12 -0
- package/dist/plugin-css/css-lib/inject-css-link.d.ts +16 -0
- package/dist/plugin-css/css-lib/is-content-script.d.ts +1 -0
- package/dist/plugin-css/css-lib/messages.d.ts +9 -0
- package/dist/plugin-css/css-lib/resolve-css-asset.d.ts +21 -0
- package/dist/plugin-css/css-parse-guard-loader.d.ts +8 -0
- package/dist/plugin-css/css-tools/less.d.ts +7 -0
- package/dist/plugin-css/css-tools/postcss.d.ts +4 -0
- package/dist/plugin-css/css-tools/sass.d.ts +10 -0
- package/dist/plugin-css/css-tools/tailwind.d.ts +2 -0
- package/dist/plugin-css/index.d.ts +26 -0
- package/dist/plugin-css/preprocessor-passthrough-loader.d.ts +6 -0
- package/dist/plugin-js-frameworks/frameworks-lib/integrations.d.ts +4 -0
- package/dist/plugin-js-frameworks/index.d.ts +18 -0
- package/dist/plugin-js-frameworks/js-frameworks-lib/load-loader-options.d.ts +2 -0
- package/dist/plugin-js-frameworks/js-frameworks-lib/messages.d.ts +10 -0
- package/dist/plugin-js-frameworks/js-tools/preact.d.ts +3 -0
- package/dist/plugin-js-frameworks/js-tools/react.d.ts +8 -0
- package/dist/plugin-js-frameworks/js-tools/svelte.d.ts +4 -0
- package/dist/plugin-js-frameworks/js-tools/typescript.d.ts +37 -0
- package/dist/plugin-js-frameworks/js-tools/vue.d.ts +3 -0
- package/dist/plugin-perf-budgets/categorize.d.ts +3 -0
- package/dist/plugin-perf-budgets/index.d.ts +34 -0
- package/dist/plugin-perf-budgets/messages.d.ts +8 -0
- package/dist/plugin-playwright/index.d.ts +89 -0
- package/dist/plugin-reload/classify-reload.d.ts +86 -0
- package/dist/plugin-reload/index.d.ts +29 -0
- package/dist/plugin-reload/messages.d.ts +1 -0
- package/dist/plugin-reload/reload-dispatch.d.ts +46 -0
- package/dist/plugin-reload/reload-lib/minimum-files/minimum-background-file-chromium.d.ts +0 -0
- package/dist/plugin-reload/reload-lib/minimum-files/minimum-background-file-firefox.d.ts +0 -0
- package/dist/plugin-reload/reload-lib/scripts-replay-shim.d.ts +19 -0
- package/dist/plugin-reload/steps/inject-bridge-producer.d.ts +14 -0
- package/dist/plugin-reload/steps/inject-bridge-relay.d.ts +4 -0
- package/dist/plugin-reload/steps/inject-scripts-replay-shim.d.ts +10 -0
- package/dist/plugin-reload/steps/prune-stale-hot-updates.d.ts +20 -0
- package/dist/plugin-reload/steps/remove-content-script-dev-server-runtime.d.ts +2 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/index.d.ts +9 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/setup-background-entry.d.ts +13 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/index.d.ts +2 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/ChunkLoader.d.ts +9 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/HMRDevServer.d.ts +3 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/InitialChunkFile.d.ts +5 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/NoDangerNamePlugin.d.ts +3 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/AutoPublicPath.d.ts +2 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/BaseUri.d.ts +2 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/BrowserRuntime.d.ts +8 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/ChunkLoaderFallback.d.ts +1 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/EagerlyLoadChunks.d.ts +1 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/LoadScript.d.ts +4 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/PublicPath.d.ts +2 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/ServiceWorkerPlugin.d.ts +6 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/helper.d.ts +12 -0
- package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/index.d.ts +5 -0
- package/dist/plugin-reload/steps/strip-content-script-dev-server-runtime.d.ts +4 -0
- package/dist/plugin-special-folders/check-manifest-in-public.d.ts +2 -0
- package/dist/plugin-special-folders/emit-root-absolute-refs.d.ts +2 -0
- package/dist/plugin-special-folders/folder-extensions/resolve-config.d.ts +6 -0
- package/dist/plugin-special-folders/folder-extensions/resolve-dirs.d.ts +5 -0
- package/dist/plugin-special-folders/folder-extensions/types.d.ts +17 -0
- package/dist/plugin-special-folders/folder-extensions/utils.d.ts +9 -0
- package/dist/plugin-special-folders/get-data.d.ts +12 -0
- package/dist/plugin-special-folders/index.d.ts +20 -0
- package/dist/plugin-special-folders/messages.d.ts +3 -0
- package/dist/plugin-special-folders/warn-upon-folder-changes.d.ts +13 -0
- package/dist/plugin-static-assets/index.d.ts +10 -0
- package/dist/plugin-static-assets/static-assets-lib/messages.d.ts +8 -0
- package/dist/plugin-wasm/index.d.ts +15 -0
- package/dist/plugin-web-extension/feature-html/html-lib/assets.d.ts +2 -0
- package/dist/plugin-web-extension/feature-html/html-lib/inject.d.ts +4 -0
- package/dist/plugin-web-extension/feature-html/html-lib/messages.d.ts +24 -0
- package/dist/plugin-web-extension/feature-html/html-lib/parse-html.d.ts +8 -0
- package/dist/plugin-web-extension/feature-html/html-lib/patch-html.d.ts +8 -0
- package/dist/plugin-web-extension/feature-html/html-lib/utils.d.ts +46 -0
- package/dist/plugin-web-extension/feature-html/index.d.ts +36 -0
- package/dist/plugin-web-extension/feature-html/steps/add-assets-to-compilation.d.ts +9 -0
- package/dist/plugin-web-extension/feature-html/steps/add-scripts-and-styles-to-compilation.d.ts +9 -0
- package/dist/plugin-web-extension/feature-html/steps/add-to-file-dependencies.d.ts +9 -0
- package/dist/plugin-web-extension/feature-html/steps/emit-html-file.d.ts +9 -0
- package/dist/plugin-web-extension/feature-html/steps/ensure-hmr-for-scripts.d.ts +2 -0
- package/dist/plugin-web-extension/feature-html/steps/handle-common-errors.d.ts +9 -0
- package/dist/plugin-web-extension/feature-html/steps/minimum-script-file.d.ts +1 -0
- package/dist/plugin-web-extension/feature-html/steps/preact-refresh-shim.d.ts +1 -0
- package/dist/plugin-web-extension/feature-html/steps/throw-if-recompile-is-needed.d.ts +12 -0
- package/dist/plugin-web-extension/feature-html/steps/update-html-file.d.ts +9 -0
- package/dist/plugin-web-extension/feature-icons/index.d.ts +22 -0
- package/dist/plugin-web-extension/feature-icons/messages.d.ts +12 -0
- package/dist/plugin-web-extension/feature-icons/normalize-keys.d.ts +3 -0
- package/dist/plugin-web-extension/feature-icons/steps/add-to-file-dependencies.d.ts +8 -0
- package/dist/plugin-web-extension/feature-icons/steps/emit-file.d.ts +8 -0
- package/dist/plugin-web-extension/feature-json/index.d.ts +18 -0
- package/dist/plugin-web-extension/feature-json/json-validation.d.ts +3 -0
- package/dist/plugin-web-extension/feature-json/messages.d.ts +17 -0
- package/dist/plugin-web-extension/feature-json/process-assets.d.ts +2 -0
- package/dist/plugin-web-extension/feature-json/track-dependencies.d.ts +2 -0
- package/dist/plugin-web-extension/feature-locales/compilation-error.d.ts +2 -0
- package/dist/plugin-web-extension/feature-locales/get-locales.d.ts +2 -0
- package/dist/plugin-web-extension/feature-locales/index.d.ts +12 -0
- package/dist/plugin-web-extension/feature-locales/messages.d.ts +13 -0
- package/dist/plugin-web-extension/feature-locales/process-assets.d.ts +2 -0
- package/dist/plugin-web-extension/feature-locales/track-dependencies.d.ts +2 -0
- package/dist/plugin-web-extension/feature-locales/validation.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/index.d.ts +21 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-lib/manifest.d.ts +10 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-lib/sanitize-fatal-shapes.d.ts +45 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/background.d.ts +6 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/chrome_url_overrides.d.ts +8 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/commands.d.ts +16 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/content_scripts.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/content_security_policy.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/devtools_page.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/icons.d.ts +6 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/index.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/omnibox.d.ts +9 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/options_page.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/options_ui.d.ts +8 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/page_action.d.ts +8 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/permissions.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/sandbox.d.ts +7 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/sidebar_action.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/storage.d.ts +6 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/theme.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/user_scripts.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/web_accessible_resources.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/index.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv2/background.d.ts +6 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv2/browser_action.d.ts +12 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv2/chrome_settings_overrides.d.ts +24 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv2/index.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv2/theme_experiment.d.ts +7 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv3/action.d.ts +8 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv3/background.d.ts +6 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv3/declarative_net_request.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv3/host_permissions.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv3/index.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv3/side_panel.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/messages.d.ts +9 -0
- package/dist/plugin-web-extension/feature-manifest/normalize-manifest-path.d.ts +3 -0
- package/dist/plugin-web-extension/feature-manifest/steps/add-dependencies.d.ts +6 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-background.d.ts +10 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-csp.d.ts +5 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-externally-connectable.d.ts +10 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-web-resources.d.ts +19 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults.d.ts +12 -0
- package/dist/plugin-web-extension/feature-manifest/steps/emit-manifest.d.ts +7 -0
- package/dist/plugin-web-extension/feature-manifest/steps/legacy-warnings.d.ts +5 -0
- package/dist/plugin-web-extension/feature-manifest/steps/patch-chromium-background.d.ts +15 -0
- package/dist/plugin-web-extension/feature-manifest/steps/patch-dev-content-script-manifest-paths.d.ts +11 -0
- package/dist/plugin-web-extension/feature-manifest/steps/patch-gecko-background.d.ts +15 -0
- package/dist/plugin-web-extension/feature-manifest/steps/patch-war.d.ts +15 -0
- package/dist/plugin-web-extension/feature-manifest/steps/persist-manifest.d.ts +4 -0
- package/dist/plugin-web-extension/feature-manifest/steps/update-manifest.d.ts +9 -0
- package/dist/plugin-web-extension/feature-scripts/contracts.d.ts +12 -0
- package/dist/plugin-web-extension/feature-scripts/index.d.ts +19 -0
- package/dist/plugin-web-extension/feature-scripts/messages.d.ts +7 -0
- package/dist/plugin-web-extension/feature-scripts/scripts-lib/utils.d.ts +2 -0
- package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/classic-concat-loader.d.ts +8 -0
- package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/content-script-wrapper.d.ts +13 -0
- package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/get-bridge-scripts.d.ts +6 -0
- package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/index.d.ts +11 -0
- package/dist/plugin-web-extension/feature-scripts/steps/add-public-path-runtime-module.d.ts +4 -0
- package/dist/plugin-web-extension/feature-scripts/steps/add-scripts.d.ts +9 -0
- package/dist/plugin-web-extension/feature-scripts/steps/keep-geturl-imports-native.d.ts +15 -0
- package/dist/plugin-web-extension/feature-scripts/steps/native-geturl-import-loader.d.ts +3 -0
- package/dist/plugin-web-extension/feature-scripts/steps/trace-runtime-loaded-files.d.ts +41 -0
- package/dist/plugin-web-extension/feature-scripts/steps/validate-content-script-syntax.d.ts +18 -0
- package/dist/plugin-web-extension/feature-web-resources/collect-entry-imports.d.ts +3 -0
- package/dist/plugin-web-extension/feature-web-resources/index.d.ts +19 -0
- package/dist/plugin-web-extension/feature-web-resources/steps/collect-content-entry-imports.d.ts +10 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/clean-matches.d.ts +7 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/generate-manifest.d.ts +11 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/messages.d.ts +10 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/resolve-war.d.ts +9 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/shared.d.ts +4 -0
- package/dist/plugin-web-extension/index.d.ts +9 -0
- package/dist/plugin-web-extension/shared/classic-concat.d.ts +18 -0
- package/dist/plugin-web-extension/shared/compilation-issues.d.ts +6 -0
- package/dist/plugin-web-extension/shared/manifest-fields-change-detector.d.ts +12 -0
- package/dist/plugin-web-extension/shared/paths.d.ts +26 -0
- package/dist/preview-entry.d.ts +3 -0
- package/dist/rslib.config.d.ts +3 -0
- package/dist/rspack-config.d.ts +4 -0
- package/dist/types.d.ts +406 -0
- package/package.json +3 -3
package/dist/0~rspack-config.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
2
|
import { __webpack_require__ } from "./0~rslib-runtime.mjs";
|
|
3
3
|
import { createRequire } from "module";
|
|
4
|
-
import core, { Compilation
|
|
4
|
+
import core, { Compilation, DefinePlugin, ProvidePlugin, WebpackError, rspack, sources as core_sources } from "@rspack/core";
|
|
5
5
|
import pintor from "pintor";
|
|
6
6
|
import case_sensitive_paths_webpack_plugin from "case-sensitive-paths-webpack-plugin";
|
|
7
7
|
import adm_zip from "adm-zip";
|
|
8
8
|
import tiny_glob from "tiny-glob";
|
|
9
9
|
import ignore from "ignore";
|
|
10
10
|
import { pathToFileURL } from "url";
|
|
11
|
-
import { filterKeysForThisBrowser
|
|
11
|
+
import { filterKeysForThisBrowser, getManifestFieldsData } from "browser-extension-manifest-fields";
|
|
12
12
|
import content_security_policy_parser from "content-security-policy-parser";
|
|
13
13
|
import path_0 from "path";
|
|
14
14
|
import fs from "fs";
|
|
15
|
-
import { debugExtensionsToLoad, treeWithSourceFiles, getDirs, bundlerFatalError, bundlerRecompiling, asAbsolute, browserRunnerDisabled, packagingDistributionFiles, PlaywrightPlugin, toPosixPath, constants_isGeckoBasedBrowser, debugContextPath, resolveCompanionExtensionDirs, noEntrypointsDetected, GECKO_FAMILY_ALIASES, packagingSourceFiles, debugBrowser, debugOutputPath, messages_ready, manifestInvalidJson, spacerLine, isChromiumBasedBrowser, CHROMIUM_FAMILY_ALIASES, treeWithSourceAndDistFiles, treeWithDistFilesbrowser, getSpecialFoldersDataForCompiler, computeExtensionsToLoad, noCompanionExtensionsResolved } from "./101.mjs";
|
|
16
15
|
import { isResourceUnderDirs, canonicalizeDir, toResourceKey } from "./93.mjs";
|
|
17
|
-
import { injectedFileDependencyMissing, importScriptsDependencyMissing, getURLDependencyMissing, staticImportDependencyMissing, fetchedFileDependencyMissing,
|
|
18
|
-
import {
|
|
16
|
+
import { injectedFileDependencyMissing, importScriptsDependencyMissing, getURLDependencyMissing, staticImportDependencyMissing, fetchedFileDependencyMissing, runtimeSetSurfaceDependencyMissing } from "./266.mjs";
|
|
17
|
+
import { setCurrentManifestContent, jsFrameworksIntegrationsEnabled, ensureTypeScriptConfig, ensureOptionalContractModuleLoaded, resolveDevelopInstallRoot, filterKeysForThisBrowser as manifest_utils_filterKeysForThisBrowser, isUsingCustomLoader, getUserTypeScriptConfigFile, normalizeManifestOutputPath, ReloadPlugin, jsFrameworksHmrSummary, getManifestContent, hasDependency, isFromFilepathList, setOriginalManifestContent, optional_deps_resolver_ensureOptionalContractPackageResolved, getManifestOverrides, isUsingTypeScript, resolveRootAbsoluteRef, buildCanonicalManifest, getCurrentManifestContent, loadOptionalContractModuleWithoutInstall, isUsingIntegration as messages_isUsingIntegration, resolveOptionalContractPackageWithoutInstall, reportToCompilation, collectRootAbsoluteRefs, jsFrameworksConfigsDetected, resolveDevelopDistFile, unixify as paths_unixify } from "./839.mjs";
|
|
18
|
+
import { debugExtensionsToLoad, treeWithSourceFiles, getDirs, bundlerFatalError, bundlerRecompiling, asAbsolute, browserRunnerDisabled, packagingDistributionFiles, PlaywrightPlugin, toPosixPath, constants_isGeckoBasedBrowser, debugContextPath, resolveCompanionExtensionDirs, noEntrypointsDetected, GECKO_FAMILY_ALIASES, packagingSourceFiles, debugBrowser, debugOutputPath, messages_ready, manifestInvalidJson, spacerLine, isChromiumBasedBrowser, CHROMIUM_FAMILY_ALIASES, treeWithSourceAndDistFiles, treeWithDistFilesbrowser, getSpecialFoldersDataForCompiler, computeExtensionsToLoad, noCompanionExtensionsResolved } from "./101.mjs";
|
|
19
19
|
import { stripBom, parseJsonSafe } from "./23.mjs";
|
|
20
20
|
import { scrubBrand, makeSanitizedConsole } from "./0~branding.mjs";
|
|
21
21
|
import { cssIntegrationsEnabled, cssConfigsDetected, deadCssUrlRef, missingSassDependency, isUsingIntegration, postCssPluginNotResolved } from "./845.mjs";
|
|
22
|
-
import { isUsingTypeScript, jsFrameworksIntegrationsEnabled, ensureTypeScriptConfig, ensureOptionalContractModuleLoaded, resolveDevelopInstallRoot, getUserTypeScriptConfigFile, isUsingCustomLoader, isUsingIntegration as messages_isUsingIntegration, loadOptionalContractModuleWithoutInstall, resolveOptionalContractPackageWithoutInstall, jsFrameworksHmrSummary, jsFrameworksConfigsDetected, hasDependency, resolveDevelopDistFile, optional_deps_resolver_ensureOptionalContractPackageResolved } from "./839.mjs";
|
|
23
22
|
import { PROJECT_MANIFEST_FILENAMES, findNearestProjectManifestSync, readProjectDependencies } from "./80.mjs";
|
|
23
|
+
import { getCanonicalContentScriptEntryName, parseCanonicalContentScriptAsset, getCanonicalContentScriptJsAssetName, isCanonicalContentScriptAsset, EXTENSIONJS_CONTENT_SCRIPT_LAYER } from "./291.mjs";
|
|
24
24
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
25
25
|
import { dirname as __rspack_dirname } from "node:path";
|
|
26
26
|
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
@@ -34,50 +34,6 @@ __webpack_require__.r(rspack_config_namespaceObject);
|
|
|
34
34
|
__webpack_require__.d(rspack_config_namespaceObject, {
|
|
35
35
|
default: ()=>webpackConfig
|
|
36
36
|
});
|
|
37
|
-
function filterKeysForThisBrowser(manifest, browser) {
|
|
38
|
-
const isSafariTarget = 'safari' === browser || 'webkit-based' === browser || String(browser).includes('webkit');
|
|
39
|
-
const isChromiumTarget = isChromiumBasedBrowser(String(browser)) || isSafariTarget;
|
|
40
|
-
const isGeckoTarget = constants_isGeckoBasedBrowser(String(browser));
|
|
41
|
-
const chromiumPrefixes = new Set([
|
|
42
|
-
'chromium',
|
|
43
|
-
'chrome',
|
|
44
|
-
'edge'
|
|
45
|
-
]);
|
|
46
|
-
const geckoPrefixes = new Set([
|
|
47
|
-
'gecko',
|
|
48
|
-
'firefox'
|
|
49
|
-
]);
|
|
50
|
-
const webkitPrefixes = new Set([
|
|
51
|
-
'safari',
|
|
52
|
-
'webkit'
|
|
53
|
-
]);
|
|
54
|
-
const isFamilyPrefix = (prefix)=>isChromiumTarget && chromiumPrefixes.has(prefix) || isGeckoTarget && geckoPrefixes.has(prefix);
|
|
55
|
-
const isSpecificPrefix = (prefix)=>prefix === browser || isSafariTarget && webkitPrefixes.has(prefix);
|
|
56
|
-
const resolve = (node)=>{
|
|
57
|
-
if (Array.isArray(node)) return node.map((item)=>resolve(item));
|
|
58
|
-
if (node && 'object' == typeof node) {
|
|
59
|
-
const result = {};
|
|
60
|
-
const familyMatches = {};
|
|
61
|
-
const specificMatches = {};
|
|
62
|
-
for (const [key, value] of Object.entries(node)){
|
|
63
|
-
const indexOfColon = key.indexOf(':');
|
|
64
|
-
if (-1 === indexOfColon) {
|
|
65
|
-
result[key] = resolve(value);
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
const prefix = key.substring(0, indexOfColon);
|
|
69
|
-
const strippedKey = key.substring(indexOfColon + 1);
|
|
70
|
-
if (isSpecificPrefix(prefix)) specificMatches[strippedKey] = resolve(value);
|
|
71
|
-
else if (isFamilyPrefix(prefix)) familyMatches[strippedKey] = resolve(value);
|
|
72
|
-
}
|
|
73
|
-
for (const [strippedKey, value] of Object.entries(familyMatches))result[strippedKey] = value;
|
|
74
|
-
for (const [strippedKey, value] of Object.entries(specificMatches))result[strippedKey] = value;
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
return node;
|
|
78
|
-
};
|
|
79
|
-
return resolve(manifest);
|
|
80
|
-
}
|
|
81
37
|
function normalizePath(filePath) {
|
|
82
38
|
return filePath.replace(/\\/g, '/');
|
|
83
39
|
}
|
|
@@ -223,14 +179,14 @@ class WarnUponFolderChanges {
|
|
|
223
179
|
const typeOfAsset = 'pages' === folder ? 'HTML pages' : "script files";
|
|
224
180
|
const errorMessage = serverRestartRequiredFromSpecialFolderMessageOnly(addingOrRemoving, folder, typeOfAsset);
|
|
225
181
|
if (isAddition) {
|
|
226
|
-
const warn = new
|
|
182
|
+
const warn = new WebpackError(errorMessage);
|
|
227
183
|
warn.name = 'SpecialFoldersChange';
|
|
228
184
|
warn.file = filePath;
|
|
229
185
|
warn.details = `Detected change in ${folder}/ affecting ${typeOfAsset}. Restart may be required for full effect.`;
|
|
230
186
|
compilation.warnings?.push(warn);
|
|
231
187
|
return;
|
|
232
188
|
}
|
|
233
|
-
const err = new
|
|
189
|
+
const err = new WebpackError(errorMessage);
|
|
234
190
|
err.name = 'SpecialFoldersRemoval';
|
|
235
191
|
err.file = filePath;
|
|
236
192
|
err.details = `Removing from ${folder}/ breaks current build. Restart the dev server to recompile.`;
|
|
@@ -297,64 +253,12 @@ function checkManifestInPublic(compilation, publicDir) {
|
|
|
297
253
|
try {
|
|
298
254
|
const manifestInPublic = __rspack_external_path.join(publicDir, 'manifest.json');
|
|
299
255
|
if (__rspack_external_fs.existsSync(manifestInPublic)) {
|
|
300
|
-
const err = new
|
|
256
|
+
const err = new WebpackError(`manifest.json must not be placed under public/: ${manifestInPublic}`);
|
|
301
257
|
err.file = 'manifest.json';
|
|
302
258
|
compilation.errors.push(err);
|
|
303
259
|
}
|
|
304
260
|
} catch {}
|
|
305
261
|
}
|
|
306
|
-
function isFromFilepathList(filePath, filepathList) {
|
|
307
|
-
return Object.values(filepathList || {}).some((value)=>value === filePath);
|
|
308
|
-
}
|
|
309
|
-
function getFilename(feature, filePath) {
|
|
310
|
-
const entryExt = __rspack_external_path.extname(filePath);
|
|
311
|
-
let fileOutputpath = feature;
|
|
312
|
-
if ([
|
|
313
|
-
'.js',
|
|
314
|
-
'.jsx',
|
|
315
|
-
'.tsx',
|
|
316
|
-
'.ts',
|
|
317
|
-
'.vue',
|
|
318
|
-
'.svelte'
|
|
319
|
-
].includes(entryExt)) fileOutputpath = fileOutputpath.replace(entryExt, '.js');
|
|
320
|
-
if ([
|
|
321
|
-
'.html',
|
|
322
|
-
'.njk',
|
|
323
|
-
'.nunjucks'
|
|
324
|
-
].includes(entryExt)) fileOutputpath = fileOutputpath.replace(entryExt, '.html');
|
|
325
|
-
if ([
|
|
326
|
-
'.css',
|
|
327
|
-
'.scss',
|
|
328
|
-
'.sass',
|
|
329
|
-
'.less'
|
|
330
|
-
].includes(entryExt)) fileOutputpath = fileOutputpath.replace(entryExt, '.css');
|
|
331
|
-
return unixify(fileOutputpath || '');
|
|
332
|
-
}
|
|
333
|
-
function unixify(filePath) {
|
|
334
|
-
return filePath.replace(/\\/g, '/');
|
|
335
|
-
}
|
|
336
|
-
function resolveRootAbsoluteRef(ref, projectRoot, publicRoot) {
|
|
337
|
-
if (!ref || !ref.startsWith('/')) return;
|
|
338
|
-
if (projectRoot && ref.startsWith(projectRoot)) return;
|
|
339
|
-
if (ref.startsWith('//')) return;
|
|
340
|
-
const trimmed = ref.replace(/^\/+/, '');
|
|
341
|
-
if (!trimmed) return;
|
|
342
|
-
if (publicRoot && __rspack_external_fs.existsSync(__rspack_external_path.join(publicRoot, trimmed))) return;
|
|
343
|
-
const candidate = __rspack_external_path.resolve(projectRoot, trimmed);
|
|
344
|
-
const rel = __rspack_external_path.relative(projectRoot, candidate);
|
|
345
|
-
if (rel.startsWith('..') || __rspack_external_path.isAbsolute(rel)) return;
|
|
346
|
-
if (!__rspack_external_fs.existsSync(candidate) || !__rspack_external_fs.statSync(candidate).isFile()) return;
|
|
347
|
-
return candidate;
|
|
348
|
-
}
|
|
349
|
-
function collectRootAbsoluteRefs(source) {
|
|
350
|
-
const refs = new Set();
|
|
351
|
-
const attrRe = /(?:src|href)\s*=\s*["'](\/[^"'#?]*)["']/gi;
|
|
352
|
-
const urlRe = /url\(\s*["']?(\/[^"')#?]+)["']?\s*\)/gi;
|
|
353
|
-
let m;
|
|
354
|
-
while(m = attrRe.exec(source))refs.add(m[1]);
|
|
355
|
-
while(m = urlRe.exec(source))refs.add(m[1]);
|
|
356
|
-
return refs;
|
|
357
|
-
}
|
|
358
262
|
const EMITTED_WORKER_PATH = 'background/service_worker.js';
|
|
359
263
|
const MAX_TRACE_DEPTH = 8;
|
|
360
264
|
const SOURCE_SIBLING_EXTENSIONS = [
|
|
@@ -373,7 +277,7 @@ class TraceRuntimeLoadedFiles {
|
|
|
373
277
|
compiler.hooks.thisCompilation.tap(TraceRuntimeLoadedFiles.name, (compilation)=>{
|
|
374
278
|
compilation.hooks.processAssets.tap({
|
|
375
279
|
name: TraceRuntimeLoadedFiles.name,
|
|
376
|
-
stage:
|
|
280
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
377
281
|
}, ()=>{
|
|
378
282
|
this.traceWorkerImportScripts(compilation);
|
|
379
283
|
this.traceInjectedFilePayloads(compilation);
|
|
@@ -397,7 +301,7 @@ class TraceRuntimeLoadedFiles {
|
|
|
397
301
|
const workerAsset = compilation.getAsset(EMITTED_WORKER_PATH);
|
|
398
302
|
if (!workerAsset) return;
|
|
399
303
|
const manifestDir = __rspack_external_path.dirname(this.manifestPath);
|
|
400
|
-
const sourceWorkerPath =
|
|
304
|
+
const sourceWorkerPath = unixify(String(workerRef)).replace(/^\/+/, '');
|
|
401
305
|
let pending = [
|
|
402
306
|
workerAsset.source.source().toString()
|
|
403
307
|
];
|
|
@@ -455,7 +359,7 @@ class TraceRuntimeLoadedFiles {
|
|
|
455
359
|
continue;
|
|
456
360
|
}
|
|
457
361
|
if (/\.[a-zA-Z0-9]{1,8}$/.test(distRel)) {
|
|
458
|
-
const warn = new
|
|
362
|
+
const warn = new WebpackError(fetchedFileDependencyMissing(asset.name, literal, distRel));
|
|
459
363
|
warn.name = 'RuntimeFetchedFileMissing';
|
|
460
364
|
warn.file = asset.name;
|
|
461
365
|
compilation.warnings ||= [];
|
|
@@ -523,7 +427,7 @@ class TraceRuntimeLoadedFiles {
|
|
|
523
427
|
continue;
|
|
524
428
|
}
|
|
525
429
|
if ('js' === item.kind && /\.[a-zA-Z0-9]{1,8}$/.test(distRel)) {
|
|
526
|
-
const warn = new
|
|
430
|
+
const warn = new WebpackError(isStaticImport ? staticImportDependencyMissing(item.assetName, literal, distRel) : isRuntimeSurface ? runtimeSetSurfaceDependencyMissing(item.assetName, literal, distRel) : getURLDependencyMissing(item.assetName, literal, distRel));
|
|
527
431
|
warn.name = isStaticImport ? 'RuntimeStaticImportFileMissing' : isRuntimeSurface ? 'RuntimeSetSurfaceFileMissing' : 'RuntimeGetURLFileMissing';
|
|
528
432
|
warn.file = item.assetName;
|
|
529
433
|
compilation.warnings ||= [];
|
|
@@ -541,7 +445,7 @@ class TraceRuntimeLoadedFiles {
|
|
|
541
445
|
for (const asset of jsAssets){
|
|
542
446
|
const content = asset.source.source().toString();
|
|
543
447
|
if (!hasWebpackChunkLoadingRuntime(content)) continue;
|
|
544
|
-
const assetDirRel = __rspack_external_path.posix.dirname(
|
|
448
|
+
const assetDirRel = __rspack_external_path.posix.dirname(unixify(asset.name));
|
|
545
449
|
const sourceDirs = new Set();
|
|
546
450
|
const entryDir = entrySourceDirs.get(asset.name.replace(/\.js$/i, ''));
|
|
547
451
|
if (entryDir) sourceDirs.add(entryDir);
|
|
@@ -622,7 +526,7 @@ function copyThroughOrWarn(compilation, opts) {
|
|
|
622
526
|
return buffer.toString();
|
|
623
527
|
}
|
|
624
528
|
const sourceSibling = findSourceSibling(abs);
|
|
625
|
-
const warn = new
|
|
529
|
+
const warn = new WebpackError(opts.warning(opts.sourceRel, sourceSibling ? unixify(__rspack_external_path.relative(opts.manifestDir, sourceSibling)) : void 0));
|
|
626
530
|
warn.name = opts.warningName;
|
|
627
531
|
warn.file = opts.warningFile;
|
|
628
532
|
compilation.warnings ||= [];
|
|
@@ -634,7 +538,7 @@ function findSourceSibling(abs) {
|
|
|
634
538
|
const base = abs.slice(0, -3);
|
|
635
539
|
return SOURCE_SIBLING_EXTENSIONS.map((ext)=>base + ext).find((candidate)=>__rspack_external_fs.existsSync(candidate));
|
|
636
540
|
}
|
|
637
|
-
function
|
|
541
|
+
function unixify(filePath) {
|
|
638
542
|
return filePath.replace(/\\/g, '/');
|
|
639
543
|
}
|
|
640
544
|
function resolveExtensionPath(literal, basePath) {
|
|
@@ -643,7 +547,7 @@ function resolveExtensionPath(literal, basePath) {
|
|
|
643
547
|
if (/^[a-zA-Z][\w+.-]*:/.test(trimmed)) return null;
|
|
644
548
|
if (trimmed.startsWith('//')) return null;
|
|
645
549
|
try {
|
|
646
|
-
const base = new URL('chrome-extension://extension-js/' +
|
|
550
|
+
const base = new URL('chrome-extension://extension-js/' + unixify(basePath));
|
|
647
551
|
const resolved = new URL(trimmed, base);
|
|
648
552
|
if ('extension-js' !== resolved.hostname) return null;
|
|
649
553
|
const pathname = decodeURIComponent(resolved.pathname).replace(/^\/+/, '');
|
|
@@ -656,7 +560,7 @@ function manifestDeclaredSourcePaths(manifest) {
|
|
|
656
560
|
const declared = new Set();
|
|
657
561
|
if (!manifest) return declared;
|
|
658
562
|
const add = (value)=>{
|
|
659
|
-
if ('string' == typeof value && value.trim()) declared.add(
|
|
563
|
+
if ('string' == typeof value && value.trim()) declared.add(unixify(value.trim()).replace(/^\/+/, '').split(/[?#]/)[0]);
|
|
660
564
|
};
|
|
661
565
|
add(manifest.background?.service_worker);
|
|
662
566
|
add(manifest.background?.page);
|
|
@@ -823,7 +727,7 @@ function fetchLiteralToFsPath(literal) {
|
|
|
823
727
|
if (/^[a-zA-Z][\w+.-]*:/.test(trimmed)) return null;
|
|
824
728
|
if (trimmed.startsWith('//')) return null;
|
|
825
729
|
const noQuery = trimmed.split(/[?#]/)[0];
|
|
826
|
-
return noQuery ?
|
|
730
|
+
return noQuery ? unixify(noQuery) : null;
|
|
827
731
|
}
|
|
828
732
|
function blankComments(source) {
|
|
829
733
|
let out = '';
|
|
@@ -1079,590 +983,6 @@ function envInjectedPublicVars(count) {
|
|
|
1079
983
|
function envNoMatchingFile(browser, mode, presentFiles, expectedCandidates) {
|
|
1080
984
|
return `Found ${presentFiles.map((file)=>pintor.yellow(file)).join(', ')} but none match browser ${pintor.yellow(browser)} (mode ${pintor.yellow(mode)}), so EXTENSION_PUBLIC_* variables read from code will be ${pintor.yellow('undefined')} in this build.\nMatching names, in priority order: ${expectedCandidates.map((file)=>pintor.gray(file)).join(', ')}.\nFamily names apply to every family member — e.g. ${pintor.yellow('.env.chrome')} also matches ${pintor.yellow('chromium')} and ${pintor.yellow('edge')} targets.`;
|
|
1081
985
|
}
|
|
1082
|
-
function background_background(manifest) {
|
|
1083
|
-
return manifest.background && manifest.background.scripts && {
|
|
1084
|
-
background: {
|
|
1085
|
-
scripts: [
|
|
1086
|
-
...new Set(manifest.background.scripts.map((script)=>getFilename("background/scripts.js", String(script))))
|
|
1087
|
-
]
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
function normalizeManifestOutputPath(originalPath) {
|
|
1092
|
-
if (!originalPath) return originalPath;
|
|
1093
|
-
const unixPath = originalPath.replace(/\\/g, '/');
|
|
1094
|
-
if (/^\/public\//i.test(unixPath)) return unixPath.replace(/^\/public\//i, '');
|
|
1095
|
-
if (/^(?:\.\/)?public\//i.test(unixPath)) return unixPath.replace(/^(?:\.\/)?public\//i, '');
|
|
1096
|
-
if (/^\//.test(unixPath)) return unixPath.replace(/^\//, '');
|
|
1097
|
-
return unixPath;
|
|
1098
|
-
}
|
|
1099
|
-
function manifestPageOutputTarget(raw, compiledTarget, manifestPath) {
|
|
1100
|
-
const unixPath = raw.replace(/\\/g, '/');
|
|
1101
|
-
if (/^(?:\/public\/|(?:\.\/)?public\/)/i.test(unixPath)) return normalizeManifestOutputPath(unixPath);
|
|
1102
|
-
if (/^\//.test(unixPath)) {
|
|
1103
|
-
const rest = unixPath.replace(/^\/+/, '');
|
|
1104
|
-
if (manifestPath && rest) {
|
|
1105
|
-
const manifestDir = __rspack_external_path.dirname(manifestPath);
|
|
1106
|
-
const inPublic = __rspack_external_fs.existsSync(__rspack_external_path.join(manifestDir, 'public', rest));
|
|
1107
|
-
const inRoot = __rspack_external_fs.existsSync(__rspack_external_path.join(manifestDir, rest));
|
|
1108
|
-
if (inRoot && !inPublic) return compiledTarget;
|
|
1109
|
-
}
|
|
1110
|
-
return normalizeManifestOutputPath(unixPath);
|
|
1111
|
-
}
|
|
1112
|
-
return compiledTarget;
|
|
1113
|
-
}
|
|
1114
|
-
function iconOutputPath(raw) {
|
|
1115
|
-
if (/^(?:\/public\/|(?:\.\/)?public\/)/i.test(raw)) return normalizeManifestOutputPath(raw);
|
|
1116
|
-
const normalized = normalizeManifestOutputPath(raw).replace(/^\.\//, '');
|
|
1117
|
-
const escapes = !normalized || normalized.split('/').includes('..') || /^[A-Za-z]:/.test(normalized);
|
|
1118
|
-
return escapes ? `icons/${normalized.split('/').pop() || ''}` : normalized;
|
|
1119
|
-
}
|
|
1120
|
-
function browserAction(manifest) {
|
|
1121
|
-
return manifest.browser_action && {
|
|
1122
|
-
browser_action: {
|
|
1123
|
-
...manifest.browser_action,
|
|
1124
|
-
...manifest.browser_action.default_popup && {
|
|
1125
|
-
default_popup: getFilename('action/index.html', manifest.browser_action.default_popup)
|
|
1126
|
-
},
|
|
1127
|
-
...manifest.browser_action.default_icon && {
|
|
1128
|
-
default_icon: 'string' == typeof manifest.browser_action.default_icon ? (()=>{
|
|
1129
|
-
const raw = String(manifest.browser_action.default_icon);
|
|
1130
|
-
return getFilename(iconOutputPath(raw), raw);
|
|
1131
|
-
})() : Object.fromEntries(Object.entries(manifest.browser_action.default_icon).map(([size, icon])=>{
|
|
1132
|
-
const raw = String(icon);
|
|
1133
|
-
return [
|
|
1134
|
-
size,
|
|
1135
|
-
getFilename(iconOutputPath(raw), raw)
|
|
1136
|
-
];
|
|
1137
|
-
}))
|
|
1138
|
-
},
|
|
1139
|
-
...manifest.browser_action.theme_icons && {
|
|
1140
|
-
theme_icons: manifest.browser_action.theme_icons.map((themeIcon)=>({
|
|
1141
|
-
...themeIcon,
|
|
1142
|
-
...themeIcon.light && {
|
|
1143
|
-
light: (()=>{
|
|
1144
|
-
const raw = String(themeIcon.light);
|
|
1145
|
-
const isPublic = /^(?:\/public\/|(?:\.\/)?public\/)/i.test(raw);
|
|
1146
|
-
const target = isPublic ? normalizeManifestOutputPath(raw) : `browser_action/${__rspack_external_path.basename(raw)}`;
|
|
1147
|
-
return getFilename(target, raw);
|
|
1148
|
-
})()
|
|
1149
|
-
},
|
|
1150
|
-
...themeIcon.dark && {
|
|
1151
|
-
dark: (()=>{
|
|
1152
|
-
const raw = String(themeIcon.dark);
|
|
1153
|
-
const isPublic = /^(?:\/public\/|(?:\.\/)?public\/)/i.test(raw);
|
|
1154
|
-
const target = isPublic ? normalizeManifestOutputPath(raw) : `browser_action/${__rspack_external_path.basename(raw)}`;
|
|
1155
|
-
return getFilename(target, raw);
|
|
1156
|
-
})()
|
|
1157
|
-
}
|
|
1158
|
-
}))
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
};
|
|
1162
|
-
}
|
|
1163
|
-
function chromeSettingsOverrides(manifest) {
|
|
1164
|
-
return manifest.chrome_settings_overrides && {
|
|
1165
|
-
chrome_settings_overrides: {
|
|
1166
|
-
...manifest.chrome_settings_overrides.homepage && {
|
|
1167
|
-
homepage: manifest.chrome_settings_overrides.homepage
|
|
1168
|
-
},
|
|
1169
|
-
...manifest.chrome_settings_overrides.search_provider && {
|
|
1170
|
-
search_provider: {
|
|
1171
|
-
...manifest.chrome_settings_overrides.search_provider,
|
|
1172
|
-
...manifest.chrome_settings_overrides.search_provider.favicon_url && {
|
|
1173
|
-
favicon_url: (()=>{
|
|
1174
|
-
const fav = manifest.chrome_settings_overrides.search_provider.favicon_url;
|
|
1175
|
-
const isUrl = /^(?:[a-z]+:)?\/\//i.test(fav);
|
|
1176
|
-
return isUrl ? fav : getFilename(`chrome_settings_overrides/${fav.split('/').pop()}`, fav);
|
|
1177
|
-
})()
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
},
|
|
1181
|
-
...manifest.chrome_settings_overrides.startup_pages && {
|
|
1182
|
-
startup_pages: manifest.chrome_settings_overrides.startup_pages.map((page, index)=>getFilename(`chrome_settings_overrides/startup-${index}.html`, page))
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
}
|
|
1187
|
-
function pageAction(manifest) {
|
|
1188
|
-
return manifest.page_action && {
|
|
1189
|
-
page_action: {
|
|
1190
|
-
...manifest.page_action,
|
|
1191
|
-
...manifest.page_action.default_popup && {
|
|
1192
|
-
default_popup: getFilename('action/index.html', manifest.page_action.default_popup)
|
|
1193
|
-
},
|
|
1194
|
-
...manifest.page_action.default_icon && {
|
|
1195
|
-
default_icon: 'string' == typeof manifest.page_action.default_icon ? (()=>{
|
|
1196
|
-
const raw = String(manifest.page_action.default_icon);
|
|
1197
|
-
return getFilename(iconOutputPath(raw), raw);
|
|
1198
|
-
})() : Object.fromEntries(Object.entries(manifest.page_action.default_icon).map(([size, icon])=>{
|
|
1199
|
-
const raw = String(icon);
|
|
1200
|
-
return [
|
|
1201
|
-
size,
|
|
1202
|
-
getFilename(iconOutputPath(raw), raw)
|
|
1203
|
-
];
|
|
1204
|
-
}))
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
};
|
|
1208
|
-
}
|
|
1209
|
-
function sidebarAction(manifest) {
|
|
1210
|
-
return manifest.sidebar_action && {
|
|
1211
|
-
sidebar_action: {
|
|
1212
|
-
...manifest.sidebar_action,
|
|
1213
|
-
...manifest.sidebar_action.default_panel && {
|
|
1214
|
-
default_panel: getFilename("sidebar/index.html", manifest.sidebar_action.default_panel)
|
|
1215
|
-
},
|
|
1216
|
-
...manifest.sidebar_action.default_icon && {
|
|
1217
|
-
default_icon: 'string' == typeof manifest.sidebar_action.default_icon ? (()=>{
|
|
1218
|
-
const raw = String(manifest.sidebar_action.default_icon);
|
|
1219
|
-
return getFilename(iconOutputPath(raw), raw);
|
|
1220
|
-
})() : Object.fromEntries(Object.entries(manifest.sidebar_action.default_icon).map(([size, icon])=>{
|
|
1221
|
-
const raw = String(icon);
|
|
1222
|
-
return [
|
|
1223
|
-
size,
|
|
1224
|
-
getFilename(iconOutputPath(raw), raw)
|
|
1225
|
-
];
|
|
1226
|
-
}))
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
const getBasename = (filepath)=>__rspack_external_path.basename(filepath);
|
|
1232
|
-
function themeExperiment(manifest) {
|
|
1233
|
-
const te = manifest.theme_experiment;
|
|
1234
|
-
return te && {
|
|
1235
|
-
theme_experiment: {
|
|
1236
|
-
...te,
|
|
1237
|
-
...'string' == typeof te.stylesheet && {
|
|
1238
|
-
stylesheet: getFilename(`theme_experiment/${getBasename(te.stylesheet)}`, te.stylesheet)
|
|
1239
|
-
},
|
|
1240
|
-
...Array.isArray(te.stylesheets) && {
|
|
1241
|
-
stylesheets: te.stylesheets.map((s, i)=>getFilename(`theme_experiment/stylesheet-${i}.css`, s))
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
function manifestV2(manifest) {
|
|
1247
|
-
return {
|
|
1248
|
-
...background_background(manifest),
|
|
1249
|
-
...browserAction(manifest),
|
|
1250
|
-
...pageAction(manifest),
|
|
1251
|
-
...sidebarAction(manifest),
|
|
1252
|
-
...chromeSettingsOverrides(manifest),
|
|
1253
|
-
...themeExperiment(manifest)
|
|
1254
|
-
};
|
|
1255
|
-
}
|
|
1256
|
-
function action_action(manifest) {
|
|
1257
|
-
return manifest.action && {
|
|
1258
|
-
action: {
|
|
1259
|
-
...manifest.action,
|
|
1260
|
-
...manifest.action.default_popup && {
|
|
1261
|
-
default_popup: getFilename("action/index.html", manifest.action.default_popup)
|
|
1262
|
-
},
|
|
1263
|
-
...manifest.action.default_icon && {
|
|
1264
|
-
default_icon: 'string' == typeof manifest.action.default_icon ? (()=>{
|
|
1265
|
-
const raw = String(manifest.action.default_icon);
|
|
1266
|
-
return getFilename(iconOutputPath(raw), raw);
|
|
1267
|
-
})() : Object.fromEntries(Object.entries(manifest.action.default_icon).map(([size, icon])=>{
|
|
1268
|
-
const raw = String(icon);
|
|
1269
|
-
return [
|
|
1270
|
-
size,
|
|
1271
|
-
getFilename(iconOutputPath(raw), raw)
|
|
1272
|
-
];
|
|
1273
|
-
}))
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
};
|
|
1277
|
-
}
|
|
1278
|
-
function backgroundServiceWorker(manifest) {
|
|
1279
|
-
return manifest.background && manifest.background.service_worker && {
|
|
1280
|
-
background: {
|
|
1281
|
-
service_worker: (()=>{
|
|
1282
|
-
const raw = String(manifest.background.service_worker);
|
|
1283
|
-
return getFilename('background/service_worker.js', raw);
|
|
1284
|
-
})()
|
|
1285
|
-
}
|
|
1286
|
-
};
|
|
1287
|
-
}
|
|
1288
|
-
function declarativeNetRequest(manifest) {
|
|
1289
|
-
return manifest.declarative_net_request && {
|
|
1290
|
-
declarative_net_request: {
|
|
1291
|
-
...manifest.declarative_net_request,
|
|
1292
|
-
rule_resources: manifest.declarative_net_request.rule_resources.map((resourceObj)=>({
|
|
1293
|
-
...resourceObj,
|
|
1294
|
-
path: resourceObj.path && getFilename(`declarative_net_request/${resourceObj.id}.json`, resourceObj.path)
|
|
1295
|
-
}))
|
|
1296
|
-
}
|
|
1297
|
-
};
|
|
1298
|
-
}
|
|
1299
|
-
function hostPermissions(manifest) {
|
|
1300
|
-
return manifest.host_permissions && {
|
|
1301
|
-
host_permissions: manifest.host_permissions
|
|
1302
|
-
};
|
|
1303
|
-
}
|
|
1304
|
-
function sidePanel(manifest) {
|
|
1305
|
-
return manifest.side_panel && {
|
|
1306
|
-
side_panel: {
|
|
1307
|
-
...manifest.side_panel,
|
|
1308
|
-
...manifest.side_panel.default_path && {
|
|
1309
|
-
default_path: (()=>{
|
|
1310
|
-
const raw = String(manifest.side_panel.default_path);
|
|
1311
|
-
return getFilename('sidebar/index.html', raw);
|
|
1312
|
-
})()
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
};
|
|
1316
|
-
}
|
|
1317
|
-
function manifestV3(manifest) {
|
|
1318
|
-
return {
|
|
1319
|
-
...action_action(manifest),
|
|
1320
|
-
...backgroundServiceWorker(manifest),
|
|
1321
|
-
...declarativeNetRequest(manifest),
|
|
1322
|
-
...hostPermissions(manifest),
|
|
1323
|
-
...sidePanel(manifest)
|
|
1324
|
-
};
|
|
1325
|
-
}
|
|
1326
|
-
function backgroundPage(manifest) {
|
|
1327
|
-
return manifest.background && manifest.background.page && {
|
|
1328
|
-
background: {
|
|
1329
|
-
page: (()=>{
|
|
1330
|
-
const raw = String(manifest.background.page);
|
|
1331
|
-
return getFilename('background/index.html', raw);
|
|
1332
|
-
})()
|
|
1333
|
-
}
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
function chromeUrlOverrides(manifest, manifestPath) {
|
|
1337
|
-
return manifest.chrome_url_overrides && {
|
|
1338
|
-
chrome_url_overrides: {
|
|
1339
|
-
...manifest.chrome_url_overrides.bookmarks && {
|
|
1340
|
-
bookmarks: (()=>{
|
|
1341
|
-
const raw = String(manifest.chrome_url_overrides.bookmarks);
|
|
1342
|
-
return getFilename(manifestPageOutputTarget(raw, 'chrome_url_overrides/bookmarks.html', manifestPath), raw);
|
|
1343
|
-
})()
|
|
1344
|
-
},
|
|
1345
|
-
...manifest.chrome_url_overrides.history && {
|
|
1346
|
-
history: (()=>{
|
|
1347
|
-
const raw = String(manifest.chrome_url_overrides.history);
|
|
1348
|
-
return getFilename(manifestPageOutputTarget(raw, 'chrome_url_overrides/history.html', manifestPath), raw);
|
|
1349
|
-
})()
|
|
1350
|
-
},
|
|
1351
|
-
...manifest.chrome_url_overrides.newtab && {
|
|
1352
|
-
newtab: (()=>{
|
|
1353
|
-
const raw = String(manifest.chrome_url_overrides.newtab);
|
|
1354
|
-
return getFilename(manifestPageOutputTarget(raw, 'chrome_url_overrides/newtab.html', manifestPath), raw);
|
|
1355
|
-
})()
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
};
|
|
1359
|
-
}
|
|
1360
|
-
function isBundledContentPath(filePath, ext) {
|
|
1361
|
-
const normalized = String(filePath || '').replace(/\\/g, '/');
|
|
1362
|
-
const bundledAsset = parseCanonicalContentScriptAsset(normalized);
|
|
1363
|
-
return bundledAsset?.extension === ext;
|
|
1364
|
-
}
|
|
1365
|
-
function isAlreadyBundledContentScripts(contentScripts) {
|
|
1366
|
-
if (!Array.isArray(contentScripts) || 0 === contentScripts.length) return false;
|
|
1367
|
-
return contentScripts.every((contentObj)=>{
|
|
1368
|
-
const js = Array.isArray(contentObj?.js) ? contentObj.js : [];
|
|
1369
|
-
const css = Array.isArray(contentObj?.css) ? contentObj.css : [];
|
|
1370
|
-
return js.every((filePath)=>isBundledContentPath(filePath, 'js')) && css.every((filePath)=>isBundledContentPath(filePath, 'css'));
|
|
1371
|
-
});
|
|
1372
|
-
}
|
|
1373
|
-
function content_scripts_contentScripts(manifest, manifestPath) {
|
|
1374
|
-
if (!manifest.content_scripts) return;
|
|
1375
|
-
const original = manifest.content_scripts;
|
|
1376
|
-
if (isAlreadyBundledContentScripts(original)) return {
|
|
1377
|
-
content_scripts: original
|
|
1378
|
-
};
|
|
1379
|
-
const originalCount = original.length;
|
|
1380
|
-
const result = [];
|
|
1381
|
-
let bridgeOrdinal = 0;
|
|
1382
|
-
for(let index = 0; index < original.length; index++){
|
|
1383
|
-
const contentObj = original[index] || {};
|
|
1384
|
-
const contentJs = [
|
|
1385
|
-
...new Set(contentObj.js || [])
|
|
1386
|
-
];
|
|
1387
|
-
const contentCss = [
|
|
1388
|
-
...new Set(contentObj.css || [])
|
|
1389
|
-
];
|
|
1390
|
-
if ('MAIN' === contentObj.world) {
|
|
1391
|
-
const bridgeIndex = originalCount + bridgeOrdinal++;
|
|
1392
|
-
const { world: _ignoredWorld, js: _ignoredJs, css: _ignoredCss, ...rest } = contentObj;
|
|
1393
|
-
result.push({
|
|
1394
|
-
...rest,
|
|
1395
|
-
js: [
|
|
1396
|
-
getFilename(getCanonicalContentScriptJsAssetName(bridgeIndex), 'main-world-bridge.js')
|
|
1397
|
-
],
|
|
1398
|
-
css: []
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
|
-
result.push({
|
|
1402
|
-
...original[index] || {},
|
|
1403
|
-
js: [
|
|
1404
|
-
...new Set(contentJs.map((js)=>getFilename(getCanonicalContentScriptJsAssetName(index), js)))
|
|
1405
|
-
],
|
|
1406
|
-
css: [
|
|
1407
|
-
...new Set(contentCss.map((css)=>getFilename(getCanonicalContentScriptCssAssetName(index), css)))
|
|
1408
|
-
]
|
|
1409
|
-
});
|
|
1410
|
-
}
|
|
1411
|
-
return {
|
|
1412
|
-
content_scripts: result
|
|
1413
|
-
};
|
|
1414
|
-
}
|
|
1415
|
-
function devtoolsPage(manifest, manifestPath) {
|
|
1416
|
-
return manifest.devtools_page && {
|
|
1417
|
-
devtools_page: (()=>{
|
|
1418
|
-
const raw = String(manifest.devtools_page);
|
|
1419
|
-
return getFilename(manifestPageOutputTarget(raw, 'devtools/index.html', manifestPath), raw);
|
|
1420
|
-
})()
|
|
1421
|
-
};
|
|
1422
|
-
}
|
|
1423
|
-
function icons_icons(manifest) {
|
|
1424
|
-
return manifest.icons && {
|
|
1425
|
-
icons: Object.fromEntries(Object.entries(manifest.icons).map(([size, icon])=>{
|
|
1426
|
-
const raw = String(icon);
|
|
1427
|
-
return [
|
|
1428
|
-
size,
|
|
1429
|
-
getFilename(iconOutputPath(raw), raw)
|
|
1430
|
-
];
|
|
1431
|
-
}))
|
|
1432
|
-
};
|
|
1433
|
-
}
|
|
1434
|
-
function commands_commands(manifest) {
|
|
1435
|
-
return manifest.commands && {
|
|
1436
|
-
commands: manifest.commands
|
|
1437
|
-
};
|
|
1438
|
-
}
|
|
1439
|
-
function permissions(manifest) {
|
|
1440
|
-
return manifest.permissions && {
|
|
1441
|
-
permissions: manifest.permissions
|
|
1442
|
-
};
|
|
1443
|
-
}
|
|
1444
|
-
function optionsPage(manifest, manifestPath) {
|
|
1445
|
-
return manifest.options_page && {
|
|
1446
|
-
options_page: (()=>{
|
|
1447
|
-
const raw = String(manifest.options_page);
|
|
1448
|
-
return getFilename(manifestPageOutputTarget(raw, 'options/index.html', manifestPath), raw);
|
|
1449
|
-
})()
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
function optionsUi(manifest, manifestPath) {
|
|
1453
|
-
return manifest.options_ui && {
|
|
1454
|
-
options_ui: {
|
|
1455
|
-
...manifest.options_ui,
|
|
1456
|
-
...manifest.options_ui.page && {
|
|
1457
|
-
page: (()=>{
|
|
1458
|
-
const raw = String(manifest.options_ui.page);
|
|
1459
|
-
return getFilename(manifestPageOutputTarget(raw, 'options/index.html', manifestPath), raw);
|
|
1460
|
-
})()
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
|
-
function sandbox(manifest) {
|
|
1466
|
-
return manifest.sandbox && {
|
|
1467
|
-
sandbox: {
|
|
1468
|
-
...manifest.sandbox,
|
|
1469
|
-
...manifest.sandbox.pages && {
|
|
1470
|
-
pages: manifest.sandbox.pages.map((page, index)=>getFilename(`sandbox/page-${index}.html`, page))
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
};
|
|
1474
|
-
}
|
|
1475
|
-
function storage(manifest) {
|
|
1476
|
-
return manifest.storage && {
|
|
1477
|
-
storage: {
|
|
1478
|
-
...manifest.storage.managed_schema && {
|
|
1479
|
-
managed_schema: getFilename('storage/managed_schema.json', manifest.storage.managed_schema)
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
const theme_getBasename = (filepath)=>__rspack_external_path.basename(filepath);
|
|
1485
|
-
const rewriteThemeImage = (value)=>getFilename(`theme/images/${theme_getBasename(value)}`, value);
|
|
1486
|
-
function theme(manifest) {
|
|
1487
|
-
return manifest.theme && {
|
|
1488
|
-
theme: {
|
|
1489
|
-
...manifest.theme,
|
|
1490
|
-
...manifest.theme.images && {
|
|
1491
|
-
images: Object.fromEntries(Object.entries(manifest.theme.images).map(([key, value])=>[
|
|
1492
|
-
key,
|
|
1493
|
-
Array.isArray(value) ? value.map(rewriteThemeImage) : rewriteThemeImage(value)
|
|
1494
|
-
]))
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
};
|
|
1498
|
-
}
|
|
1499
|
-
function userScripts(manifest) {
|
|
1500
|
-
return manifest.user_scripts && {
|
|
1501
|
-
user_scripts: {
|
|
1502
|
-
...manifest.user_scripts,
|
|
1503
|
-
...manifest.user_scripts.api_script && {
|
|
1504
|
-
api_script: getFilename("user_scripts/api_script.js", manifest.user_scripts.api_script)
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
};
|
|
1508
|
-
}
|
|
1509
|
-
function normalizeOutputPath(originalPath) {
|
|
1510
|
-
if (!originalPath) return originalPath;
|
|
1511
|
-
const unix = originalPath.replace(/\\/g, '/');
|
|
1512
|
-
if (/[*?\[\]{}]/.test(unix)) return unix;
|
|
1513
|
-
if (/^\/public\//i.test(unix)) return unix.replace(/^\/public\//i, '');
|
|
1514
|
-
if (/^(?:\.\/)?public\//i.test(unix)) return unix.replace(/^(?:\.\/)?public\//i, '');
|
|
1515
|
-
if (/^\//.test(unix)) return unix.replace(/^\//, '');
|
|
1516
|
-
return unix;
|
|
1517
|
-
}
|
|
1518
|
-
function webAccessibleResources(manifest) {
|
|
1519
|
-
if (!manifest.web_accessible_resources || !manifest.web_accessible_resources.length) return;
|
|
1520
|
-
const mapResource = (resource)=>getFilename(normalizeOutputPath(resource), resource);
|
|
1521
|
-
const entries = manifest.web_accessible_resources.map((entry)=>{
|
|
1522
|
-
if ('string' == typeof entry) return mapResource(entry);
|
|
1523
|
-
if (!entry || !Array.isArray(entry.resources)) return;
|
|
1524
|
-
return {
|
|
1525
|
-
...entry,
|
|
1526
|
-
resources: entry.resources.map(mapResource)
|
|
1527
|
-
};
|
|
1528
|
-
}).filter((entry)=>void 0 !== entry);
|
|
1529
|
-
if (0 === entries.length) return;
|
|
1530
|
-
return {
|
|
1531
|
-
web_accessible_resources: entries
|
|
1532
|
-
};
|
|
1533
|
-
}
|
|
1534
|
-
function contentSecurityPolicy(manifest) {
|
|
1535
|
-
return manifest.content_security_policy && {
|
|
1536
|
-
content_security_policy: manifest.content_security_policy
|
|
1537
|
-
};
|
|
1538
|
-
}
|
|
1539
|
-
const omnibox_getBasename = (filepath)=>__rspack_external_path.basename(filepath);
|
|
1540
|
-
function omnibox_omnibox(manifest) {
|
|
1541
|
-
const omnibox = manifest.omnibox;
|
|
1542
|
-
return omnibox && {
|
|
1543
|
-
omnibox: {
|
|
1544
|
-
...omnibox,
|
|
1545
|
-
...omnibox.default_icon && {
|
|
1546
|
-
default_icon: 'string' == typeof omnibox.default_icon ? getFilename(`icons/${omnibox_getBasename(omnibox.default_icon)}`, omnibox.default_icon) : Object.fromEntries(Object.entries(omnibox.default_icon).map(([size, icon])=>[
|
|
1547
|
-
size,
|
|
1548
|
-
getFilename(`icons/${omnibox_getBasename(icon)}`, icon)
|
|
1549
|
-
]))
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
function manifestCommon(manifest, manifestPath) {
|
|
1555
|
-
return {
|
|
1556
|
-
...backgroundPage(manifest),
|
|
1557
|
-
...chromeUrlOverrides(manifest, manifestPath),
|
|
1558
|
-
...content_scripts_contentScripts(manifest, manifestPath),
|
|
1559
|
-
...devtoolsPage(manifest, manifestPath),
|
|
1560
|
-
...icons_icons(manifest),
|
|
1561
|
-
...commands_commands(manifest),
|
|
1562
|
-
...permissions(manifest),
|
|
1563
|
-
...optionsPage(manifest, manifestPath),
|
|
1564
|
-
...optionsUi(manifest, manifestPath),
|
|
1565
|
-
...sandbox(manifest),
|
|
1566
|
-
...storage(manifest),
|
|
1567
|
-
...theme(manifest),
|
|
1568
|
-
...userScripts(manifest),
|
|
1569
|
-
...webAccessibleResources(manifest),
|
|
1570
|
-
...contentSecurityPolicy(manifest),
|
|
1571
|
-
...omnibox_omnibox(manifest)
|
|
1572
|
-
};
|
|
1573
|
-
}
|
|
1574
|
-
function getManifestOverrides(manifestPath, manifest) {
|
|
1575
|
-
const manifestContent = manifest || JSON.parse(stripBom(__rspack_external_fs.readFileSync(manifestPath, 'utf8')));
|
|
1576
|
-
const omit = (obj, key)=>{
|
|
1577
|
-
if (!obj) return {};
|
|
1578
|
-
const { [key]: _ignored, ...rest } = obj;
|
|
1579
|
-
return rest;
|
|
1580
|
-
};
|
|
1581
|
-
const pickBackground = (obj)=>{
|
|
1582
|
-
const value = obj.background;
|
|
1583
|
-
return value && 'object' == typeof value ? value : {};
|
|
1584
|
-
};
|
|
1585
|
-
const common = manifestCommon(manifestContent, manifestPath);
|
|
1586
|
-
const mv2 = manifestV2(manifestContent);
|
|
1587
|
-
const mv3 = manifestV3(manifestContent);
|
|
1588
|
-
const backgroundMerged = {
|
|
1589
|
-
...manifestContent.background || {},
|
|
1590
|
-
...pickBackground(common),
|
|
1591
|
-
...pickBackground(mv2),
|
|
1592
|
-
...pickBackground(mv3)
|
|
1593
|
-
};
|
|
1594
|
-
const merged = {
|
|
1595
|
-
...manifestContent,
|
|
1596
|
-
...omit(common, 'background'),
|
|
1597
|
-
...omit(mv2, 'background'),
|
|
1598
|
-
...omit(mv3, 'background')
|
|
1599
|
-
};
|
|
1600
|
-
if (Object.keys(backgroundMerged).length) merged.background = backgroundMerged;
|
|
1601
|
-
return JSON.stringify(merged, null, 2);
|
|
1602
|
-
}
|
|
1603
|
-
const cjsRequire = createRequire(import.meta.url);
|
|
1604
|
-
const INTERNAL_MANIFEST_SOURCE = '__extensionjs_manifest_source__';
|
|
1605
|
-
const INTERNAL_MANIFEST_CURRENT_SOURCE = '__extensionjs_manifest_current_source__';
|
|
1606
|
-
function readAssetSource(asset) {
|
|
1607
|
-
if (!asset) return '';
|
|
1608
|
-
const source = asset.source;
|
|
1609
|
-
if ('string' == typeof source) return source;
|
|
1610
|
-
if ('function' == typeof source) {
|
|
1611
|
-
const out = source();
|
|
1612
|
-
return 'string' == typeof out ? out : String(out || '');
|
|
1613
|
-
}
|
|
1614
|
-
if (source && 'function' == typeof source.source) {
|
|
1615
|
-
const out = source.source();
|
|
1616
|
-
return 'string' == typeof out ? out : String(out || '');
|
|
1617
|
-
}
|
|
1618
|
-
return '';
|
|
1619
|
-
}
|
|
1620
|
-
function setOriginalManifestContent(compilation, source) {
|
|
1621
|
-
compilation[INTERNAL_MANIFEST_SOURCE] = source;
|
|
1622
|
-
}
|
|
1623
|
-
function getOriginalManifestContent(compilation) {
|
|
1624
|
-
return compilation[INTERNAL_MANIFEST_SOURCE];
|
|
1625
|
-
}
|
|
1626
|
-
function setCurrentManifestContent(compilation, source) {
|
|
1627
|
-
compilation[INTERNAL_MANIFEST_CURRENT_SOURCE] = source;
|
|
1628
|
-
}
|
|
1629
|
-
function getCurrentManifestContent(compilation) {
|
|
1630
|
-
return compilation[INTERNAL_MANIFEST_CURRENT_SOURCE];
|
|
1631
|
-
}
|
|
1632
|
-
function getManifestContent(compilation, manifestPath) {
|
|
1633
|
-
const currentManifest = getCurrentManifestContent(compilation);
|
|
1634
|
-
if (currentManifest) return parseJsonSafe(currentManifest);
|
|
1635
|
-
const getAsset = compilation.getAsset;
|
|
1636
|
-
if ('function' == typeof getAsset) {
|
|
1637
|
-
const manifestAsset = getAsset.call(compilation, 'manifest.json');
|
|
1638
|
-
const manifest = readAssetSource(manifestAsset);
|
|
1639
|
-
if (manifest) return parseJsonSafe(manifest);
|
|
1640
|
-
}
|
|
1641
|
-
const manifestAsset = compilation.assets?.['manifest.json'];
|
|
1642
|
-
if (manifestAsset) {
|
|
1643
|
-
const manifest = readAssetSource(manifestAsset);
|
|
1644
|
-
if (manifest) return parseJsonSafe(manifest);
|
|
1645
|
-
}
|
|
1646
|
-
const originalManifest = getOriginalManifestContent(compilation);
|
|
1647
|
-
if (originalManifest) return parseJsonSafe(originalManifest);
|
|
1648
|
-
try {
|
|
1649
|
-
const text = __rspack_external_fs.readFileSync(manifestPath, 'utf8');
|
|
1650
|
-
return parseJsonSafe(text);
|
|
1651
|
-
} catch {
|
|
1652
|
-
try {
|
|
1653
|
-
const resolved = cjsRequire.resolve(manifestPath);
|
|
1654
|
-
delete cjsRequire.cache[resolved];
|
|
1655
|
-
} catch {}
|
|
1656
|
-
return cjsRequire(manifestPath);
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
function buildCanonicalManifest(manifestPath, manifest, browser) {
|
|
1660
|
-
const filteredManifest = filterKeysForThisBrowser(manifest, browser);
|
|
1661
|
-
return {
|
|
1662
|
-
...filteredManifest,
|
|
1663
|
-
...JSON.parse(getManifestOverrides(manifestPath, filteredManifest))
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
986
|
function resolveProcessShim() {
|
|
1667
987
|
const candidate = __rspack_external_path.join(__rspack_import_meta_dirname__, '..', 'runtime', 'process-shim.cjs');
|
|
1668
988
|
try {
|
|
@@ -1738,7 +1058,7 @@ class EnvPlugin {
|
|
|
1738
1058
|
unmatchedEnvFiles = __rspack_external_fs.readdirSync(projectPath).filter((file)=>file.startsWith('.env') && '.env.defaults' !== file && '.env.example' !== file).sort();
|
|
1739
1059
|
} catch {}
|
|
1740
1060
|
if (unmatchedEnvFiles.length > 0) compiler.hooks.thisCompilation.tap('env:warn-unmatched', (compilation)=>{
|
|
1741
|
-
const warn = new
|
|
1061
|
+
const warn = new WebpackError(envNoMatchingFile(String(this.browser), String(mode), unmatchedEnvFiles, envFiles));
|
|
1742
1062
|
warn.name = 'EnvNoMatchingFile';
|
|
1743
1063
|
compilation.warnings.push(warn);
|
|
1744
1064
|
});
|
|
@@ -1786,7 +1106,7 @@ class EnvPlugin {
|
|
|
1786
1106
|
compiler.hooks.thisCompilation.tap('manifest:update-manifest', (compilation)=>{
|
|
1787
1107
|
compilation.hooks.processAssets.tap({
|
|
1788
1108
|
name: 'env:module',
|
|
1789
|
-
stage:
|
|
1109
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
1790
1110
|
}, (assets)=>{
|
|
1791
1111
|
const files = Object.keys(compilation.assets || assets);
|
|
1792
1112
|
files.forEach((filename)=>{
|
|
@@ -2188,7 +1508,7 @@ class CompilationPlugin {
|
|
|
2188
1508
|
setupCompilerDoneDiagnostics(compiler, this.port);
|
|
2189
1509
|
}
|
|
2190
1510
|
}
|
|
2191
|
-
const
|
|
1511
|
+
const cjsRequire = createRequire(import.meta.url);
|
|
2192
1512
|
let userMessageDelivered = false;
|
|
2193
1513
|
function isUsingSass(projectPath) {
|
|
2194
1514
|
if (hasDependency(projectPath, 'sass')) {
|
|
@@ -2214,7 +1534,7 @@ function resolveSassImplementation(projectPath) {
|
|
|
2214
1534
|
return mod;
|
|
2215
1535
|
} catch {}
|
|
2216
1536
|
try {
|
|
2217
|
-
let mod =
|
|
1537
|
+
let mod = cjsRequire('sass');
|
|
2218
1538
|
if (mod && 'object' == typeof mod && 'default' in mod) mod = mod.default;
|
|
2219
1539
|
return mod;
|
|
2220
1540
|
} catch {
|
|
@@ -3010,7 +2330,7 @@ class CssPlugin {
|
|
|
3010
2330
|
const key = `${issuer}|${req}`;
|
|
3011
2331
|
if (!warned.has(key) && compilation?.warnings) {
|
|
3012
2332
|
warned.add(key);
|
|
3013
|
-
const warning = new
|
|
2333
|
+
const warning = new WebpackError(deadCssUrlRef(__rspack_external_path.relative(manifestDir, issuer) || issuer, raw));
|
|
3014
2334
|
warning.file = __rspack_external_path.relative(manifestDir, issuer);
|
|
3015
2335
|
compilation.warnings.push(warning);
|
|
3016
2336
|
}
|
|
@@ -3499,7 +2819,7 @@ async function maybeUseSvelte(projectPath, mode) {
|
|
|
3499
2819
|
alias: Object.keys(alias).length > 0 ? alias : void 0
|
|
3500
2820
|
};
|
|
3501
2821
|
}
|
|
3502
|
-
function
|
|
2822
|
+
function isUrl(src) {
|
|
3503
2823
|
try {
|
|
3504
2824
|
new URL(src);
|
|
3505
2825
|
return true;
|
|
@@ -3512,7 +2832,7 @@ function parseHtml(node, onResourceFound) {
|
|
|
3512
2832
|
if ("script" === node.nodeName) {
|
|
3513
2833
|
const src = node.attrs?.find((attr)=>'src' === attr.name)?.value;
|
|
3514
2834
|
if (!src) return;
|
|
3515
|
-
if (
|
|
2835
|
+
if (isUrl(src)) return;
|
|
3516
2836
|
onResourceFound({
|
|
3517
2837
|
filePath: src,
|
|
3518
2838
|
childNode: node,
|
|
@@ -3526,14 +2846,14 @@ function parseHtml(node, onResourceFound) {
|
|
|
3526
2846
|
const url = candidate.trim().split(/\s+/)[0];
|
|
3527
2847
|
if (!url) continue;
|
|
3528
2848
|
const { cleanPath } = cleanAssetUrl(url);
|
|
3529
|
-
if (cleanPath && !
|
|
2849
|
+
if (cleanPath && !isUrl(cleanPath)) onResourceFound({
|
|
3530
2850
|
filePath: cleanPath,
|
|
3531
2851
|
childNode: node,
|
|
3532
2852
|
assetType: 'staticHref'
|
|
3533
2853
|
});
|
|
3534
2854
|
}
|
|
3535
2855
|
if (!href) return;
|
|
3536
|
-
if (
|
|
2856
|
+
if (isUrl(href)) return;
|
|
3537
2857
|
const nonStylesheetRelTokens = [
|
|
3538
2858
|
'dns-prefetch',
|
|
3539
2859
|
'icon',
|
|
@@ -3560,7 +2880,7 @@ function parseHtml(node, onResourceFound) {
|
|
|
3560
2880
|
} else if ('audio' === node.nodeName || 'embed' === node.nodeName || 'iframe' === node.nodeName || 'img' === node.nodeName || 'input' === node.nodeName || 'source' === node.nodeName || 'track' === node.nodeName || 'video' === node.nodeName) {
|
|
3561
2881
|
const src = node.attrs?.find((attr)=>'src' === attr.name)?.value;
|
|
3562
2882
|
if (!src) return;
|
|
3563
|
-
if (
|
|
2883
|
+
if (isUrl(src)) return;
|
|
3564
2884
|
onResourceFound({
|
|
3565
2885
|
filePath: src,
|
|
3566
2886
|
childNode: node,
|
|
@@ -3574,7 +2894,7 @@ function parseHtml(node, onResourceFound) {
|
|
|
3574
2894
|
const url = parts[0];
|
|
3575
2895
|
if (!url) continue;
|
|
3576
2896
|
const { cleanPath } = cleanAssetUrl(url);
|
|
3577
|
-
if (cleanPath && !
|
|
2897
|
+
if (cleanPath && !isUrl(cleanPath)) onResourceFound({
|
|
3578
2898
|
filePath: cleanPath,
|
|
3579
2899
|
childNode: node,
|
|
3580
2900
|
assetType: 'staticSrc'
|
|
@@ -3583,7 +2903,7 @@ function parseHtml(node, onResourceFound) {
|
|
|
3583
2903
|
}
|
|
3584
2904
|
if ('video' === node.nodeName) {
|
|
3585
2905
|
const poster = node.attrs?.find((attr)=>'poster' === attr.name)?.value;
|
|
3586
|
-
if (poster && !
|
|
2906
|
+
if (poster && !isUrl(poster)) {
|
|
3587
2907
|
const { cleanPath } = cleanAssetUrl(poster);
|
|
3588
2908
|
if (cleanPath) onResourceFound({
|
|
3589
2909
|
filePath: cleanPath,
|
|
@@ -3596,21 +2916,6 @@ function parseHtml(node, onResourceFound) {
|
|
|
3596
2916
|
const { childNodes = [] } = node;
|
|
3597
2917
|
for (const childNode of childNodes)if ('#comment' !== childNode.nodeName && '#text' !== childNode.nodeName) parseHtml(childNode, onResourceFound);
|
|
3598
2918
|
}
|
|
3599
|
-
function createIssue(compiler, message, type = 'error') {
|
|
3600
|
-
const ErrorCtor = compiler?.rspack?.WebpackError || Error;
|
|
3601
|
-
const issue = new ErrorCtor(message);
|
|
3602
|
-
issue.name = 'warning' === type ? 'ExtensionWarning' : 'ExtensionError';
|
|
3603
|
-
return issue;
|
|
3604
|
-
}
|
|
3605
|
-
function reportToCompilation(compilation, compiler, message, type = 'error', file) {
|
|
3606
|
-
const issue = createIssue(compiler, message, type);
|
|
3607
|
-
if (file) issue.file = file;
|
|
3608
|
-
const bucket = 'warning' === type ? 'warnings' : 'errors';
|
|
3609
|
-
compilation[bucket] ||= [];
|
|
3610
|
-
const already = compilation[bucket].some((e)=>(e?.file || '') === (issue.file || '') && String(e?.message) === String(issue.message));
|
|
3611
|
-
if (already) return;
|
|
3612
|
-
compilation[bucket].push(issue);
|
|
3613
|
-
}
|
|
3614
2919
|
const cloneParsedHtmlAsset = (assets)=>({
|
|
3615
2920
|
css: [
|
|
3616
2921
|
...assets.css || []
|
|
@@ -3903,7 +3208,7 @@ class JsFrameworksPlugin {
|
|
|
3903
3208
|
}
|
|
3904
3209
|
const platformModulePaths = new Set();
|
|
3905
3210
|
try {
|
|
3906
|
-
const browserManifest =
|
|
3211
|
+
const browserManifest = filterKeysForThisBrowser(manifest, this.browser);
|
|
3907
3212
|
const background = browserManifest?.background;
|
|
3908
3213
|
if (background?.type === 'module' && 'string' == typeof background?.service_worker) platformModulePaths.add(toResourceKey(__rspack_external_path.resolve(manifestDir, background.service_worker)));
|
|
3909
3214
|
const htmlPages = {
|
|
@@ -4189,7 +3494,7 @@ class EmitManifest {
|
|
|
4189
3494
|
compiler.hooks.thisCompilation.tap('manifest:emit-manifest', (compilation)=>{
|
|
4190
3495
|
compilation.hooks.processAssets.tap({
|
|
4191
3496
|
name: 'manifest:emit-manifest',
|
|
4192
|
-
stage:
|
|
3497
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
|
|
4193
3498
|
}, ()=>{
|
|
4194
3499
|
let jsonContent;
|
|
4195
3500
|
try {
|
|
@@ -4498,7 +3803,7 @@ class UpdateManifest {
|
|
|
4498
3803
|
compiler.hooks.thisCompilation.tap('manifest:update-manifest', (compilation)=>{
|
|
4499
3804
|
compilation.hooks.processAssets.tap({
|
|
4500
3805
|
name: 'manifest:update-manifest',
|
|
4501
|
-
stage:
|
|
3806
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE + 1
|
|
4502
3807
|
}, ()=>{
|
|
4503
3808
|
if (compilation.errors.length > 0) return;
|
|
4504
3809
|
const manifest = getManifestContent(compilation, this.manifestPath);
|
|
@@ -4524,7 +3829,7 @@ class UpdateManifest {
|
|
|
4524
3829
|
const sanitized = sanitizeFatalManifestShapes(patchedManifest, __rspack_external_path.dirname(this.manifestPath));
|
|
4525
3830
|
patchedManifest = sanitized.manifest;
|
|
4526
3831
|
for (const fix of sanitized.fixes){
|
|
4527
|
-
const warn = new
|
|
3832
|
+
const warn = new WebpackError(fatalManifestShapeFixed(fix.field, fix.detail));
|
|
4528
3833
|
warn.name = 'ManifestFatalShapeWarning';
|
|
4529
3834
|
warn.file = 'manifest.json';
|
|
4530
3835
|
compilation.warnings.push(warn);
|
|
@@ -4610,11 +3915,11 @@ function warPatchedSummary(v3Groups, v3ResourcesTotal, v2Resources) {
|
|
|
4610
3915
|
return `Web resources: WAR patched — v3Groups=${String(v3Groups)}, v3Resources=${String(v3ResourcesTotal)}, v2Resources=${String(v2Resources)}`;
|
|
4611
3916
|
}
|
|
4612
3917
|
function isPublicRootLike(possiblePath) {
|
|
4613
|
-
const normalizedPath =
|
|
3918
|
+
const normalizedPath = paths_unixify(possiblePath || '');
|
|
4614
3919
|
return normalizedPath.startsWith('/') || /^(?:\.\/)?public\//i.test(normalizedPath) || /^\/public\//i.test(normalizedPath);
|
|
4615
3920
|
}
|
|
4616
3921
|
function toPublicOutput(possiblePath) {
|
|
4617
|
-
const normalizedPath =
|
|
3922
|
+
const normalizedPath = paths_unixify(possiblePath || '');
|
|
4618
3923
|
if (/^\/public\//i.test(normalizedPath)) return normalizedPath.replace(/^\/public\//i, '');
|
|
4619
3924
|
if (/^(?:\.\/)?public\//i.test(normalizedPath)) return normalizedPath.replace(/^(?:\.\/)?public\//i, '');
|
|
4620
3925
|
if (/^\//.test(normalizedPath)) return normalizedPath.replace(/^\//, '');
|
|
@@ -4637,7 +3942,7 @@ function emitDirectoryAsAssets(compilation, absDir, baseDir) {
|
|
|
4637
3942
|
continue;
|
|
4638
3943
|
}
|
|
4639
3944
|
if (!entry.isFile()) continue;
|
|
4640
|
-
const outName =
|
|
3945
|
+
const outName = paths_unixify(__rspack_external_path.relative(baseDir, full));
|
|
4641
3946
|
if (!compilation.getAsset(outName)) compilation.emitAsset(outName, new core_sources.RawSource(__rspack_external_fs.readFileSync(full)));
|
|
4642
3947
|
compilation.fileDependencies.add(full);
|
|
4643
3948
|
}
|
|
@@ -4656,7 +3961,7 @@ function emitFileAsAsset(compilation, absPath) {
|
|
|
4656
3961
|
}
|
|
4657
3962
|
if (!compilation.getAsset(outName)) compilation.emitAsset(outName, new core_sources.RawSource(content));
|
|
4658
3963
|
compilation.fileDependencies.add(absPath);
|
|
4659
|
-
return
|
|
3964
|
+
return paths_unixify(outName);
|
|
4660
3965
|
}
|
|
4661
3966
|
function resolve_war_findSourceSibling(absOutputPath) {
|
|
4662
3967
|
const candidatesByExt = {
|
|
@@ -4705,7 +4010,7 @@ function validateMatchesOrReport(compilation, matches, browser) {
|
|
|
4705
4010
|
compilation.errors ||= [];
|
|
4706
4011
|
for (const m of matches)if (!isValidChromeMatchPattern(m)) {
|
|
4707
4012
|
const msg = warInvalidMatchPattern(m);
|
|
4708
|
-
const err = new
|
|
4013
|
+
const err = new WebpackError(msg);
|
|
4709
4014
|
err.file = 'manifest.json';
|
|
4710
4015
|
err.name = 'WARInvalidMatchPattern';
|
|
4711
4016
|
compilation.errors.push(err);
|
|
@@ -4773,7 +4078,7 @@ function resolveUserDeclaredWAR(compilation, manifestPath, manifest, browser) {
|
|
|
4773
4078
|
publicRootHint: true,
|
|
4774
4079
|
relativeRef: res
|
|
4775
4080
|
});
|
|
4776
|
-
const err = new
|
|
4081
|
+
const err = new WebpackError(msg);
|
|
4777
4082
|
err.file = 'manifest.json';
|
|
4778
4083
|
compilation.warnings.push(err);
|
|
4779
4084
|
}
|
|
@@ -4797,7 +4102,7 @@ function resolveUserDeclaredWAR(compilation, manifestPath, manifest, browser) {
|
|
|
4797
4102
|
relativeRef: res,
|
|
4798
4103
|
sourceSibling: sourceSibling ? __rspack_external_path.relative(manifestDir, sourceSibling) : void 0
|
|
4799
4104
|
});
|
|
4800
|
-
const warn = new
|
|
4105
|
+
const warn = new WebpackError(msg);
|
|
4801
4106
|
warn.file = 'manifest.json';
|
|
4802
4107
|
warn.name = 'WARRelativeAssetMissing';
|
|
4803
4108
|
compilation.warnings.push(warn);
|
|
@@ -4805,11 +4110,11 @@ function resolveUserDeclaredWAR(compilation, manifestPath, manifest, browser) {
|
|
|
4805
4110
|
}
|
|
4806
4111
|
if (__rspack_external_fs.statSync(abs).isDirectory()) {
|
|
4807
4112
|
emitDirectoryAsAssets(compilation, abs, manifestDir);
|
|
4808
|
-
const dirResource =
|
|
4113
|
+
const dirResource = paths_unixify(res).replace(/\/+$/, '') + '/*';
|
|
4809
4114
|
pushResource(matches, dirResource, extra);
|
|
4810
4115
|
return;
|
|
4811
4116
|
}
|
|
4812
|
-
const relOut =
|
|
4117
|
+
const relOut = paths_unixify(__rspack_external_path.relative(manifestDir, abs));
|
|
4813
4118
|
if (!relOut.startsWith('..')) {
|
|
4814
4119
|
if (!compilation.getAsset(relOut)) compilation.emitAsset(relOut, new core_sources.RawSource(__rspack_external_fs.readFileSync(abs)));
|
|
4815
4120
|
compilation.fileDependencies.add(abs);
|
|
@@ -4823,7 +4128,7 @@ function resolveUserDeclaredWAR(compilation, manifestPath, manifest, browser) {
|
|
|
4823
4128
|
if ('string' == typeof entry) {
|
|
4824
4129
|
if (isMv2) return void handleOne(void 0, entry);
|
|
4825
4130
|
const msg = warStringEntryInMv3(entry);
|
|
4826
|
-
const err = new
|
|
4131
|
+
const err = new WebpackError(msg);
|
|
4827
4132
|
err.file = 'manifest.json';
|
|
4828
4133
|
err.name = 'WARStringEntryInMv3';
|
|
4829
4134
|
compilation.errors = compilation.errors || [];
|
|
@@ -5051,7 +4356,7 @@ class PatchWAR {
|
|
|
5051
4356
|
compiler.hooks.thisCompilation.tap('manifest:patch-war', (compilation)=>{
|
|
5052
4357
|
compilation.hooks.processAssets.tap({
|
|
5053
4358
|
name: 'manifest:patch-war',
|
|
5054
|
-
stage:
|
|
4359
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
5055
4360
|
}, ()=>{
|
|
5056
4361
|
if (compilation.errors.length > 0) return;
|
|
5057
4362
|
const shared = getSharedFor(compilation);
|
|
@@ -5302,7 +4607,7 @@ class ApplyDevDefaults {
|
|
|
5302
4607
|
if (!compilation?.hooks?.processAssets) return;
|
|
5303
4608
|
compilation.hooks.processAssets.tap({
|
|
5304
4609
|
name: 'manifest:apply-dev-defaults',
|
|
5305
|
-
stage:
|
|
4610
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT + 100
|
|
5306
4611
|
}, ()=>{
|
|
5307
4612
|
if (compilation.errors.length > 0) return;
|
|
5308
4613
|
if (!this.manifestPath) {
|
|
@@ -5418,7 +4723,7 @@ class PersistManifestToDisk {
|
|
|
5418
4723
|
compiler.hooks.thisCompilation.tap('manifest:persist-manifest:capture', (compilation)=>{
|
|
5419
4724
|
compilation.hooks.processAssets.tap({
|
|
5420
4725
|
name: 'manifest:persist-manifest:capture',
|
|
5421
|
-
stage:
|
|
4726
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT + 1000
|
|
5422
4727
|
}, ()=>{
|
|
5423
4728
|
pendingHadErrors = compilation.errors.length > 0;
|
|
5424
4729
|
pendingOutputPath = compilation.outputOptions.path || compiler.options.output?.path;
|
|
@@ -5509,7 +4814,7 @@ class ManifestLegacyWarnings {
|
|
|
5509
4814
|
compiler.hooks.thisCompilation.tap(ManifestLegacyWarnings.name, (compilation)=>{
|
|
5510
4815
|
compilation.hooks.processAssets.tap({
|
|
5511
4816
|
name: ManifestLegacyWarnings.name,
|
|
5512
|
-
stage:
|
|
4817
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
5513
4818
|
}, ()=>{
|
|
5514
4819
|
const asset = compilation.getAsset('manifest.json');
|
|
5515
4820
|
if (!asset) return;
|
|
@@ -5517,7 +4822,7 @@ class ManifestLegacyWarnings {
|
|
|
5517
4822
|
let count = 0;
|
|
5518
4823
|
legacy.forEach((needle)=>{
|
|
5519
4824
|
if (text.includes(needle)) {
|
|
5520
|
-
const warn = new
|
|
4825
|
+
const warn = new WebpackError(legacyManifestPathWarning(needle));
|
|
5521
4826
|
warn.name = 'ManifestLegacyWarning';
|
|
5522
4827
|
warn.file = 'manifest.json';
|
|
5523
4828
|
compilation.warnings.push(warn);
|
|
@@ -5691,7 +4996,7 @@ class EmitHtmlFile {
|
|
|
5691
4996
|
};
|
|
5692
4997
|
if (processAssetsHook && 'function' == typeof processAssetsHook.tap) processAssetsHook.tap({
|
|
5693
4998
|
name: 'AddAssetsToCompilationPlugin',
|
|
5694
|
-
stage:
|
|
4999
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
5695
5000
|
}, ()=>runner());
|
|
5696
5001
|
else runner();
|
|
5697
5002
|
});
|
|
@@ -5788,7 +5093,7 @@ function warnIfPublicRootAssetMissing(compilation, htmlEntry, cleanPath) {
|
|
|
5788
5093
|
const projectDir = __rspack_external_path.dirname(__rspack_external_path.dirname(htmlEntry));
|
|
5789
5094
|
const publicCandidate = __rspack_external_path.join(projectDir, 'public', cleanPath.slice(1));
|
|
5790
5095
|
if (__rspack_external_fs.existsSync(publicCandidate)) return;
|
|
5791
|
-
const warn = new
|
|
5096
|
+
const warn = new WebpackError(fileNotFound(htmlEntry, cleanPath));
|
|
5792
5097
|
warn.name = 'HtmlPublicAssetMissing';
|
|
5793
5098
|
warn.file = htmlEntry;
|
|
5794
5099
|
const filtered = String(warn.message).split('\n').filter((line)=>!line.includes(String(cleanPath)));
|
|
@@ -6116,7 +5421,7 @@ class AddAssetsToCompilation {
|
|
|
6116
5421
|
};
|
|
6117
5422
|
if (processAssetsHook && 'function' == typeof processAssetsHook.tap) processAssetsHook.tap({
|
|
6118
5423
|
name: 'html:add-assets-to-compilation',
|
|
6119
|
-
stage:
|
|
5424
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
6120
5425
|
}, ()=>runner());
|
|
6121
5426
|
else runner();
|
|
6122
5427
|
});
|
|
@@ -6169,29 +5474,31 @@ function normalizeHotValue(value) {
|
|
|
6169
5474
|
if ('boolean' == typeof value) return String(value);
|
|
6170
5475
|
return 'true';
|
|
6171
5476
|
}
|
|
5477
|
+
const HMR_CLIENT_SPECIFIER = '@rspack/dev-server/client/index.js';
|
|
5478
|
+
const HMR_HOT_SPECIFIER = '@rspack/core/hot/dev-server';
|
|
6172
5479
|
let _resolvedClientPath;
|
|
6173
5480
|
let _resolvedHotPath;
|
|
6174
5481
|
function resolveHmrClientPath() {
|
|
6175
5482
|
if (!_resolvedClientPath) try {
|
|
6176
|
-
_resolvedClientPath = dev_server_client_import_cjsRequire.resolve(
|
|
5483
|
+
_resolvedClientPath = dev_server_client_import_cjsRequire.resolve(HMR_CLIENT_SPECIFIER, {
|
|
6177
5484
|
paths: [
|
|
6178
5485
|
__rspack_import_meta_dirname__
|
|
6179
5486
|
]
|
|
6180
5487
|
});
|
|
6181
5488
|
} catch {
|
|
6182
|
-
_resolvedClientPath =
|
|
5489
|
+
_resolvedClientPath = HMR_CLIENT_SPECIFIER;
|
|
6183
5490
|
}
|
|
6184
5491
|
return _resolvedClientPath;
|
|
6185
5492
|
}
|
|
6186
5493
|
function resolveHmrHotPath() {
|
|
6187
5494
|
if (!_resolvedHotPath) try {
|
|
6188
|
-
_resolvedHotPath = dev_server_client_import_cjsRequire.resolve(
|
|
5495
|
+
_resolvedHotPath = dev_server_client_import_cjsRequire.resolve(HMR_HOT_SPECIFIER, {
|
|
6189
5496
|
paths: [
|
|
6190
5497
|
__rspack_import_meta_dirname__
|
|
6191
5498
|
]
|
|
6192
5499
|
});
|
|
6193
5500
|
} catch {
|
|
6194
|
-
_resolvedHotPath =
|
|
5501
|
+
_resolvedHotPath = HMR_HOT_SPECIFIER;
|
|
6195
5502
|
}
|
|
6196
5503
|
return _resolvedHotPath;
|
|
6197
5504
|
}
|
|
@@ -6320,7 +5627,7 @@ class UpdateHtmlFile {
|
|
|
6320
5627
|
const hasProcessAssets = Boolean(compilation?.hooks?.processAssets?.tap);
|
|
6321
5628
|
if (hasProcessAssets) compilation.hooks.processAssets.tap({
|
|
6322
5629
|
name: 'html:update-html-file',
|
|
6323
|
-
stage:
|
|
5630
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
6324
5631
|
}, ()=>run());
|
|
6325
5632
|
else run();
|
|
6326
5633
|
});
|
|
@@ -6339,7 +5646,7 @@ class AddToFileDependencies {
|
|
|
6339
5646
|
compiler.hooks.thisCompilation.tap('html:add-to-file-dependencies', (compilation)=>{
|
|
6340
5647
|
compilation.hooks.processAssets.tap({
|
|
6341
5648
|
name: 'html:add-to-file-dependencies',
|
|
6342
|
-
stage:
|
|
5649
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
6343
5650
|
}, ()=>{
|
|
6344
5651
|
if (compilation.errors?.length) return;
|
|
6345
5652
|
const allEntries = this.includeList || {};
|
|
@@ -6410,7 +5717,7 @@ class ThrowIfRecompileIsNeeded {
|
|
|
6410
5717
|
if (this.hasEntriesChanged(updatedCssEntries, css) || this.hasEntriesChanged(updatedJsEntries, js)) {
|
|
6411
5718
|
const projectRoot = __rspack_external_path.dirname(this.manifestPath);
|
|
6412
5719
|
const relToManifest = __rspack_external_path.relative(projectRoot, changedFile);
|
|
6413
|
-
const err = new
|
|
5720
|
+
const err = new WebpackError(serverRestartRequiredFromHtml(relToManifest, changedFile));
|
|
6414
5721
|
err.name = 'HtmlEntrypointChanged';
|
|
6415
5722
|
err.file = relToManifest;
|
|
6416
5723
|
compilation.errors.push(err);
|
|
@@ -6470,7 +5777,7 @@ function handleCantResolveError(includesList, error, compilation, manifestDir) {
|
|
|
6470
5777
|
const errorMsg = fileNotFound(resource, overrideNotFoundPath || wrongFilename, {
|
|
6471
5778
|
publicRootHint: isPublicRoot
|
|
6472
5779
|
});
|
|
6473
|
-
const warn = new
|
|
5780
|
+
const warn = new WebpackError(errorMsg);
|
|
6474
5781
|
warn.name = 'HtmlEntrypointMissing';
|
|
6475
5782
|
warn.file = __rspack_external_path.relative(manifestDir, resource);
|
|
6476
5783
|
return warn;
|
|
@@ -6493,7 +5800,7 @@ class HandleCommonErrors {
|
|
|
6493
5800
|
const hasProcessAssets = Boolean(compilation?.hooks?.processAssets?.tap);
|
|
6494
5801
|
if (hasProcessAssets) return void compilation.hooks.processAssets.tap({
|
|
6495
5802
|
name: 'html:handle-common-errors',
|
|
6496
|
-
stage:
|
|
5803
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
6497
5804
|
}, ()=>{
|
|
6498
5805
|
const errs = [
|
|
6499
5806
|
...compilation.errors
|
|
@@ -6605,18 +5912,6 @@ class HtmlPlugin {
|
|
|
6605
5912
|
}).apply(compiler);
|
|
6606
5913
|
}
|
|
6607
5914
|
}
|
|
6608
|
-
function utils_createIssue(compiler, message, type = 'error') {
|
|
6609
|
-
const ErrorCtor = compiler.rspack.WebpackError || Error;
|
|
6610
|
-
const issue = new ErrorCtor(message);
|
|
6611
|
-
issue.name = 'warning' === type ? 'ExtensionWarning' : 'ExtensionError';
|
|
6612
|
-
return issue;
|
|
6613
|
-
}
|
|
6614
|
-
function utils_reportToCompilation(compilation, compiler, message, type = 'error') {
|
|
6615
|
-
const issue = utils_createIssue(compiler, message, type);
|
|
6616
|
-
const bucket = 'warning' === type ? 'warnings' : 'errors';
|
|
6617
|
-
compilation[bucket] ||= [];
|
|
6618
|
-
compilation[bucket].push(issue);
|
|
6619
|
-
}
|
|
6620
5915
|
function getScriptEntries(scriptPath) {
|
|
6621
5916
|
const scriptEntries = Array.isArray(scriptPath) ? scriptPath || [] : scriptPath ? [
|
|
6622
5917
|
scriptPath
|
|
@@ -6665,15 +5960,16 @@ function resolveMainWorldBridgeSourcePath(options) {
|
|
|
6665
5960
|
const packageRoot = options?.packageRoot || findPackageRoot(lookupDir);
|
|
6666
5961
|
return resolveExistingFile([
|
|
6667
5962
|
path_0.resolve(lookupDir, 'main-world-bridge'),
|
|
6668
|
-
packageRoot ? path_0.resolve(packageRoot, "plugin-web-extension/feature-scripts/steps/
|
|
5963
|
+
packageRoot ? path_0.resolve(packageRoot, "plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/main-world-bridge") : void 0,
|
|
6669
5964
|
packageRoot ? path_0.resolve(packageRoot, 'dist', 'main-world-bridge') : void 0
|
|
6670
5965
|
]);
|
|
6671
5966
|
}
|
|
6672
|
-
function getMainWorldBridgeScripts(manifestPath) {
|
|
5967
|
+
function getMainWorldBridgeScripts(manifestPath, browser = 'chrome') {
|
|
6673
5968
|
const bridgeScripts = {};
|
|
6674
5969
|
try {
|
|
6675
5970
|
const raw = JSON.parse(stripBom(fs.readFileSync(manifestPath, 'utf-8')));
|
|
6676
|
-
const
|
|
5971
|
+
const resolved = manifest_utils_filterKeysForThisBrowser(raw, browser);
|
|
5972
|
+
const contentScripts = Array.isArray(resolved?.content_scripts) ? resolved.content_scripts : [];
|
|
6677
5973
|
const originalCount = contentScripts.length;
|
|
6678
5974
|
const bridgeSource = resolveMainWorldBridgeSourcePath();
|
|
6679
5975
|
if (!bridgeSource) return bridgeScripts;
|
|
@@ -6688,8 +5984,8 @@ function getMainWorldBridgeScripts(manifestPath) {
|
|
|
6688
5984
|
return bridgeScripts;
|
|
6689
5985
|
}
|
|
6690
5986
|
class AddContentScriptWrapper {
|
|
6691
|
-
static getBridgeScripts(manifestPath) {
|
|
6692
|
-
return getMainWorldBridgeScripts(manifestPath);
|
|
5987
|
+
static getBridgeScripts(manifestPath, browser = 'chrome') {
|
|
5988
|
+
return getMainWorldBridgeScripts(manifestPath, browser);
|
|
6693
5989
|
}
|
|
6694
5990
|
manifestPath;
|
|
6695
5991
|
browser;
|
|
@@ -6774,12 +6070,14 @@ function createSequentialEntryModule(feature, scriptImports) {
|
|
|
6774
6070
|
class AddScripts {
|
|
6775
6071
|
manifestPath;
|
|
6776
6072
|
includeList;
|
|
6073
|
+
browser;
|
|
6777
6074
|
constructor(options){
|
|
6778
6075
|
this.manifestPath = options.manifestPath;
|
|
6779
6076
|
this.includeList = options.includeList || {};
|
|
6077
|
+
this.browser = options.browser || 'chrome';
|
|
6780
6078
|
}
|
|
6781
6079
|
apply(compiler) {
|
|
6782
|
-
const bridgeScripts = AddContentScriptWrapper.getBridgeScripts(this.manifestPath);
|
|
6080
|
+
const bridgeScripts = AddContentScriptWrapper.getBridgeScripts(this.manifestPath, this.browser);
|
|
6783
6081
|
const scriptFields = {
|
|
6784
6082
|
...this.includeList,
|
|
6785
6083
|
...bridgeScripts
|
|
@@ -6873,2340 +6171,10 @@ class AddScripts {
|
|
|
6873
6171
|
};
|
|
6874
6172
|
}
|
|
6875
6173
|
}
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
if (compilation.runtimeTemplate) return compilation.runtimeTemplate.basicFunction(args, body);
|
|
6881
|
-
return compilation.outputOptions.environment.arrowFunction ? `(${args}) => {\n${Template.indent(body)}\n}` : `function(${args}) {\n${Template.indent(body)}\n}`;
|
|
6882
|
-
},
|
|
6883
|
-
retF: (returnValue, args = '')=>{
|
|
6884
|
-
if (!compilation) throw new TypeError('No compilation is found.');
|
|
6885
|
-
if (compilation.runtimeTemplate) return compilation.runtimeTemplate.returningFunction(returnValue, args);
|
|
6886
|
-
return compilation.outputOptions.environment.arrowFunction ? `(${args}) => (${returnValue})` : `function(${args}) { return ${returnValue}; }`;
|
|
6887
|
-
}
|
|
6888
|
-
};
|
|
6889
|
-
}
|
|
6890
|
-
const RuntimeGlobal = '__webpack_require__.webExtRt';
|
|
6891
|
-
const RuntimeGlobalIsBrowser = '__webpack_require__.webExtRtModern';
|
|
6892
|
-
function BrowserRuntimeModule(webpack, acceptWeak) {
|
|
6893
|
-
const { RuntimeModule, Template } = webpack;
|
|
6894
|
-
class BrowserRuntime extends RuntimeModule {
|
|
6895
|
-
constructor(){
|
|
6896
|
-
super('WebExtensionBrowserRuntime', RuntimeModule.STAGE_NORMAL);
|
|
6897
|
-
}
|
|
6898
|
-
generate() {
|
|
6899
|
-
const { compilation } = this;
|
|
6900
|
-
if (!compilation) return Template.asString('/* [webpack-target-webextension] BrowserRuntimeModule skipped because no compilation is found. */');
|
|
6901
|
-
const optionalChaining = compilation.outputOptions.environment.optionalChaining;
|
|
6902
|
-
const _let = compilation.outputOptions.environment.const ? 'let' : 'var';
|
|
6903
|
-
return Template.asString([
|
|
6904
|
-
`${_let} isChrome, runtime;`,
|
|
6905
|
-
'try {',
|
|
6906
|
-
Template.indent([
|
|
6907
|
-
`if (typeof globalThis === "object" && globalThis && typeof globalThis.browser !== "undefined" && ${optionalChaining ? 'typeof globalThis.browser.runtime?.getURL === "function"' : 'typeof globalThis.browser.runtime === "object" && typeof globalThis.browser.runtime.getURL === "function"'}) {`,
|
|
6908
|
-
Template.indent([
|
|
6909
|
-
'runtime = globalThis.browser;'
|
|
6910
|
-
]),
|
|
6911
|
-
'}'
|
|
6912
|
-
]),
|
|
6913
|
-
'} catch (_) {}',
|
|
6914
|
-
'if (!runtime) {',
|
|
6915
|
-
Template.indent([
|
|
6916
|
-
'try {',
|
|
6917
|
-
Template.indent([
|
|
6918
|
-
`if (typeof globalThis === "object" && globalThis && typeof globalThis.chrome !== "undefined" && ${optionalChaining ? 'typeof globalThis.chrome.runtime?.getURL === "function"' : 'typeof globalThis.chrome.runtime === "object" && typeof globalThis.chrome.runtime.getURL === "function"'}) {`,
|
|
6919
|
-
Template.indent([
|
|
6920
|
-
'isChrome = true;',
|
|
6921
|
-
'runtime = globalThis.chrome;'
|
|
6922
|
-
]),
|
|
6923
|
-
'}'
|
|
6924
|
-
]),
|
|
6925
|
-
'} catch (_) {}'
|
|
6926
|
-
]),
|
|
6927
|
-
'}',
|
|
6928
|
-
`${RuntimeGlobalIsBrowser} = !isChrome;`,
|
|
6929
|
-
`${RuntimeGlobal} = runtime || { runtime: null };`,
|
|
6930
|
-
acceptWeak ? 'if (!runtime && (typeof self !== "object" || !self.addEventListener)) {' : '',
|
|
6931
|
-
acceptWeak ? Template.indent([
|
|
6932
|
-
`${RuntimeGlobal} = { runtime: { getURL: String } };`
|
|
6933
|
-
]) : '',
|
|
6934
|
-
acceptWeak ? '}' : ''
|
|
6935
|
-
].filter(Boolean));
|
|
6936
|
-
}
|
|
6937
|
-
}
|
|
6938
|
-
return new BrowserRuntime();
|
|
6939
|
-
}
|
|
6940
|
-
const DYNAMIC_IMPORT_LOADER = 'dynamicImportLoader';
|
|
6941
|
-
const DOM_LOADER = "scriptLoader";
|
|
6942
|
-
const WORKER_LOADER = 'workerLoader';
|
|
6943
|
-
const CLASSIC_LOADER = 'classicLoader';
|
|
6944
|
-
const MAIN_CLASSIC_LOADER = 'classicLoaderMainWorld';
|
|
6945
|
-
const FALLBACK_LOADER = 'fallbackLoader';
|
|
6946
|
-
function LoadScriptRuntimeModule(webpack, supportDynamicImport, classicLoaderEnabled, contentScriptsMeta) {
|
|
6947
|
-
const { Template, RuntimeGlobals, RuntimeModule } = webpack;
|
|
6948
|
-
class LoadScriptRuntime extends RuntimeModule {
|
|
6949
|
-
supportDynamicImport;
|
|
6950
|
-
classicLoaderEnabled;
|
|
6951
|
-
contentScriptsMeta;
|
|
6952
|
-
constructor(){
|
|
6953
|
-
super("load script", RuntimeModule.STAGE_BASIC);
|
|
6954
|
-
this.supportDynamicImport = Boolean(supportDynamicImport);
|
|
6955
|
-
this.classicLoaderEnabled = Boolean(classicLoaderEnabled);
|
|
6956
|
-
this.contentScriptsMeta = contentScriptsMeta || {};
|
|
6957
|
-
}
|
|
6958
|
-
generate() {
|
|
6959
|
-
const { compilation } = this;
|
|
6960
|
-
if (!compilation) return Template.asString('/* [webpack-target-webextension] ChunkLoaderFallbackRuntimeModule skipped because no compilation is found. */');
|
|
6961
|
-
const { f } = TemplateFn(compilation, Template);
|
|
6962
|
-
const _const = compilation.outputOptions.environment.const ? 'const' : 'var';
|
|
6963
|
-
const _let = compilation.outputOptions.environment.const ? 'let' : 'var';
|
|
6964
|
-
const chunkName = (this.chunk && this.chunk.name ? this.chunk.name : '') || (compilation && compilation.chunk && compilation.chunk.name ? compilation.chunk.name : '');
|
|
6965
|
-
const bundleId = chunkName ? `${chunkName}.js` : '';
|
|
6966
|
-
const world = bundleId && this.contentScriptsMeta[bundleId] ? this.contentScriptsMeta[bundleId].world : void 0;
|
|
6967
|
-
const isMainWorld = 'main' === world;
|
|
6968
|
-
const HasExtensionRuntime = `${_const} hasExtensionRuntime = (function(){ try {return ((typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.sendMessage === "function") || (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.sendMessage === "function"));} catch (e) { return false; } })();`;
|
|
6969
|
-
const DynamicImportLoader = `${_const} ${DYNAMIC_IMPORT_LOADER} = ` + f('url, done, key, chunkId', `import(url).then(${f('', [
|
|
6970
|
-
'if (isNotIframe) return done();',
|
|
6971
|
-
'try {',
|
|
6972
|
-
Template.indent([
|
|
6973
|
-
"// It's a Chrome bug, if the import() is called in a sandboxed iframe, it _fails_ the script loading but _resolve_ the Promise.",
|
|
6974
|
-
`// we call ${RuntimeGlobals.ensureChunkHandlers}.j(chunkId) to check if it is loaded.`,
|
|
6975
|
-
'// if it is, this is a no-op. if it is not, it will throw a TypeError because this function requires 2 parameters.',
|
|
6976
|
-
'// This call will not trigger the chunk loading because it is already loading.',
|
|
6977
|
-
'// see https://github.com/awesome-webextension/webpack-target-webextension/issues/41',
|
|
6978
|
-
`chunkId !== undefined && ${RuntimeGlobals.ensureChunkHandlers}.j(chunkId);`,
|
|
6979
|
-
'done();'
|
|
6980
|
-
]),
|
|
6981
|
-
'}',
|
|
6982
|
-
'catch (_) {',
|
|
6983
|
-
Template.indent([
|
|
6984
|
-
'if (!bug816121warned) {',
|
|
6985
|
-
Template.indent([
|
|
6986
|
-
'console.warn("Chrome bug https://crbug.com/816121 hit.");',
|
|
6987
|
-
'bug816121warned = true;'
|
|
6988
|
-
]),
|
|
6989
|
-
'}',
|
|
6990
|
-
`return ${FALLBACK_LOADER}(url, done, key, chunkId);`
|
|
6991
|
-
]),
|
|
6992
|
-
'}'
|
|
6993
|
-
])}, ${f('e', [
|
|
6994
|
-
'console.warn("Dynamic import loader failed. Using fallback loader (see https://github.com/awesome-webextension/webpack-target-webextension#content-script).", e);',
|
|
6995
|
-
`${FALLBACK_LOADER}(url, done, key, chunkId);`
|
|
6996
|
-
])});`);
|
|
6997
|
-
const DOMLoader = `${_const} ${DOM_LOADER} = ` + f('url, done', [
|
|
6998
|
-
`${_const} script = document.createElement('script');`,
|
|
6999
|
-
"script.src = url;",
|
|
7000
|
-
"script.onload = done;",
|
|
7001
|
-
"script.onerror = done;",
|
|
7002
|
-
"document.body.appendChild(script);"
|
|
7003
|
-
]);
|
|
7004
|
-
const WorkerLoader = `${_const} ${WORKER_LOADER} = ` + f('url, done', [
|
|
7005
|
-
'try {',
|
|
7006
|
-
Template.indent([
|
|
7007
|
-
'importScripts(url);',
|
|
7008
|
-
'done();'
|
|
7009
|
-
]),
|
|
7010
|
-
'} catch (e) {',
|
|
7011
|
-
Template.indent([
|
|
7012
|
-
'done(e);'
|
|
7013
|
-
]),
|
|
7014
|
-
'}'
|
|
7015
|
-
]);
|
|
7016
|
-
const ClassicLoader = `${_const} ${CLASSIC_LOADER} = ` + f('url, done', Template.asString([
|
|
7017
|
-
`${_const} msg = { type: "WTW_INJECT", file: url };`,
|
|
7018
|
-
`${_const} onError = ${f('e', 'done(Object.assign(e, { type: "missing" }))')};`,
|
|
7019
|
-
'try {',
|
|
7020
|
-
`if (${RuntimeGlobalIsBrowser}) {`,
|
|
7021
|
-
Template.indent([
|
|
7022
|
-
`${RuntimeGlobal}.runtime.sendMessage(msg).then(done, onError);`
|
|
7023
|
-
]),
|
|
7024
|
-
'} else {',
|
|
7025
|
-
Template.indent([
|
|
7026
|
-
`${RuntimeGlobal}.runtime.sendMessage(msg, ${f('', [
|
|
7027
|
-
`${_const} error = ${RuntimeGlobal}.runtime.lastError;`,
|
|
7028
|
-
'if (error) onError(error);',
|
|
7029
|
-
'else done();'
|
|
7030
|
-
])});`
|
|
7031
|
-
]),
|
|
7032
|
-
'}',
|
|
7033
|
-
'} catch (e) { onError(e); }'
|
|
7034
|
-
])) + ';';
|
|
7035
|
-
const ClassicLoaderDisabled = `${_const} ${CLASSIC_LOADER} = ` + f('', [
|
|
7036
|
-
"throw new Error(\"[webpack-target-webextension] Failed to load async chunk in the content script. No script loader is found. You can either\\n - Set output.environment.dynamicImport to true if your environment supports native ES Module\\n - Specify the background entry to enable the fallback loader\\n - Set module.parser.javascript.dynamicImportMode to 'eager' to inline all async chunks.\");"
|
|
7037
|
-
]);
|
|
7038
|
-
return Template.asString([
|
|
7039
|
-
this.supportDynamicImport ? `${_let} bug816121warned, isNotIframe;` : '',
|
|
7040
|
-
this.supportDynamicImport ? Template.asString([
|
|
7041
|
-
'try {',
|
|
7042
|
-
Template.indent([
|
|
7043
|
-
'isNotIframe = typeof window === "object" ? window.top === window : true;'
|
|
7044
|
-
]),
|
|
7045
|
-
'} catch(e) {',
|
|
7046
|
-
Template.indent([
|
|
7047
|
-
'isNotIframe = false /* CORS error */;'
|
|
7048
|
-
]),
|
|
7049
|
-
'}'
|
|
7050
|
-
]) : '',
|
|
7051
|
-
HasExtensionRuntime,
|
|
7052
|
-
this.classicLoaderEnabled ? ClassicLoader : ClassicLoaderDisabled,
|
|
7053
|
-
this.supportDynamicImport ? DynamicImportLoader : '',
|
|
7054
|
-
DOMLoader,
|
|
7055
|
-
WorkerLoader,
|
|
7056
|
-
`${_const} isWorker = typeof importScripts === 'function'`,
|
|
7057
|
-
"if (typeof location === 'object' && location.protocol.includes('-extension:')) {",
|
|
7058
|
-
Template.indent([
|
|
7059
|
-
`${RuntimeGlobals.loadScript} = isWorker ? ${WORKER_LOADER} : ${DOM_LOADER};`
|
|
7060
|
-
]),
|
|
7061
|
-
"} else {",
|
|
7062
|
-
Template.indent(isMainWorld ? Template.asString([
|
|
7063
|
-
`${_const} __extjsMark = "__extjs__";`,
|
|
7064
|
-
`${_const} __extjsReqType = "EXTJS_WTW_LOAD";`,
|
|
7065
|
-
`${_const} __extjsResType = "EXTJS_WTW_LOADED";`,
|
|
7066
|
-
`${_const} ${MAIN_CLASSIC_LOADER} = ` + f('url, done', [
|
|
7067
|
-
`${_const} requestId = String(Date.now()) + "-" + Math.random().toString(16).slice(2);`,
|
|
7068
|
-
`${_const} onMessage = ${f('event', [
|
|
7069
|
-
'try {',
|
|
7070
|
-
Template.indent([
|
|
7071
|
-
'if (!event || event.source !== window) return;',
|
|
7072
|
-
`${_const} data = event.data || null;`,
|
|
7073
|
-
"if (!data || data[__extjsMark] !== true) return;",
|
|
7074
|
-
"if (data.type !== __extjsResType || data.requestId !== requestId) return;",
|
|
7075
|
-
'window.removeEventListener("message", onMessage);',
|
|
7076
|
-
'if (data.ok) done();',
|
|
7077
|
-
'else done(Object.assign(new Error(data.error || "Bridge failed"), { type: "missing" }));'
|
|
7078
|
-
]),
|
|
7079
|
-
'} catch (e) {',
|
|
7080
|
-
Template.indent([
|
|
7081
|
-
'window.removeEventListener("message", onMessage);',
|
|
7082
|
-
'done(Object.assign(e, { type: "missing" }));'
|
|
7083
|
-
]),
|
|
7084
|
-
'}'
|
|
7085
|
-
])};`,
|
|
7086
|
-
'window.addEventListener("message", onMessage);',
|
|
7087
|
-
'try {',
|
|
7088
|
-
Template.indent([
|
|
7089
|
-
'window.postMessage({ [__extjsMark]: true, type: __extjsReqType, requestId: requestId, url: url }, "*");'
|
|
7090
|
-
]),
|
|
7091
|
-
'} catch (e) {',
|
|
7092
|
-
Template.indent([
|
|
7093
|
-
'window.removeEventListener("message", onMessage);',
|
|
7094
|
-
'done(Object.assign(e, { type: "missing" }));'
|
|
7095
|
-
]),
|
|
7096
|
-
'}',
|
|
7097
|
-
'setTimeout(function(){ try { window.removeEventListener("message", onMessage); } catch(_){} done(Object.assign(new Error("Bridge timeout"), { type: "missing" })); }, 5000);'
|
|
7098
|
-
]) + ';',
|
|
7099
|
-
`if (!isWorker) ${RuntimeGlobals.loadScript} = ${MAIN_CLASSIC_LOADER};`
|
|
7100
|
-
]) : Template.asString([
|
|
7101
|
-
`if (!isWorker && hasExtensionRuntime) ${RuntimeGlobals.loadScript} = ${CLASSIC_LOADER};`,
|
|
7102
|
-
`else if (!isWorker) ${RuntimeGlobals.loadScript} = ${DOM_LOADER};`
|
|
7103
|
-
])),
|
|
7104
|
-
"}",
|
|
7105
|
-
this.supportDynamicImport ? `${_const} ${FALLBACK_LOADER} = ${RuntimeGlobals.loadScript};` : '',
|
|
7106
|
-
this.supportDynamicImport ? `${RuntimeGlobals.loadScript} = ${DYNAMIC_IMPORT_LOADER};` : ''
|
|
7107
|
-
].filter(Boolean));
|
|
7108
|
-
}
|
|
7109
|
-
}
|
|
7110
|
-
return new LoadScriptRuntime();
|
|
7111
|
-
}
|
|
7112
|
-
function PublicPath_PublicPathRuntimeModule(webpack) {
|
|
7113
|
-
const { RuntimeGlobals, RuntimeModule, Template } = webpack;
|
|
7114
|
-
class PublicPathRuntime extends RuntimeModule {
|
|
7115
|
-
constructor(){
|
|
7116
|
-
super('publicPath', RuntimeModule.STAGE_BASIC);
|
|
7117
|
-
}
|
|
7118
|
-
generate() {
|
|
7119
|
-
const { compilation } = this;
|
|
7120
|
-
if (!compilation) return Template.asString('/* [webpack-target-webextension] PublicPathRuntimeModule skipped because no compilation is found. */');
|
|
7121
|
-
const { publicPath } = compilation.outputOptions;
|
|
7122
|
-
const path = JSON.stringify(compilation.getPath(publicPath || '', {
|
|
7123
|
-
hash: compilation.hash || 'XXXX'
|
|
7124
|
-
}));
|
|
7125
|
-
return Template.asString([
|
|
7126
|
-
'var __extjsBase = (typeof globalThis === "object" && globalThis && globalThis.__EXTJS_EXTENSION_BASE__) ? String(globalThis.__EXTJS_EXTENSION_BASE__) : "";',
|
|
7127
|
-
'if (!__extjsBase && typeof document === "object" && document && document.documentElement) {',
|
|
7128
|
-
Template.indent([
|
|
7129
|
-
'try { __extjsBase = document.documentElement.getAttribute("data-extjs-extension-base") || ""; } catch(_) { __extjsBase = ""; }'
|
|
7130
|
-
]),
|
|
7131
|
-
"}",
|
|
7132
|
-
'var __extjsRuntimePath = "";',
|
|
7133
|
-
`if (${RuntimeGlobal} && ${RuntimeGlobal}.runtime && typeof ${RuntimeGlobal}.runtime.getURL === "function") {`,
|
|
7134
|
-
Template.indent([
|
|
7135
|
-
`try { __extjsRuntimePath = ${RuntimeGlobal}.runtime.getURL(${path}); } catch (_) { __extjsRuntimePath = ""; }`
|
|
7136
|
-
]),
|
|
7137
|
-
"}",
|
|
7138
|
-
"if (__extjsRuntimePath) {",
|
|
7139
|
-
Template.indent([
|
|
7140
|
-
`${RuntimeGlobals.publicPath} = __extjsRuntimePath;`
|
|
7141
|
-
]),
|
|
7142
|
-
"} else if (__extjsBase) {",
|
|
7143
|
-
Template.indent([
|
|
7144
|
-
`${RuntimeGlobals.publicPath} = __extjsBase.replace(/\\/+$/, "/") + String(${path}).replace(/^\\/+/, "");`
|
|
7145
|
-
]),
|
|
7146
|
-
"} else {",
|
|
7147
|
-
Template.indent([
|
|
7148
|
-
`${RuntimeGlobals.publicPath} = "";`
|
|
7149
|
-
]),
|
|
7150
|
-
"}",
|
|
7151
|
-
'if (!__extjsBase && typeof document === "object" && document && document.documentElement) {',
|
|
7152
|
-
Template.indent([
|
|
7153
|
-
"try {",
|
|
7154
|
-
Template.indent([
|
|
7155
|
-
"var __extjsRetries = 0;",
|
|
7156
|
-
"var __extjsUpdateBase = function(){",
|
|
7157
|
-
Template.indent([
|
|
7158
|
-
'var base = "";',
|
|
7159
|
-
'try { base = document.documentElement.getAttribute("data-extjs-extension-base") || ""; } catch(_) { base = ""; }',
|
|
7160
|
-
"if (base) {",
|
|
7161
|
-
Template.indent([
|
|
7162
|
-
`${RuntimeGlobals.publicPath} = base.replace(/\\/+$/, "/") + String(${path}).replace(/^\\/+/, "");`
|
|
7163
|
-
]),
|
|
7164
|
-
"} else if (__extjsRetries++ < 50) {",
|
|
7165
|
-
Template.indent([
|
|
7166
|
-
"setTimeout(__extjsUpdateBase, 100);"
|
|
7167
|
-
]),
|
|
7168
|
-
"}"
|
|
7169
|
-
]),
|
|
7170
|
-
"};",
|
|
7171
|
-
"__extjsUpdateBase();"
|
|
7172
|
-
]),
|
|
7173
|
-
"} catch (_) {}"
|
|
7174
|
-
]),
|
|
7175
|
-
"}"
|
|
7176
|
-
]);
|
|
7177
|
-
}
|
|
7178
|
-
}
|
|
7179
|
-
return new PublicPathRuntime();
|
|
7180
|
-
}
|
|
7181
|
-
function AutoPublicPathRuntimeModule(webpack) {
|
|
7182
|
-
const { RuntimeModule, RuntimeGlobals, Template, javascript: { JavascriptModulesPlugin }, HotUpdateChunk } = webpack;
|
|
7183
|
-
const getChunkFilenameTemplate = JavascriptModulesPlugin.getChunkFilenameTemplate || function(chunk, outputOptions) {
|
|
7184
|
-
if (chunk.filenameTemplate) return chunk.filenameTemplate;
|
|
7185
|
-
if ('function' == typeof HotUpdateChunk && chunk instanceof HotUpdateChunk) return outputOptions.hotUpdateChunkFilename;
|
|
7186
|
-
if (chunk.canBeInitial()) return outputOptions.filename;
|
|
7187
|
-
return outputOptions.chunkFilename;
|
|
7188
|
-
};
|
|
7189
|
-
class AutoPublicPathRuntime extends RuntimeModule {
|
|
7190
|
-
constructor(){
|
|
7191
|
-
super('publicPath', RuntimeModule.STAGE_BASIC);
|
|
7192
|
-
}
|
|
7193
|
-
generate() {
|
|
7194
|
-
const { compilation } = this;
|
|
7195
|
-
if (!compilation || !this.chunk) return Template.asString('/* [webpack-target-webextension] AutoPublicPathRuntimeModule skipped because no compilation/chunk is found. */');
|
|
7196
|
-
const { scriptType, importMetaName } = compilation.outputOptions;
|
|
7197
|
-
const chunkName = compilation.getPath(getChunkFilenameTemplate(this.chunk, compilation.outputOptions), {
|
|
7198
|
-
chunk: this.chunk,
|
|
7199
|
-
contentHashType: "javascript"
|
|
7200
|
-
});
|
|
7201
|
-
const outputPath = compilation.outputOptions.path;
|
|
7202
|
-
if (!outputPath) return Template.asString('/* [webpack-target-webextension] AutoPublicPathRuntimeModule skipped because no output path is found. */');
|
|
7203
|
-
const undoPath = getUndoPath(chunkName, outputPath, false);
|
|
7204
|
-
const optionalChaining = compilation.outputOptions.environment.optionalChaining;
|
|
7205
|
-
const _const = compilation.outputOptions.environment.const ? 'const' : 'var';
|
|
7206
|
-
const _let = compilation.outputOptions.environment.const ? 'let' : 'var';
|
|
7207
|
-
return Template.asString([
|
|
7208
|
-
`${_let} scriptUrl;`,
|
|
7209
|
-
'module' === scriptType ? `if (typeof ${importMetaName}.url === "string") scriptUrl = ${importMetaName}.url;` : Template.asString([
|
|
7210
|
-
`if (${RuntimeGlobals.global}.importScripts) scriptUrl = ${RuntimeGlobals.global}.location + "";`,
|
|
7211
|
-
`${_const} document = ${RuntimeGlobals.global}.document;`,
|
|
7212
|
-
`if (!scriptUrl && ${optionalChaining ? 'document?.currentScript' : 'document && document.currentScript'}) {`,
|
|
7213
|
-
Template.indent("scriptUrl = document.currentScript.src;"),
|
|
7214
|
-
'}'
|
|
7215
|
-
]),
|
|
7216
|
-
'// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration',
|
|
7217
|
-
'// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.',
|
|
7218
|
-
'var __extjsBase = (typeof globalThis === "object" && globalThis && globalThis.__EXTJS_EXTENSION_BASE__) ? String(globalThis.__EXTJS_EXTENSION_BASE__) : "";',
|
|
7219
|
-
'if (!__extjsBase && typeof document === "object" && document && document.documentElement) {',
|
|
7220
|
-
Template.indent([
|
|
7221
|
-
'try { __extjsBase = document.documentElement.getAttribute("data-extjs-extension-base") || ""; } catch(_) { __extjsBase = ""; }'
|
|
7222
|
-
]),
|
|
7223
|
-
"}",
|
|
7224
|
-
"if (__extjsBase && scriptUrl && !/^((chrome|moz)-extension):///.test(scriptUrl)) {",
|
|
7225
|
-
Template.indent([
|
|
7226
|
-
"scriptUrl = __extjsBase;"
|
|
7227
|
-
]),
|
|
7228
|
-
"}",
|
|
7229
|
-
"if (!scriptUrl) {",
|
|
7230
|
-
Template.indent([
|
|
7231
|
-
'var __extjsRuntimeRoot = "";',
|
|
7232
|
-
`if (${RuntimeGlobal} && ${RuntimeGlobal}.runtime && typeof ${RuntimeGlobal}.runtime.getURL === "function") {`,
|
|
7233
|
-
Template.indent(`try { __extjsRuntimeRoot = ${RuntimeGlobal}.runtime.getURL("/"); } catch (_) { __extjsRuntimeRoot = ""; }`),
|
|
7234
|
-
Template.indent("scriptUrl = __extjsRuntimeRoot || scriptUrl;"),
|
|
7235
|
-
"} else {",
|
|
7236
|
-
Template.indent('scriptUrl = __extjsBase || "";'),
|
|
7237
|
-
"}"
|
|
7238
|
-
]),
|
|
7239
|
-
'}',
|
|
7240
|
-
'scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");',
|
|
7241
|
-
undoPath ? `${RuntimeGlobals.publicPath} = scriptUrl + ${JSON.stringify(undoPath)};` : `${RuntimeGlobals.publicPath} = scriptUrl;`,
|
|
7242
|
-
'if (!scriptUrl && typeof document === "object" && document && document.documentElement) {',
|
|
7243
|
-
Template.indent([
|
|
7244
|
-
"try {",
|
|
7245
|
-
Template.indent([
|
|
7246
|
-
"var __extjsRetries = 0;",
|
|
7247
|
-
"var __extjsUpdateBase = function(){",
|
|
7248
|
-
Template.indent([
|
|
7249
|
-
'var base = "";',
|
|
7250
|
-
'try { base = document.documentElement.getAttribute("data-extjs-extension-base") || ""; } catch(_) { base = ""; }',
|
|
7251
|
-
"if (base) {",
|
|
7252
|
-
Template.indent([
|
|
7253
|
-
'var normalized = base.replace(/\\/+$/, "/");',
|
|
7254
|
-
undoPath ? `${RuntimeGlobals.publicPath} = normalized + ${JSON.stringify(undoPath)};` : `${RuntimeGlobals.publicPath} = normalized;`
|
|
7255
|
-
]),
|
|
7256
|
-
"} else if (__extjsRetries++ < 50) {",
|
|
7257
|
-
Template.indent([
|
|
7258
|
-
"setTimeout(__extjsUpdateBase, 100);"
|
|
7259
|
-
]),
|
|
7260
|
-
"}"
|
|
7261
|
-
]),
|
|
7262
|
-
"};",
|
|
7263
|
-
"__extjsUpdateBase();"
|
|
7264
|
-
]),
|
|
7265
|
-
"} catch (_) {}"
|
|
7266
|
-
]),
|
|
7267
|
-
"}"
|
|
7268
|
-
]);
|
|
7269
|
-
}
|
|
7270
|
-
}
|
|
7271
|
-
return new AutoPublicPathRuntime();
|
|
7272
|
-
}
|
|
7273
|
-
function getUndoPath(filename, outputPath, enforceRelative) {
|
|
7274
|
-
let depth = -1;
|
|
7275
|
-
let append = '';
|
|
7276
|
-
outputPath = outputPath.replace(/[\\/]$/, '');
|
|
7277
|
-
for (const part of filename.split(/[/\\]+/))if ('..' === part) if (depth > -1) depth--;
|
|
7278
|
-
else {
|
|
7279
|
-
const i = outputPath.lastIndexOf('/');
|
|
7280
|
-
const j = outputPath.lastIndexOf('\\');
|
|
7281
|
-
const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
|
|
7282
|
-
if (pos < 0) return outputPath + '/';
|
|
7283
|
-
append = outputPath.slice(pos + 1) + '/' + append;
|
|
7284
|
-
outputPath = outputPath.slice(0, pos);
|
|
7285
|
-
}
|
|
7286
|
-
else if ('.' !== part) depth++;
|
|
7287
|
-
return depth > 0 ? `${'../'.repeat(depth)}${append}` : enforceRelative ? `./${append}` : append;
|
|
7288
|
-
}
|
|
7289
|
-
function BaseUriRuntimeModule(webpack) {
|
|
7290
|
-
const { RuntimeGlobals, RuntimeModule, Template } = webpack;
|
|
7291
|
-
class BaseUriRuntime extends RuntimeModule {
|
|
7292
|
-
constructor(){
|
|
7293
|
-
super('baseURI', RuntimeModule.STAGE_BASIC);
|
|
7294
|
-
}
|
|
7295
|
-
generate() {
|
|
7296
|
-
return Template.asString([
|
|
7297
|
-
'var __extjsBase = "";',
|
|
7298
|
-
"try {",
|
|
7299
|
-
Template.indent([
|
|
7300
|
-
`if (${RuntimeGlobal} && ${RuntimeGlobal}.runtime && typeof ${RuntimeGlobal}.runtime.getURL === "function") {`,
|
|
7301
|
-
Template.indent([
|
|
7302
|
-
`__extjsBase = String(${RuntimeGlobal}.runtime.getURL("/"));`
|
|
7303
|
-
]),
|
|
7304
|
-
"}"
|
|
7305
|
-
]),
|
|
7306
|
-
"} catch (_) {}",
|
|
7307
|
-
'if (!__extjsBase && typeof globalThis === "object" && globalThis && globalThis.__EXTJS_EXTENSION_BASE__) {',
|
|
7308
|
-
Template.indent([
|
|
7309
|
-
'__extjsBase = String(globalThis.__EXTJS_EXTENSION_BASE__ || "");'
|
|
7310
|
-
]),
|
|
7311
|
-
"}",
|
|
7312
|
-
'if (!__extjsBase && typeof document === "object" && document && document.documentElement) {',
|
|
7313
|
-
Template.indent([
|
|
7314
|
-
'try { __extjsBase = String(document.documentElement.getAttribute("data-extjs-extension-base") || ""); } catch (_) { __extjsBase = ""; }'
|
|
7315
|
-
]),
|
|
7316
|
-
"}",
|
|
7317
|
-
"if (__extjsBase) {",
|
|
7318
|
-
Template.indent([
|
|
7319
|
-
`${RuntimeGlobals.baseURI} = __extjsBase;`
|
|
7320
|
-
]),
|
|
7321
|
-
'} else if (typeof document !== "undefined" && document.baseURI) {',
|
|
7322
|
-
Template.indent([
|
|
7323
|
-
`${RuntimeGlobals.baseURI} = document.baseURI;`
|
|
7324
|
-
]),
|
|
7325
|
-
"} else {",
|
|
7326
|
-
Template.indent([
|
|
7327
|
-
`${RuntimeGlobals.baseURI} = self.location.href;`
|
|
7328
|
-
]),
|
|
7329
|
-
"}"
|
|
7330
|
-
]);
|
|
7331
|
-
}
|
|
7332
|
-
}
|
|
7333
|
-
return new BaseUriRuntime();
|
|
7334
|
-
}
|
|
7335
|
-
function ChunkLoaderFallbackRuntimeModule(webpack) {
|
|
7336
|
-
const { RuntimeModule, Template } = webpack;
|
|
7337
|
-
class ChunkLoaderFallbackRuntime extends RuntimeModule {
|
|
7338
|
-
constructor(){
|
|
7339
|
-
super('chunk loader fallback', RuntimeModule.STAGE_TRIGGER);
|
|
7340
|
-
}
|
|
7341
|
-
generate() {
|
|
7342
|
-
const { compilation } = this;
|
|
7343
|
-
if (!compilation) return Template.asString('/* [webpack-target-webextension] ChunkLoaderFallbackRuntimeModule skipped because no compilation is found. */');
|
|
7344
|
-
const { f } = TemplateFn(compilation, Template);
|
|
7345
|
-
const optionalChain = compilation.outputOptions.environment.optionalChaining;
|
|
7346
|
-
const _const = compilation.outputOptions.environment.const ? 'const' : 'var';
|
|
7347
|
-
const _let = compilation.outputOptions.environment.const ? 'let' : 'var';
|
|
7348
|
-
return `if (${RuntimeGlobal} && ${RuntimeGlobal}.runtime && ${RuntimeGlobal}.runtime.onMessage) {${RuntimeGlobal}.runtime.onMessage.addListener(` + f('message, sender, sendResponse', [
|
|
7349
|
-
optionalChain ? 'if (message?.type != "WTW_INJECT" || typeof sender?.tab?.id != "number") return;' : 'if (!message || message.type != "WTW_INJECT" || !sender || !sender.tab || sender.tab.id == null) return;',
|
|
7350
|
-
`${_let} file = message.file;`,
|
|
7351
|
-
'try {',
|
|
7352
|
-
Template.indent([
|
|
7353
|
-
'file = new URL(file).pathname;'
|
|
7354
|
-
]),
|
|
7355
|
-
'} catch (_) {}',
|
|
7356
|
-
'if (!file) return;',
|
|
7357
|
-
`if (${RuntimeGlobal}.scripting) {`,
|
|
7358
|
-
Template.indent([
|
|
7359
|
-
`${RuntimeGlobal}.scripting.executeScript({`,
|
|
7360
|
-
Template.indent([
|
|
7361
|
-
'target: { tabId: sender.tab.id, frameIds: [sender.frameId] },',
|
|
7362
|
-
'files: [file],'
|
|
7363
|
-
]),
|
|
7364
|
-
'}).then(sendResponse);'
|
|
7365
|
-
]),
|
|
7366
|
-
"} else {",
|
|
7367
|
-
Template.indent([
|
|
7368
|
-
`${_const} details = { frameId: sender.frameId, file, matchAboutBlank: true };`,
|
|
7369
|
-
`if (${RuntimeGlobalIsBrowser}) {`,
|
|
7370
|
-
`${RuntimeGlobal}.tabs.executeScript(sender.tab.id, details).then(sendResponse);`,
|
|
7371
|
-
'} else {',
|
|
7372
|
-
`${RuntimeGlobal}.tabs.executeScript(sender.tab.id, details, sendResponse);`,
|
|
7373
|
-
'}'
|
|
7374
|
-
]),
|
|
7375
|
-
'}',
|
|
7376
|
-
'return true;'
|
|
7377
|
-
]) + ");}";
|
|
7378
|
-
}
|
|
7379
|
-
}
|
|
7380
|
-
return new ChunkLoaderFallbackRuntime();
|
|
7381
|
-
}
|
|
7382
|
-
class WebExtensionChuckLoaderRuntimePlugin {
|
|
7383
|
-
pluginOptions;
|
|
7384
|
-
options;
|
|
7385
|
-
contentScriptsMeta;
|
|
7386
|
-
rspackAutoPublicPath = false;
|
|
7387
|
-
constructor(options){
|
|
7388
|
-
this.pluginOptions = options || {};
|
|
7389
|
-
this.options = this.pluginOptions.background || this.pluginOptions || {};
|
|
7390
|
-
this.contentScriptsMeta = this.pluginOptions.contentScriptsMeta || {};
|
|
7391
|
-
}
|
|
7392
|
-
apply(compiler) {
|
|
7393
|
-
if ('rspack' in compiler) {
|
|
7394
|
-
const { output } = compiler.options;
|
|
7395
|
-
if (void 0 === output.publicPath || 'auto' === output.publicPath) {
|
|
7396
|
-
output.publicPath = '';
|
|
7397
|
-
this.rspackAutoPublicPath = true;
|
|
7398
|
-
}
|
|
7399
|
-
}
|
|
7400
|
-
compiler.hooks.compilation.tap(WebExtensionChuckLoaderRuntimePlugin.name, (compilation)=>{
|
|
7401
|
-
this.tap(compiler, compilation);
|
|
7402
|
-
});
|
|
7403
|
-
}
|
|
7404
|
-
tap(compiler, compilation) {
|
|
7405
|
-
const { RuntimeGlobals } = compiler.webpack;
|
|
7406
|
-
const { options } = this;
|
|
7407
|
-
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.loadScript).tap(WebExtensionChuckLoaderRuntimePlugin.name, (_chunk, set)=>{
|
|
7408
|
-
set.add(RuntimeGlobal);
|
|
7409
|
-
compilation.addRuntimeModule(_chunk, LoadScriptRuntimeModule(compiler.webpack, false !== compilation.outputOptions.environment.dynamicImport, false !== options.classicLoader, this.contentScriptsMeta));
|
|
7410
|
-
return true;
|
|
7411
|
-
});
|
|
7412
|
-
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.baseURI).tap(WebExtensionChuckLoaderRuntimePlugin.name, (chunk, set)=>{
|
|
7413
|
-
set.add(RuntimeGlobal);
|
|
7414
|
-
compilation.addRuntimeModule(chunk, BaseUriRuntimeModule(compiler.webpack));
|
|
7415
|
-
return true;
|
|
7416
|
-
});
|
|
7417
|
-
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.publicPath).tap(WebExtensionChuckLoaderRuntimePlugin.name, (chunk, set)=>{
|
|
7418
|
-
const { outputOptions } = compilation;
|
|
7419
|
-
const { publicPath, scriptType } = outputOptions;
|
|
7420
|
-
if ('auto' === publicPath || '' === publicPath && this.rspackAutoPublicPath) {
|
|
7421
|
-
const module = AutoPublicPathRuntimeModule(compiler.webpack);
|
|
7422
|
-
set.add(RuntimeGlobal);
|
|
7423
|
-
if ('module' !== scriptType) set.add(RuntimeGlobals.global);
|
|
7424
|
-
compilation.addRuntimeModule(chunk, module);
|
|
7425
|
-
} else {
|
|
7426
|
-
set.add(RuntimeGlobal);
|
|
7427
|
-
const module = PublicPath_PublicPathRuntimeModule(compiler.webpack);
|
|
7428
|
-
if ('string' != typeof publicPath || /\[(full)?hash\]/.test(publicPath)) module.fullHash = true;
|
|
7429
|
-
compilation.addRuntimeModule(chunk, module);
|
|
7430
|
-
}
|
|
7431
|
-
return true;
|
|
7432
|
-
});
|
|
7433
|
-
if (false !== options.classicLoader) compilation.hooks.afterOptimizeModules.tap(WebExtensionChuckLoaderRuntimePlugin.name, ()=>{
|
|
7434
|
-
const { pageEntry, serviceWorkerEntry } = options;
|
|
7435
|
-
const entryPoint1 = pageEntry && compilation.entrypoints.get(pageEntry);
|
|
7436
|
-
const entryPoint2 = serviceWorkerEntry && compilation.entrypoints.get(serviceWorkerEntry);
|
|
7437
|
-
if (entryPoint1) compilation.addRuntimeModule(entryPoint1.chunks[0], ChunkLoaderFallbackRuntimeModule(compiler.webpack));
|
|
7438
|
-
if (entryPoint2) compilation.addRuntimeModule(entryPoint2.chunks[0], ChunkLoaderFallbackRuntimeModule(compiler.webpack));
|
|
7439
|
-
});
|
|
7440
|
-
}
|
|
7441
|
-
}
|
|
7442
|
-
class NoDangerNamePlugin {
|
|
7443
|
-
apply(compiler) {
|
|
7444
|
-
const { Compilation, WebpackError } = compiler.webpack;
|
|
7445
|
-
compiler.hooks.thisCompilation.tap(NoDangerNamePlugin.name, (compilation)=>{
|
|
7446
|
-
compilation.hooks.processAssets.tap({
|
|
7447
|
-
name: NoDangerNamePlugin.name,
|
|
7448
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
7449
|
-
}, (assets)=>{
|
|
7450
|
-
for (const name of Object.keys(assets || {})){
|
|
7451
|
-
if (!name.startsWith('_')) continue;
|
|
7452
|
-
const e = new WebpackError(`[webpack-extension-target] Output file name ${JSON.stringify(name)} starts with "_" which is prohibited.`);
|
|
7453
|
-
e.stack = '';
|
|
7454
|
-
compilation.errors.push(e);
|
|
7455
|
-
}
|
|
7456
|
-
});
|
|
7457
|
-
});
|
|
7458
|
-
}
|
|
7459
|
-
}
|
|
7460
|
-
function createEagerlyLoadChunksRuntimeModule(webpack) {
|
|
7461
|
-
const { RuntimeGlobals, RuntimeModule, Template } = webpack;
|
|
7462
|
-
return class extends RuntimeModule {
|
|
7463
|
-
chunkIds;
|
|
7464
|
-
constructor(chunkIds){
|
|
7465
|
-
super('eagerly load chunks', RuntimeModule.STAGE_NORMAL);
|
|
7466
|
-
this.chunkIds = chunkIds;
|
|
7467
|
-
}
|
|
7468
|
-
generate() {
|
|
7469
|
-
const { compilation } = this;
|
|
7470
|
-
if (!compilation) return Template.asString('/* [webpack-target-webextension] EagerlyLoadChunksRuntimeModule skipped because no compilation is found. */');
|
|
7471
|
-
const _const = compilation.outputOptions.environment.const ? 'const' : 'var';
|
|
7472
|
-
return Template.asString([
|
|
7473
|
-
`${_const} __extjsChunkIds = ${JSON.stringify(this.chunkIds)};`,
|
|
7474
|
-
`${_const} __extjsLoad = ${RuntimeGlobals.ensureChunkHandlers};`,
|
|
7475
|
-
`for (${_const} __extjsId of __extjsChunkIds) __extjsLoad(__extjsId);`
|
|
7476
|
-
]);
|
|
7477
|
-
}
|
|
7478
|
-
};
|
|
7479
|
-
}
|
|
7480
|
-
class WebExtensionServiceWorkerEntryPlugin {
|
|
7481
|
-
options;
|
|
7482
|
-
backgroundOutputEmitted;
|
|
7483
|
-
constructor(options, backgroundOutputEmitted){
|
|
7484
|
-
this.options = options;
|
|
7485
|
-
this.backgroundOutputEmitted = backgroundOutputEmitted;
|
|
7486
|
-
}
|
|
7487
|
-
apply(compiler) {
|
|
7488
|
-
const { javascript, sources } = compiler.webpack;
|
|
7489
|
-
const entry = this.options.serviceWorkerEntry;
|
|
7490
|
-
if (void 0 === entry) return;
|
|
7491
|
-
if (!(compiler.options.output.module || compiler.options.experiments.outputModule)) {
|
|
7492
|
-
const hook = compiler.hooks.entryOption;
|
|
7493
|
-
hook.tap(WebExtensionServiceWorkerEntryPlugin.name, (_context, entries)=>{
|
|
7494
|
-
if ('function' == typeof entries) {
|
|
7495
|
-
if (this.options.noDynamicEntryWarning) return;
|
|
7496
|
-
console.warn(`[webpack-extension-target] Dynamic entry points not supported yet.
|
|
7497
|
-
You must manually set the chuck loading of entry point ${entry} to "import-scripts".
|
|
7498
|
-
|
|
7499
|
-
See https://webpack.js.org/configuration/entry-context/#entry-descriptor
|
|
7500
|
-
|
|
7501
|
-
Set background.noDynamicEntryWarning to true to disable this warning.
|
|
7502
|
-
`);
|
|
7503
|
-
}
|
|
7504
|
-
const selectedEntry = entries?.[entry];
|
|
7505
|
-
if (!selectedEntry) throw new Error(`[webpack-extension-target] There is no entry called ${entry}.`);
|
|
7506
|
-
selectedEntry.chunkLoading = "import-scripts";
|
|
7507
|
-
});
|
|
7508
|
-
}
|
|
7509
|
-
if (false !== this.options.eagerChunkLoading) compiler.hooks.compilation.tap(WebExtensionServiceWorkerEntryPlugin.name, (compilation)=>{
|
|
7510
|
-
compilation.hooks.afterOptimizeChunkIds?.tap(WebExtensionServiceWorkerEntryPlugin.name, ()=>{
|
|
7511
|
-
const entryPoint = compilation.entrypoints.get(entry);
|
|
7512
|
-
if (!entryPoint) return;
|
|
7513
|
-
const entryChunk = entryPoint.getEntrypointChunk();
|
|
7514
|
-
const reachableChunks = getReachableChunks(entryPoint, new Set(entryPoint.chunks));
|
|
7515
|
-
const reachableChunkIds = new Set([
|
|
7516
|
-
...reachableChunks
|
|
7517
|
-
].map((x)=>x.id));
|
|
7518
|
-
for (const id of getInitialChunkIds(entryChunk, compilation.chunkGraph, chunkHasJs))reachableChunkIds.delete(id);
|
|
7519
|
-
if (reachableChunkIds.size) {
|
|
7520
|
-
const EagerlyLoadChunksRuntimeModule = createEagerlyLoadChunksRuntimeModule(compiler.webpack);
|
|
7521
|
-
compilation.hooks.additionalTreeRuntimeRequirements.tap(EagerlyLoadChunksRuntimeModule.name, (chunk, set)=>{
|
|
7522
|
-
if (chunk.id !== entryChunk.id) return;
|
|
7523
|
-
set.add(compiler.webpack.RuntimeGlobals.ensureChunkHandlers);
|
|
7524
|
-
compilation.addRuntimeModule(entryChunk, new EagerlyLoadChunksRuntimeModule([
|
|
7525
|
-
...reachableChunkIds
|
|
7526
|
-
]));
|
|
7527
|
-
});
|
|
7528
|
-
}
|
|
7529
|
-
});
|
|
7530
|
-
});
|
|
7531
|
-
if (false !== this.options.tryCatchWrapper && 'module' !== compiler.options.output.chunkFormat && !this.backgroundOutputEmitted) compiler.hooks.compilation.tap(WebExtensionServiceWorkerEntryPlugin.name, (compilation)=>{
|
|
7532
|
-
const hooks = javascript.JavascriptModulesPlugin.getCompilationHooks(compilation);
|
|
7533
|
-
if (hooks.renderContent) hooks.renderContent.tap(WebExtensionServiceWorkerEntryPlugin.name, (source, context)=>{
|
|
7534
|
-
const entryPoint = compilation.entrypoints.get(entry);
|
|
7535
|
-
const entryChunk = entryPoint?.getEntrypointChunk();
|
|
7536
|
-
if (entryChunk !== context.chunk) return source;
|
|
7537
|
-
return new sources.ConcatSource('/******/ try { // If the initial code of the serviceWorkerEntry throws, the console cannot be opened.\n', source, '\n/******/ } catch (e) {\n/******/ \tPromise.reject(e);\n/******/ }');
|
|
7538
|
-
});
|
|
7539
|
-
});
|
|
7540
|
-
}
|
|
7541
|
-
}
|
|
7542
|
-
function getInitialChunkIds(chunk, chunkGraph, filterFn) {
|
|
7543
|
-
const initialChunkIds = new Set(chunk.ids);
|
|
7544
|
-
for (const c of chunk.getAllInitialChunks())if (!(c === chunk || filterFn(c, chunkGraph)) && c.ids) for (const id of c.ids)initialChunkIds.add(id);
|
|
7545
|
-
return initialChunkIds;
|
|
7546
|
-
}
|
|
7547
|
-
function chunkHasJs(chunk, chunkGraph) {
|
|
7548
|
-
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
|
|
7549
|
-
return !!chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript");
|
|
7550
|
-
}
|
|
7551
|
-
function getReachableChunks(chunkGroup, reachableChunks = new Set(), visitedChunkGroups = new Set()) {
|
|
7552
|
-
for (const x of chunkGroup.getChildren())if (!visitedChunkGroups.has(x)) {
|
|
7553
|
-
visitedChunkGroups.add(x);
|
|
7554
|
-
x.chunks.forEach((c)=>reachableChunks.add(c));
|
|
7555
|
-
getReachableChunks(x, reachableChunks, visitedChunkGroups);
|
|
7556
|
-
}
|
|
7557
|
-
return reachableChunks;
|
|
7558
|
-
}
|
|
7559
|
-
class WebExtensionContentScriptEntryPlugin {
|
|
7560
|
-
options;
|
|
7561
|
-
constructor(options){
|
|
7562
|
-
this.options = options;
|
|
7563
|
-
}
|
|
7564
|
-
apply(compiler) {
|
|
7565
|
-
const { WebpackError, sources, Template } = compiler.webpack;
|
|
7566
|
-
const { experimental_output } = this.options;
|
|
7567
|
-
if (!experimental_output) return;
|
|
7568
|
-
{
|
|
7569
|
-
const sw = this.options.background?.serviceWorkerEntry;
|
|
7570
|
-
if (sw && sw in experimental_output && 'function' == typeof experimental_output[sw]) throw new Error(`[webpack-extension-target] options.experimental_output[${JSON.stringify(sw)}] cannot be a function because it is a service worker entry. Use { file, touch(manifest, file) { manifest.background.service_worker = file; } } instead.`);
|
|
7571
|
-
}
|
|
7572
|
-
compiler.hooks.thisCompilation.tap(WebExtensionContentScriptEntryPlugin.name, (compilation)=>{
|
|
7573
|
-
compilation.hooks.processAssets.tap({
|
|
7574
|
-
name: WebExtensionContentScriptEntryPlugin.name,
|
|
7575
|
-
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVED
|
|
7576
|
-
}, (assets)=>{
|
|
7577
|
-
let manifest;
|
|
7578
|
-
const serviceWorkerEntry = this.options.background?.serviceWorkerEntry;
|
|
7579
|
-
if (serviceWorkerEntry && !(serviceWorkerEntry in experimental_output) && (getInitialFiles(compilation, serviceWorkerEntry)?.length || 0) > 1) {
|
|
7580
|
-
const e = new WebpackError(`[webpack-extension-target] Entry ${JSON.stringify(serviceWorkerEntry)} is not specified in options.experimental_output.`);
|
|
7581
|
-
e.stack = '';
|
|
7582
|
-
compilation.warnings.push(e);
|
|
7583
|
-
}
|
|
7584
|
-
for(const entry in experimental_output){
|
|
7585
|
-
const isBackgroundEntry = entry === serviceWorkerEntry;
|
|
7586
|
-
const entryOption = experimental_output[entry];
|
|
7587
|
-
const initialFiles = getInitialFiles(compilation, entry);
|
|
7588
|
-
if (!initialFiles || 0 === initialFiles.length) {
|
|
7589
|
-
const name = JSON.stringify(entry);
|
|
7590
|
-
const e = new WebpackError(initialFiles ? `[webpack-extension-target] Entry ${name} does not emit any initial file (specified in options.experimental_output).` : `[webpack-extension-target] Entry ${name} does not exist (specified in options.experimental_output).`);
|
|
7591
|
-
e.stack = '';
|
|
7592
|
-
compilation.errors.push(e);
|
|
7593
|
-
continue;
|
|
7594
|
-
}
|
|
7595
|
-
if (false === entryOption) {
|
|
7596
|
-
if (initialFiles.length > 1) {
|
|
7597
|
-
const name = JSON.stringify(entry);
|
|
7598
|
-
const e = new WebpackError(`[webpack-extension-target] Entry ${name} emits more than one initial file which is prohibited (specified in options.experimental_output).`);
|
|
7599
|
-
e.stack = '';
|
|
7600
|
-
compilation.errors.push(e);
|
|
7601
|
-
}
|
|
7602
|
-
continue;
|
|
7603
|
-
}
|
|
7604
|
-
const emitFile = (entryOptionFile, files)=>{
|
|
7605
|
-
if (entryOptionFile in assets) {
|
|
7606
|
-
const e = new WebpackError(`[webpack-extension-target] Cannot override an existing file ${JSON.stringify(entryOptionFile)} (specified by options.experimental_output[${JSON.stringify(entry)}]).`);
|
|
7607
|
-
e.stack = '';
|
|
7608
|
-
compilation.errors.push(e);
|
|
7609
|
-
return;
|
|
7610
|
-
}
|
|
7611
|
-
let code;
|
|
7612
|
-
if (isBackgroundEntry) {
|
|
7613
|
-
const asyncAndSyncFiles = getInitialAndAsyncFiles(compilation, entry);
|
|
7614
|
-
code = 'module' === compilation.outputOptions.chunkFormat ? asyncAndSyncFiles.map((file)=>`import ${JSON.stringify('./' + file)};`) : [
|
|
7615
|
-
'try {',
|
|
7616
|
-
Template.indent('importScripts(' + asyncAndSyncFiles.map((file)=>JSON.stringify(file)).join(', ') + ');'),
|
|
7617
|
-
'} catch (e) {',
|
|
7618
|
-
Template.indent('Promise.reject(e);'),
|
|
7619
|
-
'}'
|
|
7620
|
-
];
|
|
7621
|
-
} else code = [
|
|
7622
|
-
';(() => {',
|
|
7623
|
-
Template.indent([
|
|
7624
|
-
'const getURL = typeof globalThis === "object" && globalThis && typeof globalThis.browser === "object" ? globalThis.browser.runtime.getURL : globalThis.chrome.runtime.getURL;',
|
|
7625
|
-
`${JSON.stringify(files)}.forEach(file => import(getURL(file)));`
|
|
7626
|
-
]),
|
|
7627
|
-
'})();',
|
|
7628
|
-
'null;'
|
|
7629
|
-
];
|
|
7630
|
-
const source = new compiler.webpack.sources.RawSource(Template.asString(code));
|
|
7631
|
-
compilation.emitAsset(entryOptionFile, source);
|
|
7632
|
-
};
|
|
7633
|
-
if ('string' == typeof entryOption) {
|
|
7634
|
-
emitFile(entryOption, initialFiles);
|
|
7635
|
-
continue;
|
|
7636
|
-
}
|
|
7637
|
-
if (!manifest) {
|
|
7638
|
-
const manifestAsset = assets['manifest.json'];
|
|
7639
|
-
const name = JSON.stringify(entry);
|
|
7640
|
-
if (!manifestAsset) {
|
|
7641
|
-
const e = new WebpackError(`[webpack-extension-target] A manifest.json is required (required by options.experimental_output[${name}]). You can emit this file by using CopyPlugin or any other plugins.`);
|
|
7642
|
-
e.stack = '';
|
|
7643
|
-
compilation.errors.push(e);
|
|
7644
|
-
continue;
|
|
7645
|
-
}
|
|
7646
|
-
try {
|
|
7647
|
-
const source = manifestAsset.source();
|
|
7648
|
-
manifest = 'string' == typeof source ? JSON.parse(source) : JSON.parse(source.toString('utf-8'));
|
|
7649
|
-
} catch {
|
|
7650
|
-
const e = new WebpackError(`[webpack-extension-target] Failed to parse manifest.json (required by options.experimental_output[${name}]).`);
|
|
7651
|
-
e.stack = '';
|
|
7652
|
-
e.file = 'manifest.json';
|
|
7653
|
-
compilation.errors.push(e);
|
|
7654
|
-
continue;
|
|
7655
|
-
}
|
|
7656
|
-
}
|
|
7657
|
-
if ('function' == typeof entryOption) entryOption(manifest, initialFiles);
|
|
7658
|
-
else if ('object' == typeof entryOption) {
|
|
7659
|
-
emitFile(entryOption.file, initialFiles);
|
|
7660
|
-
entryOption.touch(manifest, entryOption.file);
|
|
7661
|
-
}
|
|
7662
|
-
}
|
|
7663
|
-
if (manifest) compilation.updateAsset('manifest.json', new sources.RawSource(JSON.stringify(manifest, void 0, 4)));
|
|
7664
|
-
});
|
|
7665
|
-
});
|
|
7666
|
-
}
|
|
7667
|
-
}
|
|
7668
|
-
function getInitialFiles(compilation, entry) {
|
|
7669
|
-
const entryPoint = compilation.entrypoints.get(entry);
|
|
7670
|
-
if (!entryPoint) return;
|
|
7671
|
-
const files = new Set();
|
|
7672
|
-
const runtimeChunk = entryPoint.getRuntimeChunk();
|
|
7673
|
-
if (runtimeChunk) runtimeChunk.files.forEach((file)=>{
|
|
7674
|
-
if (!isJSFile(file)) return;
|
|
7675
|
-
const asset = compilation.getAsset(file);
|
|
7676
|
-
if (!asset) return;
|
|
7677
|
-
if (!asset.info.hotModuleReplacement) files.add(file);
|
|
7678
|
-
});
|
|
7679
|
-
entryPoint.getFiles().forEach((file)=>{
|
|
7680
|
-
if (!isJSFile(file)) return;
|
|
7681
|
-
const asset = compilation.getAsset(file);
|
|
7682
|
-
if (!asset) return;
|
|
7683
|
-
if (!asset.info.hotModuleReplacement) files.add(file);
|
|
7684
|
-
});
|
|
7685
|
-
return [
|
|
7686
|
-
...files
|
|
7687
|
-
];
|
|
7688
|
-
}
|
|
7689
|
-
function getInitialAndAsyncFiles(compilation, entry) {
|
|
7690
|
-
const entryPoint = compilation.entrypoints.get(entry);
|
|
7691
|
-
if (!entryPoint) return [];
|
|
7692
|
-
const files = new Set();
|
|
7693
|
-
const visitedChunk = new Set();
|
|
7694
|
-
function visit(chunk) {
|
|
7695
|
-
const chunkId = 'rspack' in compilation.compiler ? chunk.id && chunk.hash ? chunk.id + chunk.hash : Array.from(chunk.files).join('') : chunk;
|
|
7696
|
-
if (visitedChunk.has(chunkId)) return;
|
|
7697
|
-
visitedChunk.add(chunkId);
|
|
7698
|
-
chunk.files.forEach((file)=>{
|
|
7699
|
-
if (!isJSFile(file)) return;
|
|
7700
|
-
const asset = compilation.getAsset(file);
|
|
7701
|
-
if (!asset) return;
|
|
7702
|
-
if (!asset.info.hotModuleReplacement) files.add(file);
|
|
7703
|
-
});
|
|
7704
|
-
for (const child of chunk.getAllAsyncChunks())visit(child);
|
|
7705
|
-
}
|
|
7706
|
-
entryPoint.chunks.forEach(visit);
|
|
7707
|
-
const allFiles = [
|
|
7708
|
-
...files
|
|
7709
|
-
].filter((file)=>isJSFile(file) && compilation.getAsset(file));
|
|
7710
|
-
return allFiles;
|
|
7711
|
-
}
|
|
7712
|
-
function isJSFile(file) {
|
|
7713
|
-
return file.endsWith('.js') || file.endsWith('.mjs');
|
|
7714
|
-
}
|
|
7715
|
-
class DevServerConfigPlugin {
|
|
7716
|
-
apply(compiler) {
|
|
7717
|
-
if (!compiler.options.devServer) compiler.options.devServer = {};
|
|
7718
|
-
const devServer = compiler.options.devServer;
|
|
7719
|
-
setDefault(devServer, 'devMiddleware', {});
|
|
7720
|
-
setDefault(devServer.devMiddleware, 'writeToDisk', true);
|
|
7721
|
-
if (void 0 === devServer.hot) devServer.hot = 'only';
|
|
7722
|
-
if (!devServer.hot) return;
|
|
7723
|
-
setDefault(devServer, 'host', '127.0.0.1');
|
|
7724
|
-
setDefault(devServer, 'client', {
|
|
7725
|
-
overlay: false,
|
|
7726
|
-
progress: false,
|
|
7727
|
-
webSocketURL: {
|
|
7728
|
-
protocol: 'ws'
|
|
7729
|
-
}
|
|
7730
|
-
});
|
|
7731
|
-
setDefault(devServer.client, 'overlay', false);
|
|
7732
|
-
setDefault(devServer.client, 'progress', false);
|
|
7733
|
-
setDefault(devServer.client, 'webSocketURL', {
|
|
7734
|
-
protocol: 'ws'
|
|
7735
|
-
});
|
|
7736
|
-
setDefault(devServer.client.webSocketURL, 'protocol', 'ws');
|
|
7737
|
-
const connectableHost = resolveClientHost(process.env.EXTENSION_DEV_SERVER_CONNECTABLE_HOST, devServer.host);
|
|
7738
|
-
if (connectableHost) setDefault(devServer.client.webSocketURL, 'hostname', connectableHost);
|
|
7739
|
-
if (devServer.port) setDefault(devServer.client.webSocketURL, 'port', devServer.port);
|
|
7740
|
-
setDefault(devServer, 'allowedHosts', 'all');
|
|
7741
|
-
setDefault(devServer, 'headers', {
|
|
7742
|
-
'Access-Control-Allow-Origin': '*'
|
|
7743
|
-
});
|
|
7744
|
-
setDefault(devServer, 'static', {
|
|
7745
|
-
watch: {
|
|
7746
|
-
ignored: /\bnode_modules\b/
|
|
7747
|
-
}
|
|
7748
|
-
});
|
|
7749
|
-
setDefault(devServer.static, 'watch', {
|
|
7750
|
-
ignored: /\bnode_modules\b/
|
|
7751
|
-
});
|
|
7752
|
-
isObject(devServer.static) && 'watch' in devServer.static && isObject(devServer.static.watch) && setDefault(devServer.static.watch, 'ignored', /\bnode_modules\b/);
|
|
7753
|
-
}
|
|
7754
|
-
}
|
|
7755
|
-
function setDefault(obj, key, val) {
|
|
7756
|
-
if (isObject(obj) && void 0 === obj[key]) obj[key] = val;
|
|
7757
|
-
}
|
|
7758
|
-
const HMRDevServer_WILDCARD_HOSTS = new Set([
|
|
7759
|
-
'0.0.0.0',
|
|
7760
|
-
'::',
|
|
7761
|
-
'[::]',
|
|
7762
|
-
'::0',
|
|
7763
|
-
'*',
|
|
7764
|
-
''
|
|
7765
|
-
]);
|
|
7766
|
-
function resolveClientHost(connectable, bindHost) {
|
|
7767
|
-
const resolved = String(connectable ?? '').trim();
|
|
7768
|
-
if (resolved) return resolved;
|
|
7769
|
-
const bind = 'string' == typeof bindHost ? bindHost.trim() : '';
|
|
7770
|
-
if (!bind) return;
|
|
7771
|
-
return HMRDevServer_WILDCARD_HOSTS.has(bind) ? '127.0.0.1' : bind;
|
|
7772
|
-
}
|
|
7773
|
-
function isObject(x) {
|
|
7774
|
-
return 'object' == typeof x && null !== x;
|
|
7775
|
-
}
|
|
7776
|
-
class WebExtensionPlugin {
|
|
7777
|
-
options;
|
|
7778
|
-
constructor(options = {}){
|
|
7779
|
-
const { background } = options;
|
|
7780
|
-
if (background) {
|
|
7781
|
-
const { serviceWorkerEntry, pageEntry } = background;
|
|
7782
|
-
if ('entry' in background || 'manifest' in background) throw new Error('[webpack-extension-target] background.entry and background.manifest has been removed. Use background.pageEntry and/or background.serviceWorkerEntry instead.');
|
|
7783
|
-
if (serviceWorkerEntry && serviceWorkerEntry === pageEntry) throw new Error(`[webpack-extension-target] background.serviceWorkerEntry must not be the same as background.pageEntry. Service Worker entry only supports importScript, but importScript does not exist in background page (mv2) or limited event page (mv3).
|
|
7784
|
-
A possible fix is to create two new files to be the service worker entry and the page entry, then those two files imports the background entry.`);
|
|
7785
|
-
}
|
|
7786
|
-
this.options = options;
|
|
7787
|
-
}
|
|
7788
|
-
apply(compiler) {
|
|
7789
|
-
const { background, experimental_output } = this.options;
|
|
7790
|
-
if (background?.serviceWorkerEntry) {
|
|
7791
|
-
const serviceWorkerEntry = this.options.background?.serviceWorkerEntry;
|
|
7792
|
-
const output = serviceWorkerEntry ? this.options.experimental_output?.[serviceWorkerEntry] : false;
|
|
7793
|
-
new WebExtensionServiceWorkerEntryPlugin(background, !!output).apply(compiler);
|
|
7794
|
-
}
|
|
7795
|
-
if (experimental_output) new WebExtensionContentScriptEntryPlugin(this.options).apply(compiler);
|
|
7796
|
-
if (false !== this.options.hmrConfig) new DevServerConfigPlugin().apply(compiler);
|
|
7797
|
-
new WebExtensionChuckLoaderRuntimePlugin(this.options).apply(compiler);
|
|
7798
|
-
new NoDangerNamePlugin().apply(compiler);
|
|
7799
|
-
compiler.hooks.environment.tap(WebExtensionPlugin.name, ()=>{
|
|
7800
|
-
const { output } = compiler.options;
|
|
7801
|
-
if (false !== output.environment.dynamicImport) output.environment.dynamicImport = true;
|
|
7802
|
-
if (void 0 !== output.hotUpdateChunkFilename) output.hotUpdateChunkFilename = 'hot/[id].[fullhash].js';
|
|
7803
|
-
if (void 0 !== output.hotUpdateMainFilename) output.hotUpdateMainFilename = 'hot/[runtime].[fullhash].json';
|
|
7804
|
-
});
|
|
7805
|
-
compiler.hooks.compilation.tap(WebExtensionPlugin.name, (compilation)=>{
|
|
7806
|
-
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobal).tap(WebExtensionPlugin.name, (chunk)=>{
|
|
7807
|
-
compilation.addRuntimeModule(chunk, BrowserRuntimeModule(compiler.webpack, !!this.options.weakRuntimeCheck));
|
|
7808
|
-
return true;
|
|
7809
|
-
});
|
|
7810
|
-
});
|
|
7811
|
-
}
|
|
7812
|
-
}
|
|
7813
|
-
const webpack_target_webextension_fork = WebExtensionPlugin;
|
|
7814
|
-
function manifest_filterKeysForThisBrowser(manifest, browser) {
|
|
7815
|
-
return filterKeysForThisBrowser(manifest, browser);
|
|
7816
|
-
}
|
|
7817
|
-
class SetupBackgroundEntry {
|
|
7818
|
-
manifestPath;
|
|
7819
|
-
browser;
|
|
7820
|
-
constructor(options){
|
|
7821
|
-
this.manifestPath = options.manifestPath;
|
|
7822
|
-
this.browser = options.browser || 'chrome';
|
|
7823
|
-
}
|
|
7824
|
-
getMissingBackgroundError(bgFile) {
|
|
7825
|
-
if (!__rspack_external_fs.existsSync(bgFile) && this.manifestPath) {
|
|
7826
|
-
const manifest = JSON.parse(stripBom(__rspack_external_fs.readFileSync(this.manifestPath, 'utf8')));
|
|
7827
|
-
const patched = manifest_filterKeysForThisBrowser(manifest, this.browser);
|
|
7828
|
-
const fieldKey = 3 === patched.manifest_version ? 'background/service_worker' : "background/scripts";
|
|
7829
|
-
return backgroundIsRequiredMessageOnly(fieldKey);
|
|
7830
|
-
}
|
|
7831
|
-
}
|
|
7832
|
-
addDefaultEntry(compiler, name, defaultScript) {
|
|
7833
|
-
compiler.options.entry = {
|
|
7834
|
-
...compiler.options.entry,
|
|
7835
|
-
[name]: {
|
|
7836
|
-
import: [
|
|
7837
|
-
defaultScript
|
|
7838
|
-
]
|
|
7839
|
-
}
|
|
7840
|
-
};
|
|
7841
|
-
}
|
|
7842
|
-
apply(compiler) {
|
|
7843
|
-
const manifest = JSON.parse(stripBom(__rspack_external_fs.readFileSync(this.manifestPath, 'utf-8')));
|
|
7844
|
-
const browser = this.browser;
|
|
7845
|
-
const isGecko = constants_isGeckoBasedBrowser(String(browser));
|
|
7846
|
-
const minimumBgScript = resolveDevelopDistFile(isGecko ? 'minimum-firefox-file' : 'minimum-chromium-file');
|
|
7847
|
-
const dirname = __rspack_external_path.dirname(this.manifestPath);
|
|
7848
|
-
const filteredManifest = manifest_filterKeysForThisBrowser(manifest, browser) || manifest;
|
|
7849
|
-
const manifestBg = filteredManifest?.background ?? manifest.background;
|
|
7850
|
-
const manifestVersion = filteredManifest?.manifest_version ?? manifest.manifest_version;
|
|
7851
|
-
function hookError(maybeError) {
|
|
7852
|
-
compiler.hooks.thisCompilation.tap('run-chromium:setup-background-entry', (compilation)=>{
|
|
7853
|
-
utils_reportToCompilation(compilation, compiler, maybeError, 'error');
|
|
7854
|
-
});
|
|
7855
|
-
}
|
|
7856
|
-
if (isGecko) {
|
|
7857
|
-
const bgScripts = manifestBg?.scripts;
|
|
7858
|
-
if (bgScripts && bgScripts.length > 0) {
|
|
7859
|
-
const bgScriptPath = __rspack_external_path.join(dirname, bgScripts[0]);
|
|
7860
|
-
const maybeError = this.getMissingBackgroundError(bgScriptPath);
|
|
7861
|
-
if (maybeError) hookError(maybeError);
|
|
7862
|
-
} else this.addDefaultEntry(compiler, "background/script", minimumBgScript);
|
|
7863
|
-
return;
|
|
7864
|
-
}
|
|
7865
|
-
if (2 === manifestVersion) {
|
|
7866
|
-
const bgScripts = manifestBg?.scripts;
|
|
7867
|
-
if (bgScripts && bgScripts.length > 0) {
|
|
7868
|
-
const bgScriptPath = __rspack_external_path.join(dirname, bgScripts[0]);
|
|
7869
|
-
const maybeError = this.getMissingBackgroundError(bgScriptPath);
|
|
7870
|
-
if (maybeError) hookError(maybeError);
|
|
7871
|
-
} else this.addDefaultEntry(compiler, "background/script", minimumBgScript);
|
|
7872
|
-
} else {
|
|
7873
|
-
const serviceWorker = manifestBg?.service_worker;
|
|
7874
|
-
if (serviceWorker) {
|
|
7875
|
-
const swPath = __rspack_external_path.join(dirname, serviceWorker);
|
|
7876
|
-
const maybeError = this.getMissingBackgroundError(swPath);
|
|
7877
|
-
if (maybeError) hookError(maybeError);
|
|
7878
|
-
const existingEntry = compiler.options.entry && 'background/service_worker' in compiler.options.entry ? compiler.options.entry['background/service_worker'] : void 0;
|
|
7879
|
-
if (!existingEntry && __rspack_external_fs.existsSync(swPath)) this.addDefaultEntry(compiler, 'background/service_worker', swPath);
|
|
7880
|
-
} else this.addDefaultEntry(compiler, 'background/service_worker', minimumBgScript);
|
|
7881
|
-
}
|
|
7882
|
-
}
|
|
7883
|
-
}
|
|
7884
|
-
class SetupReloadStrategy {
|
|
7885
|
-
manifestPath;
|
|
7886
|
-
browser;
|
|
7887
|
-
constructor(options){
|
|
7888
|
-
this.manifestPath = options.manifestPath;
|
|
7889
|
-
this.browser = options.browser || 'chrome';
|
|
7890
|
-
}
|
|
7891
|
-
getEntryName(manifest) {
|
|
7892
|
-
if (manifest.background) {
|
|
7893
|
-
if (constants_isGeckoBasedBrowser(String(this.browser))) return {
|
|
7894
|
-
pageEntry: "background/script",
|
|
7895
|
-
tryCatchWrapper: true,
|
|
7896
|
-
eagerChunkLoading: false
|
|
7897
|
-
};
|
|
7898
|
-
if (3 === manifest.manifest_version) return {
|
|
7899
|
-
serviceWorkerEntry: 'background/service_worker',
|
|
7900
|
-
tryCatchWrapper: true,
|
|
7901
|
-
eagerChunkLoading: false
|
|
7902
|
-
};
|
|
7903
|
-
if (2 === manifest.manifest_version) return {
|
|
7904
|
-
pageEntry: "background/script",
|
|
7905
|
-
tryCatchWrapper: true,
|
|
7906
|
-
eagerChunkLoading: false
|
|
7907
|
-
};
|
|
7908
|
-
}
|
|
7909
|
-
return {
|
|
7910
|
-
pageEntry: 'background',
|
|
7911
|
-
tryCatchWrapper: true,
|
|
7912
|
-
eagerChunkLoading: false
|
|
7913
|
-
};
|
|
7914
|
-
}
|
|
7915
|
-
apply(compiler) {
|
|
7916
|
-
const manifest = JSON.parse(stripBom(__rspack_external_fs.readFileSync(this.manifestPath, 'utf-8')));
|
|
7917
|
-
const patchedManifest = manifest_filterKeysForThisBrowser(manifest, this.browser);
|
|
7918
|
-
const contentScriptsMeta = {};
|
|
7919
|
-
try {
|
|
7920
|
-
const csList = Array.isArray(patchedManifest.content_scripts) ? patchedManifest.content_scripts : [];
|
|
7921
|
-
const originalCount = csList.length;
|
|
7922
|
-
let bridgeOrdinal = 0;
|
|
7923
|
-
for(let i = 0; i < csList.length; i++){
|
|
7924
|
-
const cs = csList[i];
|
|
7925
|
-
const bundleId = getCanonicalContentScriptJsAssetName(i);
|
|
7926
|
-
const isMain = cs?.world === 'MAIN';
|
|
7927
|
-
if (isMain) {
|
|
7928
|
-
const bridgeIndex = originalCount + bridgeOrdinal++;
|
|
7929
|
-
const bridgeBundleId = getCanonicalContentScriptJsAssetName(bridgeIndex);
|
|
7930
|
-
contentScriptsMeta[bundleId] = {
|
|
7931
|
-
index: i,
|
|
7932
|
-
bundleId,
|
|
7933
|
-
world: 'main',
|
|
7934
|
-
bridgeBundleId
|
|
7935
|
-
};
|
|
7936
|
-
contentScriptsMeta[bridgeBundleId] = {
|
|
7937
|
-
index: bridgeIndex,
|
|
7938
|
-
bundleId: bridgeBundleId,
|
|
7939
|
-
world: 'extension',
|
|
7940
|
-
role: 'main_world_bridge',
|
|
7941
|
-
mainBundleId: bundleId
|
|
7942
|
-
};
|
|
7943
|
-
} else contentScriptsMeta[bundleId] = {
|
|
7944
|
-
index: i,
|
|
7945
|
-
bundleId,
|
|
7946
|
-
world: 'extension'
|
|
7947
|
-
};
|
|
7948
|
-
}
|
|
7949
|
-
} catch {}
|
|
7950
|
-
new SetupBackgroundEntry({
|
|
7951
|
-
manifestPath: this.manifestPath,
|
|
7952
|
-
browser: this.browser
|
|
7953
|
-
}).apply(compiler);
|
|
7954
|
-
new webpack_target_webextension_fork({
|
|
7955
|
-
background: this.getEntryName(patchedManifest),
|
|
7956
|
-
hmrConfig: false,
|
|
7957
|
-
weakRuntimeCheck: true,
|
|
7958
|
-
contentScriptsMeta
|
|
7959
|
-
}).apply(compiler);
|
|
7960
|
-
}
|
|
7961
|
-
}
|
|
7962
|
-
const SCRIPTS_REPLAY_SHIM_SOURCE = `;(function () {
|
|
7963
|
-
try {
|
|
7964
|
-
if (typeof globalThis !== "object" || !globalThis) return;
|
|
7965
|
-
var chromeRef =
|
|
7966
|
-
(globalThis.chrome && globalThis.chrome.scripting && typeof globalThis.chrome.scripting.executeScript === "function")
|
|
7967
|
-
? globalThis.chrome
|
|
7968
|
-
: (globalThis.browser && globalThis.browser.scripting && typeof globalThis.browser.scripting.executeScript === "function")
|
|
7969
|
-
? globalThis.browser
|
|
7970
|
-
: null;
|
|
7971
|
-
if (!chromeRef) return;
|
|
7972
|
-
if (globalThis.__extjsScriptsReplayInstalled) return;
|
|
7973
|
-
globalThis.__extjsScriptsReplayInstalled = true;
|
|
7974
|
-
|
|
7975
|
-
var registry = new Map();
|
|
7976
|
-
var originalExecuteScript = chromeRef.scripting.executeScript.bind(chromeRef.scripting);
|
|
7977
|
-
|
|
7978
|
-
var serialize = function (entry) {
|
|
7979
|
-
try {
|
|
7980
|
-
return JSON.stringify({
|
|
7981
|
-
files: entry && Array.isArray(entry.files) ? entry.files : [],
|
|
7982
|
-
world: entry && entry.world ? String(entry.world) : ""
|
|
7983
|
-
});
|
|
7984
|
-
} catch (error) {
|
|
7985
|
-
return "";
|
|
7986
|
-
}
|
|
7987
|
-
};
|
|
7988
|
-
|
|
7989
|
-
var track = function (injection) {
|
|
7990
|
-
try {
|
|
7991
|
-
var tabId = injection && injection.target && injection.target.tabId;
|
|
7992
|
-
var files =
|
|
7993
|
-
injection && Array.isArray(injection.files) ? injection.files.slice() : null;
|
|
7994
|
-
if (typeof tabId !== "number") return;
|
|
7995
|
-
if (!files || !files.length) return;
|
|
7996
|
-
var world = injection.world ? String(injection.world) : undefined;
|
|
7997
|
-
var entry = { files: files, world: world, sig: serialize({ files: files, world: world }) };
|
|
7998
|
-
var existing = registry.get(tabId) || [];
|
|
7999
|
-
// Dedupe by signature — repeated identical injections (e.g. user
|
|
8000
|
-
// clicks the action twice) shouldn't stack in the replay list.
|
|
8001
|
-
if (existing.some(function (e) { return e.sig === entry.sig; })) return;
|
|
8002
|
-
existing.push(entry);
|
|
8003
|
-
// Cap to the most recent 50 distinct injections per tab so a misbehaving
|
|
8004
|
-
// user loop can't grow the registry unbounded.
|
|
8005
|
-
registry.set(tabId, existing.slice(-50));
|
|
8006
|
-
} catch (error) {
|
|
8007
|
-
// Tracking is best-effort; never break the user's executeScript call.
|
|
8008
|
-
}
|
|
8009
|
-
};
|
|
8010
|
-
|
|
8011
|
-
chromeRef.scripting.executeScript = function (injection, callback) {
|
|
8012
|
-
track(injection);
|
|
8013
|
-
return originalExecuteScript(injection, callback);
|
|
8014
|
-
};
|
|
8015
|
-
|
|
8016
|
-
var normalizeFile = function (value) {
|
|
8017
|
-
return String(value || "").replace(/^[/\\\\]+/, "");
|
|
8018
|
-
};
|
|
8019
|
-
|
|
8020
|
-
var fileMatches = function (entryFile, changedNormalized) {
|
|
8021
|
-
var fn = normalizeFile(entryFile);
|
|
8022
|
-
for (var i = 0; i < changedNormalized.length; i++) {
|
|
8023
|
-
var c = changedNormalized[i];
|
|
8024
|
-
if (!c) continue;
|
|
8025
|
-
if (fn === c) return true;
|
|
8026
|
-
if (fn.length > c.length && fn.slice(fn.length - c.length - 1) === "/" + c) return true;
|
|
8027
|
-
if (c.length > fn.length && c.slice(c.length - fn.length - 1) === "/" + fn) return true;
|
|
8028
|
-
}
|
|
8029
|
-
return false;
|
|
8030
|
-
};
|
|
8031
|
-
|
|
8032
|
-
globalThis.__extjsScriptsReplay = function (changedFiles) {
|
|
8033
|
-
var changedNormalized = (Array.isArray(changedFiles) ? changedFiles : []).map(normalizeFile);
|
|
8034
|
-
var promises = [];
|
|
8035
|
-
registry.forEach(function (entries, tabId) {
|
|
8036
|
-
entries.forEach(function (entry) {
|
|
8037
|
-
var matches = false;
|
|
8038
|
-
for (var i = 0; i < entry.files.length; i++) {
|
|
8039
|
-
if (fileMatches(entry.files[i], changedNormalized)) {
|
|
8040
|
-
matches = true;
|
|
8041
|
-
break;
|
|
8042
|
-
}
|
|
8043
|
-
}
|
|
8044
|
-
if (!matches) return;
|
|
8045
|
-
try {
|
|
8046
|
-
promises.push(
|
|
8047
|
-
originalExecuteScript({
|
|
8048
|
-
target: { tabId: tabId },
|
|
8049
|
-
files: entry.files,
|
|
8050
|
-
world: entry.world
|
|
8051
|
-
}).then(
|
|
8052
|
-
function () { return { ok: true, tabId: tabId, files: entry.files }; },
|
|
8053
|
-
function (error) {
|
|
8054
|
-
return {
|
|
8055
|
-
ok: false,
|
|
8056
|
-
tabId: tabId,
|
|
8057
|
-
files: entry.files,
|
|
8058
|
-
error: String((error && error.message) || error)
|
|
8059
|
-
};
|
|
8060
|
-
}
|
|
8061
|
-
)
|
|
8062
|
-
);
|
|
8063
|
-
} catch (error) {
|
|
8064
|
-
// Tab may have closed; skip silently.
|
|
8065
|
-
}
|
|
8066
|
-
});
|
|
8067
|
-
});
|
|
8068
|
-
return Promise.all(promises);
|
|
8069
|
-
};
|
|
8070
|
-
} catch (error) {
|
|
8071
|
-
// Best-effort shim; do not break the SW bootstrap on any failure.
|
|
8072
|
-
}
|
|
8073
|
-
})();
|
|
8074
|
-
`;
|
|
8075
|
-
const BACKGROUND_ASSET = /(^|\/)background\/(?:service_worker|script)\.js$/i;
|
|
8076
|
-
class InjectScriptsReplayShim {
|
|
8077
|
-
apply(compiler) {
|
|
8078
|
-
compiler.hooks.thisCompilation.tap(InjectScriptsReplayShim.name, (compilation)=>{
|
|
8079
|
-
compilation.hooks.processAssets.tap({
|
|
8080
|
-
name: InjectScriptsReplayShim.name,
|
|
8081
|
-
stage: core_Compilation.PROCESS_ASSETS_STAGE_REPORT + 100
|
|
8082
|
-
}, ()=>{
|
|
8083
|
-
for (const asset of compilation.getAssets()){
|
|
8084
|
-
if (!BACKGROUND_ASSET.test(asset.name)) continue;
|
|
8085
|
-
const original = asset.source.source().toString();
|
|
8086
|
-
if (-1 !== original.indexOf('__extjsScriptsReplayInstalled')) continue;
|
|
8087
|
-
const next = SCRIPTS_REPLAY_SHIM_SOURCE + '\n' + original;
|
|
8088
|
-
compilation.updateAsset(asset.name, new core_sources.RawSource(next));
|
|
8089
|
-
}
|
|
8090
|
-
});
|
|
8091
|
-
});
|
|
8092
|
-
}
|
|
8093
|
-
}
|
|
8094
|
-
const BRIDGE_PRODUCER_SOURCE = `;(function () {
|
|
8095
|
-
try {
|
|
8096
|
-
var g = (typeof globalThis === "object" && globalThis) ? globalThis : this;
|
|
8097
|
-
if (!g || g.__extjsBridgeProducerInstalled) return;
|
|
8098
|
-
|
|
8099
|
-
var PORT = parseInt("__EXTJS_CONTROL_PORT__", 10);
|
|
8100
|
-
var INSTANCE_ID = "__EXTJS_INSTANCE_ID__";
|
|
8101
|
-
var CONTEXT = "__EXTJS_CONTEXT__";
|
|
8102
|
-
// Connectable host of the dev-server control WS. Baked from the resolved
|
|
8103
|
-
// connectable host (loopback locally; the public host for remote/devcontainer).
|
|
8104
|
-
var HOST = "__EXTJS_CONTROL_HOST__";
|
|
8105
|
-
if (!HOST || HOST.indexOf("__EXTJS") === 0) HOST = "127.0.0.1";
|
|
8106
|
-
if (!PORT || PORT < 1) return;
|
|
8107
|
-
|
|
8108
|
-
var WS = g.WebSocket;
|
|
8109
|
-
if (typeof WS !== "function") return;
|
|
8110
|
-
|
|
8111
|
-
var consoleRef = g.console || {};
|
|
8112
|
-
g.__extjsBridgeProducerInstalled = true;
|
|
8113
|
-
|
|
8114
|
-
// Capture extension event listeners at install time. The producer is
|
|
8115
|
-
// prepended to the background bundle, so these wraps run BEFORE user code
|
|
8116
|
-
// registers its listeners — letting the bridge replay them on demand. The
|
|
8117
|
-
// platform exposes no API to dispatch these events, and CDP attaches too
|
|
8118
|
-
// late to wrap addListener, so this is the only path. Replay invokes the
|
|
8119
|
-
// handler WITHOUT a user gesture, so the gesture-derived activeTab grant
|
|
8120
|
-
// does NOT apply (callers are told gesture:false). This is engine-agnostic:
|
|
8121
|
-
// it works on Chromium and Gecko because it only touches addListener.
|
|
8122
|
-
//
|
|
8123
|
-
// captureEvent transparently wraps addListener/removeListener (delegating to
|
|
8124
|
-
// the originals) and records callbacks into the sink array.
|
|
8125
|
-
function captureEvent(event, sink) {
|
|
8126
|
-
try {
|
|
8127
|
-
if (!event || typeof event.addListener !== "function") return;
|
|
8128
|
-
var origAdd = event.addListener.bind(event);
|
|
8129
|
-
event.addListener = function (cb) {
|
|
8130
|
-
if (typeof cb === "function" && sink.indexOf(cb) === -1) sink.push(cb);
|
|
8131
|
-
return origAdd(cb);
|
|
8132
|
-
};
|
|
8133
|
-
if (typeof event.removeListener === "function") {
|
|
8134
|
-
var origRemove = event.removeListener.bind(event);
|
|
8135
|
-
event.removeListener = function (cb) {
|
|
8136
|
-
var i = sink.indexOf(cb);
|
|
8137
|
-
if (i !== -1) sink.splice(i, 1);
|
|
8138
|
-
return origRemove(cb);
|
|
8139
|
-
};
|
|
8140
|
-
}
|
|
8141
|
-
} catch (e) { /* non-fatal: trigger falls back to its no-listener reply */ }
|
|
8142
|
-
}
|
|
8143
|
-
|
|
8144
|
-
// Use g.chrome (not the hoisted chrome var below) — this runs first.
|
|
8145
|
-
var actionClickedListeners = [];
|
|
8146
|
-
var commandListeners = [];
|
|
8147
|
-
if (g.chrome) {
|
|
8148
|
-
captureEvent(g.chrome.action && g.chrome.action.onClicked, actionClickedListeners);
|
|
8149
|
-
captureEvent(g.chrome.commands && g.chrome.commands.onCommand, commandListeners);
|
|
8150
|
-
}
|
|
8151
|
-
|
|
8152
|
-
var LEVELS = ["log", "info", "warn", "error", "debug", "trace"];
|
|
8153
|
-
var socket = null;
|
|
8154
|
-
var open = false;
|
|
8155
|
-
var queue = [];
|
|
8156
|
-
var backoff = 250;
|
|
8157
|
-
var MAX_BACKOFF = 5000;
|
|
8158
|
-
var MAX_QUEUE = 1000;
|
|
8159
|
-
var MAX_RESULT_BYTES = 256 * 1024;
|
|
8160
|
-
|
|
8161
|
-
function nowId() {
|
|
8162
|
-
return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
|
|
8163
|
-
}
|
|
8164
|
-
|
|
8165
|
-
function engineName() {
|
|
8166
|
-
try {
|
|
8167
|
-
return (typeof navigator !== "undefined" && /firefox/i.test(navigator.userAgent)) ? "firefox" : "chromium";
|
|
8168
|
-
} catch (e) { return "chromium"; }
|
|
8169
|
-
}
|
|
8170
|
-
|
|
8171
|
-
// JSON-safe, byte-capped clone of a result value.
|
|
8172
|
-
function safeValue(v) {
|
|
8173
|
-
try {
|
|
8174
|
-
var s = JSON.stringify(v);
|
|
8175
|
-
if (s === undefined) return {value: undefined, truncated: false};
|
|
8176
|
-
if (s.length > MAX_RESULT_BYTES) {
|
|
8177
|
-
return {value: {__type: "truncated", preview: s.slice(0, 1024)}, truncated: true};
|
|
8178
|
-
}
|
|
8179
|
-
return {value: JSON.parse(s), truncated: false};
|
|
8180
|
-
} catch (e) {
|
|
8181
|
-
return {value: {__type: "unserializable", preview: String(v).slice(0, 512)}, truncated: false};
|
|
8182
|
-
}
|
|
8183
|
-
}
|
|
8184
|
-
|
|
8185
|
-
function replyOk(cmdId, value) {
|
|
8186
|
-
var s = safeValue(value);
|
|
8187
|
-
var frame = {type: "result", cmdId: cmdId, ok: true, value: s.value};
|
|
8188
|
-
if (s.truncated) frame.truncated = true;
|
|
8189
|
-
try { socket && socket.send(JSON.stringify(frame)); } catch (e) {}
|
|
8190
|
-
}
|
|
8191
|
-
|
|
8192
|
-
function replyErr(cmdId, name, message) {
|
|
8193
|
-
var frame = {type: "result", cmdId: cmdId, ok: false, error: {name: name, message: String(message), engine: engineName()}};
|
|
8194
|
-
try { socket && socket.send(JSON.stringify(frame)); } catch (e) {}
|
|
8195
|
-
}
|
|
8196
|
-
|
|
8197
|
-
// Execute one authorized command in the SW (or route to a tab). chrome.*
|
|
8198
|
-
// promise APIs are used; callback-only APIs are wrapped.
|
|
8199
|
-
function executeCommand(cmd) {
|
|
8200
|
-
var op = cmd.op, target = cmd.target || {}, args = cmd.args || {};
|
|
8201
|
-
var ctx = target.context || "background";
|
|
8202
|
-
var chrome = g.chrome;
|
|
8203
|
-
var cmdId = cmd.cmdId;
|
|
8204
|
-
try {
|
|
8205
|
-
if (!chrome) { replyErr(cmdId, "Unsupported", "chrome.* not available in this context"); return; }
|
|
8206
|
-
if (op === "eval") {
|
|
8207
|
-
if (ctx === "background") {
|
|
8208
|
-
Promise.resolve().then(function () { return (0, eval)(args.expression); })
|
|
8209
|
-
.then(function (r) { replyOk(cmdId, r); }, function (e) {
|
|
8210
|
-
var msg = (e && e.message) || String(e);
|
|
8211
|
-
// MV3 forbids eval of strings in the SW/extension pages; Chrome
|
|
8212
|
-
// rejects 'unsafe-eval' in MV3 extension_pages, so this can't be
|
|
8213
|
-
// relaxed. Surface it honestly with a usable alternative.
|
|
8214
|
-
if (/Content Security Policy|unsafe-eval/i.test(msg)) {
|
|
8215
|
-
replyErr(cmdId, "Unsupported", "eval is blocked in the MV3 service worker by CSP. Use --context page --tab <id> (eval runs in the page's MAIN world), or run on an MV2/Firefox build. Engine: " + engineName());
|
|
8216
|
-
} else {
|
|
8217
|
-
replyErr(cmdId, (e && e.name) || "EvalError", msg);
|
|
8218
|
-
}
|
|
8219
|
-
});
|
|
8220
|
-
} else if ((ctx === "content" || ctx === "page") && target.tabId && chrome.scripting) {
|
|
8221
|
-
chrome.scripting.executeScript({
|
|
8222
|
-
target: {tabId: target.tabId},
|
|
8223
|
-
world: ctx === "page" ? "MAIN" : "ISOLATED",
|
|
8224
|
-
func: function (src) { return eval(src); },
|
|
8225
|
-
args: [String(args.expression)]
|
|
8226
|
-
}).then(function (res) { replyOk(cmdId, res && res[0] ? res[0].result : undefined); },
|
|
8227
|
-
function (e) { replyErr(cmdId, "EvalError", e); });
|
|
8228
|
-
} else {
|
|
8229
|
-
replyErr(cmdId, "Unsupported", "eval in context " + ctx + " requires a tabId");
|
|
8230
|
-
}
|
|
8231
|
-
return;
|
|
8232
|
-
}
|
|
8233
|
-
if (op === "storage.get") {
|
|
8234
|
-
chrome.storage[args.area || "local"].get(args.key != null ? args.key : null)
|
|
8235
|
-
.then(function (r) { replyOk(cmdId, r); }, function (e) { replyErr(cmdId, "StorageError", e); });
|
|
8236
|
-
return;
|
|
8237
|
-
}
|
|
8238
|
-
if (op === "storage.set") {
|
|
8239
|
-
chrome.storage[args.area || "local"].set(args.items || {})
|
|
8240
|
-
.then(function () { replyOk(cmdId, {set: Object.keys(args.items || {})}); }, function (e) { replyErr(cmdId, "StorageError", e); });
|
|
8241
|
-
return;
|
|
8242
|
-
}
|
|
8243
|
-
if (op === "reload") {
|
|
8244
|
-
if (ctx === "background") {
|
|
8245
|
-
replyOk(cmdId, {reloading: true});
|
|
8246
|
-
setTimeout(function () { try { chrome.runtime.reload(); } catch (e) {} }, 50);
|
|
8247
|
-
} else if (target.tabId) {
|
|
8248
|
-
chrome.tabs.reload(target.tabId).then(function () { replyOk(cmdId, {reloaded: target.tabId}); }, function (e) { replyErr(cmdId, "ReloadError", e); });
|
|
8249
|
-
} else {
|
|
8250
|
-
replyErr(cmdId, "Unsupported", "reload needs background or a tabId");
|
|
8251
|
-
}
|
|
8252
|
-
return;
|
|
8253
|
-
}
|
|
8254
|
-
if (op === "open") {
|
|
8255
|
-
var surface = args.surface || ctx;
|
|
8256
|
-
// getPopup is promise-style on Gecko and (MV3) Chromium; fall back to
|
|
8257
|
-
// callback-style for older Chromium. Always resolves to a string.
|
|
8258
|
-
var getActionPopup = function (cb) {
|
|
8259
|
-
try {
|
|
8260
|
-
var r = chrome.action && chrome.action.getPopup && chrome.action.getPopup({});
|
|
8261
|
-
if (r && typeof r.then === "function") {
|
|
8262
|
-
r.then(function (p) { cb(p || ""); }, function () { cb(""); });
|
|
8263
|
-
return;
|
|
8264
|
-
}
|
|
8265
|
-
} catch (e) {}
|
|
8266
|
-
try { chrome.action.getPopup({}, function (p) { cb(p || ""); }); }
|
|
8267
|
-
catch (e) { cb(""); }
|
|
8268
|
-
};
|
|
8269
|
-
// Resolve the tab a replayed event should carry: an explicit args.tabId,
|
|
8270
|
-
// else the active tab of the focused window.
|
|
8271
|
-
var resolveActiveTab = function (a, cb) {
|
|
8272
|
-
if (a && typeof a.tabId === "number") {
|
|
8273
|
-
try { chrome.tabs.get(a.tabId, function (t) { cb(t || {id: a.tabId}); }); return; }
|
|
8274
|
-
catch (e) {}
|
|
8275
|
-
}
|
|
8276
|
-
try { chrome.tabs.query({active: true, lastFocusedWindow: true}, function (tabs) { cb((tabs && tabs[0]) || undefined); }); }
|
|
8277
|
-
catch (e) { cb(undefined); }
|
|
8278
|
-
};
|
|
8279
|
-
// Replaying a listener carries no user gesture, so activeTab is never
|
|
8280
|
-
// granted. Warn when the manifest declares it (handler will diverge
|
|
8281
|
-
// from a real click).
|
|
8282
|
-
var activeTabWarning = function () {
|
|
8283
|
-
try {
|
|
8284
|
-
var m = chrome.runtime.getManifest();
|
|
8285
|
-
var perms = (m && m.permissions) || [];
|
|
8286
|
-
if (perms.indexOf("activeTab") !== -1) {
|
|
8287
|
-
return "replayed without a user gesture: activeTab is NOT granted, so APIs that depend on it (scripting on the active tab, captureVisibleTab) behave differently than a real click";
|
|
8288
|
-
}
|
|
8289
|
-
} catch (e) {}
|
|
8290
|
-
return null;
|
|
8291
|
-
};
|
|
8292
|
-
if (surface === "popup") {
|
|
8293
|
-
if (chrome.action && chrome.action.openPopup) {
|
|
8294
|
-
chrome.action.openPopup().then(function () { replyOk(cmdId, {opened: "popup"}); }, function (e) { replyErr(cmdId, "Unsupported", "openPopup: " + e); });
|
|
8295
|
-
} else { replyErr(cmdId, "Unsupported", "action.openPopup not available"); }
|
|
8296
|
-
} else if (surface === "options") {
|
|
8297
|
-
try { chrome.runtime.openOptionsPage(function () { replyOk(cmdId, {opened: "options"}); }); }
|
|
8298
|
-
catch (e) { replyErr(cmdId, "Unsupported", "openOptionsPage: " + e); }
|
|
8299
|
-
} else if (surface === "sidebar") {
|
|
8300
|
-
if (chrome.sidePanel && chrome.sidePanel.open && chrome.windows) {
|
|
8301
|
-
chrome.windows.getCurrent(function (w) {
|
|
8302
|
-
chrome.sidePanel.open({windowId: w.id}).then(function () { replyOk(cmdId, {opened: "sidebar"}); }, function (e) { replyErr(cmdId, "Unsupported", "sidePanel.open: " + e); });
|
|
8303
|
-
});
|
|
8304
|
-
} else { replyErr(cmdId, "Unsupported", "sidePanel not available (engine: " + engineName() + ")"); }
|
|
8305
|
-
} else if (surface === "action") {
|
|
8306
|
-
// Trigger the toolbar action. With a default_popup, clicking the icon
|
|
8307
|
-
// opens it (reuse openPopup). Without a popup, clicking fires
|
|
8308
|
-
// chrome.action.onClicked — we replay the listeners captured at install.
|
|
8309
|
-
if (chrome.action) {
|
|
8310
|
-
getActionPopup(function (popup) {
|
|
8311
|
-
if (popup) {
|
|
8312
|
-
try {
|
|
8313
|
-
chrome.action.openPopup().then(function () { replyOk(cmdId, {triggered: "popup"}); }, function (e) { replyErr(cmdId, "Unsupported", "openPopup: " + e); });
|
|
8314
|
-
} catch (e) { replyErr(cmdId, "Unsupported", "openPopup: " + e); }
|
|
8315
|
-
} else if (actionClickedListeners.length) {
|
|
8316
|
-
resolveActiveTab(args, function (tab) {
|
|
8317
|
-
var fired = 0;
|
|
8318
|
-
for (var i = 0; i < actionClickedListeners.length; i++) {
|
|
8319
|
-
try { actionClickedListeners[i](tab); fired++; } catch (e) {}
|
|
8320
|
-
}
|
|
8321
|
-
var reply = {triggered: "onClicked", listeners: fired, gesture: false};
|
|
8322
|
-
var warning = activeTabWarning();
|
|
8323
|
-
if (warning) reply.warning = warning;
|
|
8324
|
-
replyOk(cmdId, reply);
|
|
8325
|
-
});
|
|
8326
|
-
} else {
|
|
8327
|
-
replyErr(cmdId, "Unsupported", "action has no popup and no onClicked listener registered");
|
|
8328
|
-
}
|
|
8329
|
-
});
|
|
8330
|
-
} else { replyErr(cmdId, "Unsupported", "chrome.action not available (engine: " + engineName() + ")"); }
|
|
8331
|
-
} else if (surface === "command") {
|
|
8332
|
-
// Replay a captured chrome.commands.onCommand listener (keyboard
|
|
8333
|
-
// shortcut). Same no-gesture caveat as onClicked.
|
|
8334
|
-
var commandName = (args && args.name) || undefined;
|
|
8335
|
-
if (!commandListeners.length) {
|
|
8336
|
-
replyErr(cmdId, "Unsupported", "no chrome.commands.onCommand listener registered");
|
|
8337
|
-
} else {
|
|
8338
|
-
resolveActiveTab(args, function (tab) {
|
|
8339
|
-
var fired = 0;
|
|
8340
|
-
for (var i = 0; i < commandListeners.length; i++) {
|
|
8341
|
-
try { commandListeners[i](commandName, tab); fired++; } catch (e) {}
|
|
8342
|
-
}
|
|
8343
|
-
replyOk(cmdId, {triggered: "command", command: commandName || null, listeners: fired, gesture: false});
|
|
8344
|
-
});
|
|
8345
|
-
}
|
|
8346
|
-
} else { replyErr(cmdId, "BadRequest", "unknown surface: " + surface); }
|
|
8347
|
-
return;
|
|
8348
|
-
}
|
|
8349
|
-
if (op === "tabs.query") {
|
|
8350
|
-
chrome.tabs.query(args || {}).then(function (tabs) {
|
|
8351
|
-
replyOk(cmdId, (tabs || []).map(function (t) { return {id: t.id, url: t.url, title: t.title, active: t.active, windowId: t.windowId}; }));
|
|
8352
|
-
}, function (e) { replyErr(cmdId, "TabsError", e); });
|
|
8353
|
-
return;
|
|
8354
|
-
}
|
|
8355
|
-
if (op === "inspect") {
|
|
8356
|
-
// Slice 3 sidecar/default path: extract a DOM snapshot from the target
|
|
8357
|
-
// page via chrome.scripting (CDP-free). Closed shadow roots need the
|
|
8358
|
-
// --deep-dom CDP escape hatch (separate tool); here we read open ones.
|
|
8359
|
-
if ((ctx === "content" || ctx === "page") && target.tabId && chrome.scripting) {
|
|
8360
|
-
var maxBytes = (args && args.maxBytes) || 262144;
|
|
8361
|
-
var includeHtml = !args || !args.include || args.include.indexOf("html") !== -1;
|
|
8362
|
-
chrome.scripting.executeScript({
|
|
8363
|
-
target: {tabId: target.tabId},
|
|
8364
|
-
world: ctx === "page" ? "MAIN" : "ISOLATED",
|
|
8365
|
-
func: function (wantHtml, cap) {
|
|
8366
|
-
function countShadow(root) {
|
|
8367
|
-
var n = 0, els = root.querySelectorAll("*");
|
|
8368
|
-
for (var i = 0; i < els.length; i++) { if (els[i].shadowRoot) { n++; n += countShadow(els[i].shadowRoot); } }
|
|
8369
|
-
return n;
|
|
8370
|
-
}
|
|
8371
|
-
var doc = document;
|
|
8372
|
-
var roots = doc.querySelectorAll('#extension-root,[data-extension-root]');
|
|
8373
|
-
var out = {
|
|
8374
|
-
url: location.href,
|
|
8375
|
-
title: doc.title,
|
|
8376
|
-
summary: {
|
|
8377
|
-
htmlLength: doc.documentElement.outerHTML.length,
|
|
8378
|
-
scriptCount: doc.querySelectorAll("script").length,
|
|
8379
|
-
styleCount: doc.querySelectorAll("style,link[rel=stylesheet]").length,
|
|
8380
|
-
extensionRootCount: roots.length,
|
|
8381
|
-
openShadowRoots: countShadow(doc),
|
|
8382
|
-
bodyChildCount: doc.body ? doc.body.children.length : 0
|
|
8383
|
-
}
|
|
8384
|
-
};
|
|
8385
|
-
if (wantHtml) {
|
|
8386
|
-
var html = doc.documentElement.outerHTML;
|
|
8387
|
-
if (cap > 0 && html.length > cap) { out.html = html.slice(0, cap); out.htmlTruncated = true; }
|
|
8388
|
-
else { out.html = html; }
|
|
8389
|
-
}
|
|
8390
|
-
return out;
|
|
8391
|
-
},
|
|
8392
|
-
args: [includeHtml, maxBytes]
|
|
8393
|
-
}).then(function (res) { replyOk(cmdId, res && res[0] ? res[0].result : undefined); },
|
|
8394
|
-
function (e) { replyErr(cmdId, "InspectError", e); });
|
|
8395
|
-
} else if (ctx === "popup" || ctx === "options" || ctx === "sidebar" || ctx === "devtools") {
|
|
8396
|
-
// The SW can't read a surface page's DOM; ask the surface's own
|
|
8397
|
-
// in-bundle relay (only the open, matching-context page responds).
|
|
8398
|
-
chrome.runtime.sendMessage(
|
|
8399
|
-
{__extjsInspectRequest: true, target: target, args: args},
|
|
8400
|
-
function (resp) {
|
|
8401
|
-
if (chrome.runtime.lastError || !resp) {
|
|
8402
|
-
replyErr(cmdId, "Unsupported", "surface '" + ctx + "' is not open (open it first: extension open " + ctx + ")");
|
|
8403
|
-
} else if (resp.ok) {
|
|
8404
|
-
replyOk(cmdId, resp.value);
|
|
8405
|
-
} else {
|
|
8406
|
-
replyErr(cmdId, (resp.error && resp.error.name) || "InspectError", (resp.error && resp.error.message) || "inspect failed");
|
|
8407
|
-
}
|
|
8408
|
-
}
|
|
8409
|
-
);
|
|
8410
|
-
} else if (ctx === "background") {
|
|
8411
|
-
replyErr(cmdId, "Unsupported", "the service worker has no DOM; inspect a content/page (with --tab) or an open surface");
|
|
8412
|
-
} else {
|
|
8413
|
-
replyErr(cmdId, "Unsupported", "inspect of " + ctx + " requires a tabId (content/page) or an open surface");
|
|
8414
|
-
}
|
|
8415
|
-
return;
|
|
8416
|
-
}
|
|
8417
|
-
replyErr(cmdId, "BadRequest", "unknown op: " + op);
|
|
8418
|
-
} catch (e) {
|
|
8419
|
-
replyErr(cmdId, "ExecutorError", e);
|
|
8420
|
-
}
|
|
8421
|
-
}
|
|
8422
|
-
|
|
8423
|
-
function noopLastError() { try { void g.chrome.runtime.lastError; } catch (e) {} }
|
|
8424
|
-
|
|
8425
|
-
// Only http(s)/file/ftp tabs can run a content script; skip chrome://, the
|
|
8426
|
-
// extension's own pages, about:blank, etc.
|
|
8427
|
-
function isInjectableUrl(url) {
|
|
8428
|
-
return typeof url === "string" && /^(https?|file|ftp):/i.test(url);
|
|
8429
|
-
}
|
|
8430
|
-
|
|
8431
|
-
// Re-inject a single declared content-script entry's fresh files into every
|
|
8432
|
-
// open tab it matches, in place. The wrapper's reinject runtime tears down
|
|
8433
|
-
// the previous mount (matched by data-extjs-reinject-owner + build hash) and
|
|
8434
|
-
// mounts the new one — so this is the controller-less equivalent of the CDP
|
|
8435
|
-
// controller's reinjection, just driven from inside the extension.
|
|
8436
|
-
//
|
|
8437
|
-
// exclude_matches MUST be honored: the browser's own static injection never
|
|
8438
|
-
// touches excluded pages, and extensions can rely on that (e.g. a script
|
|
8439
|
-
// whose message handler opens the very page it excludes — injecting there
|
|
8440
|
-
// anyway creates an open-a-tab → inject → open-a-tab runaway loop). Chrome's
|
|
8441
|
-
// tabs.query has no exclude support, so query the exclude patterns
|
|
8442
|
-
// separately and subtract — the browser stays the single pattern matcher.
|
|
8443
|
-
function reinjectContentScriptEntry(entry) {
|
|
8444
|
-
var chrome = g.chrome;
|
|
8445
|
-
var matches = (entry && entry.matches) || [];
|
|
8446
|
-
if (!Array.isArray(matches) || !matches.length) return;
|
|
8447
|
-
var excludeMatches = (entry && entry.exclude_matches) || [];
|
|
8448
|
-
var jsFiles = ((entry && entry.js) || []).filter(function (f) { return typeof f === "string"; });
|
|
8449
|
-
var cssFiles = ((entry && entry.css) || []).filter(function (f) { return typeof f === "string"; });
|
|
8450
|
-
if (!jsFiles.length && !cssFiles.length) return;
|
|
8451
|
-
var world = entry.world === "MAIN" ? "MAIN" : "ISOLATED";
|
|
8452
|
-
var allFrames = !!entry.all_frames;
|
|
8453
|
-
function injectInto(excludedTabIds) {
|
|
8454
|
-
try {
|
|
8455
|
-
chrome.tabs.query({url: matches}, function (tabs) {
|
|
8456
|
-
var err = null;
|
|
8457
|
-
try { err = chrome.runtime.lastError; } catch (e) {}
|
|
8458
|
-
if (err || !tabs) return;
|
|
8459
|
-
for (var i = 0; i < tabs.length; i++) {
|
|
8460
|
-
(function (tab) {
|
|
8461
|
-
if (!tab || tab.id == null || !isInjectableUrl(tab.url)) return;
|
|
8462
|
-
if (excludedTabIds[tab.id]) return;
|
|
8463
|
-
var target = {tabId: tab.id, allFrames: allFrames};
|
|
8464
|
-
if (cssFiles.length && chrome.scripting.insertCSS) {
|
|
8465
|
-
try { chrome.scripting.insertCSS({target: target, files: cssFiles}, noopLastError); } catch (e) {}
|
|
8466
|
-
}
|
|
8467
|
-
if (jsFiles.length && chrome.scripting.executeScript) {
|
|
8468
|
-
try {
|
|
8469
|
-
chrome.scripting.executeScript(
|
|
8470
|
-
{target: target, files: jsFiles, world: world, injectImmediately: true},
|
|
8471
|
-
noopLastError
|
|
8472
|
-
);
|
|
8473
|
-
} catch (e) {}
|
|
8474
|
-
}
|
|
8475
|
-
})(tabs[i]);
|
|
8476
|
-
}
|
|
8477
|
-
});
|
|
8478
|
-
} catch (e) {}
|
|
8479
|
-
}
|
|
8480
|
-
if (Array.isArray(excludeMatches) && excludeMatches.length) {
|
|
8481
|
-
try {
|
|
8482
|
-
chrome.tabs.query({url: excludeMatches}, function (excludedTabs) {
|
|
8483
|
-
try { void chrome.runtime.lastError; } catch (e) {}
|
|
8484
|
-
var excluded = {};
|
|
8485
|
-
if (excludedTabs) {
|
|
8486
|
-
for (var i = 0; i < excludedTabs.length; i++) {
|
|
8487
|
-
if (excludedTabs[i] && excludedTabs[i].id != null) excluded[excludedTabs[i].id] = true;
|
|
8488
|
-
}
|
|
8489
|
-
}
|
|
8490
|
-
injectInto(excluded);
|
|
8491
|
-
});
|
|
8492
|
-
return;
|
|
8493
|
-
} catch (e) {}
|
|
8494
|
-
}
|
|
8495
|
-
injectInto({});
|
|
8496
|
-
}
|
|
8497
|
-
|
|
8498
|
-
// Re-inject all content scripts into their open tabs. Reads the manifest
|
|
8499
|
-
// FROM DISK (not chrome.runtime.getManifest(), which is frozen at extension-
|
|
8500
|
-
// registration time) because dev content-script filenames are content-hashed
|
|
8501
|
-
// and change on every edit — disk has the new js/css paths.
|
|
8502
|
-
function reinjectContentScripts(onDone) {
|
|
8503
|
-
var chrome = g.chrome;
|
|
8504
|
-
try {
|
|
8505
|
-
if (typeof g.fetch !== "function" || !chrome.scripting) return false;
|
|
8506
|
-
g.fetch(chrome.runtime.getURL("manifest.json"), {cache: "no-store"})
|
|
8507
|
-
.then(function (r) { return r.json(); })
|
|
8508
|
-
.then(function (manifest) {
|
|
8509
|
-
var entries = (manifest && manifest.content_scripts) || [];
|
|
8510
|
-
for (var i = 0; i < entries.length; i++) reinjectContentScriptEntry(entries[i]);
|
|
8511
|
-
reregisterForFutureNavigations(entries);
|
|
8512
|
-
if (onDone) { try { onDone(); } catch (e) {} }
|
|
8513
|
-
})
|
|
8514
|
-
.catch(function () {});
|
|
8515
|
-
return true;
|
|
8516
|
-
} catch (e) { return false; }
|
|
8517
|
-
}
|
|
8518
|
-
|
|
8519
|
-
function mapRunAt(runAt) {
|
|
8520
|
-
if (runAt === "document_start") return "document_start";
|
|
8521
|
-
if (runAt === "document_end") return "document_end";
|
|
8522
|
-
return "document_idle";
|
|
8523
|
-
}
|
|
8524
|
-
|
|
8525
|
-
// Re-register the content scripts dynamically (chrome.scripting) pointing at
|
|
8526
|
-
// the fresh files, so tabs opened AFTER an edit also get the new build. The
|
|
8527
|
-
// static manifest registration still points at the old content-hashed file
|
|
8528
|
-
// (it only updates on an extension reload) and keeps firing on new
|
|
8529
|
-
// navigations; the dynamic registration injects the new file alongside it,
|
|
8530
|
-
// and the wrapper's reinject runtime converges the mount to the newest build.
|
|
8531
|
-
// Idempotent: update an existing id, else register it.
|
|
8532
|
-
function reregisterForFutureNavigations(entries) {
|
|
8533
|
-
var chrome = g.chrome;
|
|
8534
|
-
if (
|
|
8535
|
-
!chrome.scripting ||
|
|
8536
|
-
!chrome.scripting.registerContentScripts ||
|
|
8537
|
-
!chrome.scripting.getRegisteredContentScripts
|
|
8538
|
-
) return;
|
|
8539
|
-
|
|
8540
|
-
var scripts = [];
|
|
8541
|
-
for (var i = 0; i < entries.length; i++) {
|
|
8542
|
-
var e = entries[i] || {};
|
|
8543
|
-
if (!Array.isArray(e.matches) || !e.matches.length) continue;
|
|
8544
|
-
var js = (e.js || []).filter(function (f) { return typeof f === "string"; });
|
|
8545
|
-
var css = (e.css || []).filter(function (f) { return typeof f === "string"; });
|
|
8546
|
-
if (!js.length && !css.length) continue;
|
|
8547
|
-
var s = {
|
|
8548
|
-
id: "extjs-dev-cs-" + i,
|
|
8549
|
-
matches: e.matches,
|
|
8550
|
-
runAt: mapRunAt(e.run_at),
|
|
8551
|
-
allFrames: !!e.all_frames,
|
|
8552
|
-
world: e.world === "MAIN" ? "MAIN" : "ISOLATED"
|
|
8553
|
-
};
|
|
8554
|
-
// Dev registration must not be BROADER than the static one: dropping
|
|
8555
|
-
// exclude_matches injects into pages the browser itself would skip.
|
|
8556
|
-
if (Array.isArray(e.exclude_matches) && e.exclude_matches.length) {
|
|
8557
|
-
s.excludeMatches = e.exclude_matches;
|
|
8558
|
-
}
|
|
8559
|
-
if (js.length) s.js = js;
|
|
8560
|
-
if (css.length) s.css = css;
|
|
8561
|
-
scripts.push(s);
|
|
8562
|
-
}
|
|
8563
|
-
if (!scripts.length) return;
|
|
8564
|
-
|
|
8565
|
-
try {
|
|
8566
|
-
chrome.scripting.getRegisteredContentScripts(function (existing) {
|
|
8567
|
-
try { void chrome.runtime.lastError; } catch (e) {}
|
|
8568
|
-
var have = {};
|
|
8569
|
-
if (existing) for (var k = 0; k < existing.length; k++) have[existing[k].id] = true;
|
|
8570
|
-
var toRegister = [], toUpdate = [];
|
|
8571
|
-
for (var j = 0; j < scripts.length; j++) {
|
|
8572
|
-
(have[scripts[j].id] ? toUpdate : toRegister).push(scripts[j]);
|
|
8573
|
-
}
|
|
8574
|
-
if (toRegister.length) {
|
|
8575
|
-
try { chrome.scripting.registerContentScripts(toRegister, noopLastError); } catch (e) {}
|
|
8576
|
-
}
|
|
8577
|
-
if (toUpdate.length) {
|
|
8578
|
-
try { chrome.scripting.updateContentScripts(toUpdate, noopLastError); } catch (e) {}
|
|
8579
|
-
}
|
|
8580
|
-
});
|
|
8581
|
-
} catch (e) {}
|
|
8582
|
-
}
|
|
8583
|
-
|
|
8584
|
-
// Perform a dev-loop reload without the CDP controller:
|
|
8585
|
-
// - content-scripts: re-inject the fresh script into open matching tabs in
|
|
8586
|
-
// place (no extension restart), the controller-less equivalent of CDP
|
|
8587
|
-
// reinjection. Needs the scripting permission + host access to the tab —
|
|
8588
|
-
// both injected in dev by ApplyDevDefaults. Falls back to a full reload
|
|
8589
|
-
// if scripting is unavailable.
|
|
8590
|
-
// - service-worker / full / manifest: restart the whole extension so it
|
|
8591
|
-
// re-registers from the fresh manifest.
|
|
8592
|
-
function performDevReload(type, onDone) {
|
|
8593
|
-
var chrome = g.chrome;
|
|
8594
|
-
if (!chrome) return;
|
|
8595
|
-
|
|
8596
|
-
var fullReload = function () {
|
|
8597
|
-
// Leave a pending-reinject flag for the NEXT producer generation:
|
|
8598
|
-
// Chrome never re-runs content scripts in tabs that were already open
|
|
8599
|
-
// when the extension reloads, and runtime.reload() does NOT fire
|
|
8600
|
-
// onInstalled (verified Chromium 146), so the boot-time heal below is
|
|
8601
|
-
// the only thing that converges open tabs after a SW/full reload —
|
|
8602
|
-
// without it a shared SW+content module edit restarts the SW while
|
|
8603
|
-
// every open tab keeps the stale content world (family F).
|
|
8604
|
-
try {
|
|
8605
|
-
if (chrome.storage && chrome.storage.local) {
|
|
8606
|
-
chrome.storage.local.set({__extjsDevPendingReinject: Date.now()}, noopLastError);
|
|
8607
|
-
}
|
|
8608
|
-
} catch (e) {}
|
|
8609
|
-
// Deferred so any in-flight result/log frame — and the "Reloading…"
|
|
8610
|
-
// console announcement dispatched into tabs — flushes before the SW
|
|
8611
|
-
// dies. runtime.reload() restarts the whole extension; the devtools
|
|
8612
|
-
// companion confirms completion via chrome.management events, so no
|
|
8613
|
-
// onDone here.
|
|
8614
|
-
try { setTimeout(function () { try { chrome.runtime.reload(); } catch (e) {} }, 150); } catch (e) {}
|
|
8615
|
-
};
|
|
8616
|
-
|
|
8617
|
-
if (type === "content-scripts" && chrome.scripting && chrome.tabs && chrome.tabs.query) {
|
|
8618
|
-
if (reinjectContentScripts(onDone)) return;
|
|
8619
|
-
}
|
|
8620
|
-
|
|
8621
|
-
fullReload();
|
|
8622
|
-
}
|
|
8623
|
-
|
|
8624
|
-
// ---- Dev-reload announcement surfaces --------------------------------
|
|
8625
|
-
// One server-built label travels the ReloadFrame; the producer echoes it
|
|
8626
|
-
// 1:1 into (a) the page's devtools console and (b) the bundled
|
|
8627
|
-
// extension-js-devtools companion (the bottom-left pill). Both fire HERE,
|
|
8628
|
-
// next to the actual reload action, so a surface can only say
|
|
8629
|
-
// "Reloading…" when a reload is actually being performed.
|
|
8630
|
-
|
|
8631
|
-
// Stable IDs of the bundled extension-js-devtools companion: Chromium pins
|
|
8632
|
-
// via the manifest "key"; Firefox via browser_specific_settings.gecko.id.
|
|
8633
|
-
// Absent companion (e.g. --no-browser in the user's own browser) is fine —
|
|
8634
|
-
// sendMessage just reports no receiver and we swallow it.
|
|
8635
|
-
var DEVTOOLS_COMPANION_ID_CHROMIUM = "kgdaecdpfkikjncaalnmmnjjfpofkcbl";
|
|
8636
|
-
var DEVTOOLS_COMPANION_ID_FIREFOX = "devtools@extension.js";
|
|
8637
|
-
|
|
8638
|
-
function notifyDevtoolsCompanion(phase, label, kind) {
|
|
8639
|
-
try {
|
|
8640
|
-
var chrome = g.chrome;
|
|
8641
|
-
if (!chrome || !chrome.runtime || typeof chrome.runtime.sendMessage !== "function") return;
|
|
8642
|
-
var id = engineName() === "firefox" ? DEVTOOLS_COMPANION_ID_FIREFOX : DEVTOOLS_COMPANION_ID_CHROMIUM;
|
|
8643
|
-
chrome.runtime.sendMessage(
|
|
8644
|
-
id,
|
|
8645
|
-
{type: "extjs-dev-reload-state", phase: phase, label: label || "", kind: kind || "", instanceId: INSTANCE_ID},
|
|
8646
|
-
function () { noopLastError(); }
|
|
8647
|
-
);
|
|
8648
|
-
} catch (e) {}
|
|
8649
|
-
}
|
|
8650
|
-
|
|
8651
|
-
// console.log the reload line into every open injectable tab. Runs in the
|
|
8652
|
-
// user extension's ISOLATED world, where the bridge relay patched console —
|
|
8653
|
-
// so the same line also lands in the centralized dev-server log stream.
|
|
8654
|
-
function announceReloadInTabs(text) {
|
|
8655
|
-
var chrome = g.chrome;
|
|
8656
|
-
if (!chrome || !chrome.tabs || !chrome.tabs.query) return;
|
|
8657
|
-
try {
|
|
8658
|
-
chrome.tabs.query({}, function (tabs) {
|
|
8659
|
-
noopLastError();
|
|
8660
|
-
if (!tabs) return;
|
|
8661
|
-
for (var i = 0; i < tabs.length; i++) {
|
|
8662
|
-
(function (tab) {
|
|
8663
|
-
if (!tab || tab.id == null || !isInjectableUrl(tab.url)) return;
|
|
8664
|
-
if (chrome.scripting && chrome.scripting.executeScript) {
|
|
8665
|
-
try {
|
|
8666
|
-
chrome.scripting.executeScript(
|
|
8667
|
-
{target: {tabId: tab.id}, func: function (t) { console.log(t); }, args: [text]},
|
|
8668
|
-
noopLastError
|
|
8669
|
-
);
|
|
8670
|
-
return;
|
|
8671
|
-
} catch (e) {}
|
|
8672
|
-
}
|
|
8673
|
-
// MV2 fallback (Firefox without the scripting API).
|
|
8674
|
-
if (chrome.tabs.executeScript) {
|
|
8675
|
-
try {
|
|
8676
|
-
chrome.tabs.executeScript(tab.id, {code: "console.log(" + JSON.stringify(text) + ");"}, noopLastError);
|
|
8677
|
-
} catch (e) {}
|
|
8678
|
-
}
|
|
8679
|
-
})(tabs[i]);
|
|
8680
|
-
}
|
|
8681
|
-
});
|
|
8682
|
-
} catch (e) {}
|
|
8683
|
-
}
|
|
8684
|
-
|
|
8685
|
-
function handleDevReloadFrame(frame) {
|
|
8686
|
-
var kind = frame.reloadType || "full";
|
|
8687
|
-
var label = typeof frame.label === "string" ? frame.label : "";
|
|
8688
|
-
// The server always builds the label; the kind-derived fallback only
|
|
8689
|
-
// covers a malformed frame so the announcement stays truthful.
|
|
8690
|
-
var fallback = kind === "content-scripts" ? "content_script"
|
|
8691
|
-
: kind === "service-worker" ? "service_worker"
|
|
8692
|
-
: "extension";
|
|
8693
|
-
var announced = "[extension.js] Reloading " + (label || fallback) + "…";
|
|
8694
|
-
|
|
8695
|
-
notifyDevtoolsCompanion("reloading", label, kind);
|
|
8696
|
-
|
|
8697
|
-
if (kind === "page") {
|
|
8698
|
-
// Notify-only: rspack-dev-server's livereload refreshes the open
|
|
8699
|
-
// surface; reloading the extension here would race it. No tab console
|
|
8700
|
-
// line either — the reloading page clears its own console anyway.
|
|
8701
|
-
return;
|
|
8702
|
-
}
|
|
8703
|
-
|
|
8704
|
-
// Delivery ack for the broker: proves this SW's message pump actually
|
|
8705
|
-
// processed the frame — a successful socket WRITE proves nothing when
|
|
8706
|
-
// the worker is wedged-but-connected (bug 27). The broker latches a
|
|
8707
|
-
// content-scripts reload until this ack and replays it to the next
|
|
8708
|
-
// producer hello, so an edit that landed on a dead pump still converges.
|
|
8709
|
-
// Sent on receipt (not after reinjection): the scripting-unavailable
|
|
8710
|
-
// fallback restarts the whole extension, and an unacked latch would
|
|
8711
|
-
// replay into the fresh SW and restart it a second time.
|
|
8712
|
-
send({type: "reload-ack", reloadType: kind, label: label});
|
|
8713
|
-
|
|
8714
|
-
announceReloadInTabs(announced);
|
|
8715
|
-
performDevReload(kind, function () {
|
|
8716
|
-
// Only the content-scripts path confirms from here (reinjection ran to
|
|
8717
|
-
// completion in this same SW). Full/SW reloads are confirmed by the
|
|
8718
|
-
// devtools companion's chrome.management listeners.
|
|
8719
|
-
notifyDevtoolsCompanion("reloaded", label, kind);
|
|
8720
|
-
});
|
|
8721
|
-
}
|
|
8722
|
-
|
|
8723
|
-
function sanitize(args) {
|
|
8724
|
-
var out = [];
|
|
8725
|
-
for (var i = 0; i < args.length; i++) {
|
|
8726
|
-
var p = args[i];
|
|
8727
|
-
try {
|
|
8728
|
-
if (typeof p === "string") out.push(p.length > 2048 ? p.slice(0, 2048) + "..." : p);
|
|
8729
|
-
else if (p instanceof Error) out.push(p.name + ": " + p.message);
|
|
8730
|
-
else out.push(JSON.stringify(p));
|
|
8731
|
-
} catch (e) {
|
|
8732
|
-
out.push(String(p));
|
|
8733
|
-
}
|
|
8734
|
-
if (out.join(" ").length > 8192) break;
|
|
8735
|
-
}
|
|
8736
|
-
return out;
|
|
8737
|
-
}
|
|
8738
|
-
|
|
8739
|
-
function flush() {
|
|
8740
|
-
while (queue.length && open && socket) {
|
|
8741
|
-
var f = queue.shift();
|
|
8742
|
-
try { socket.send(JSON.stringify(f)); } catch (e) { break; }
|
|
8743
|
-
}
|
|
8744
|
-
}
|
|
8745
|
-
|
|
8746
|
-
function send(frame) {
|
|
8747
|
-
if (open && socket) {
|
|
8748
|
-
try { socket.send(JSON.stringify(frame)); return; } catch (e) {}
|
|
8749
|
-
}
|
|
8750
|
-
if (queue.length < MAX_QUEUE) queue.push(frame);
|
|
8751
|
-
}
|
|
8752
|
-
|
|
8753
|
-
function schedule() {
|
|
8754
|
-
var delay = backoff;
|
|
8755
|
-
backoff = Math.min(backoff * 2, MAX_BACKOFF);
|
|
8756
|
-
try { setTimeout(connect, delay); } catch (e) {}
|
|
8757
|
-
}
|
|
8758
|
-
|
|
8759
|
-
function connect() {
|
|
8760
|
-
try {
|
|
8761
|
-
socket = new WS("ws://" + HOST + ":" + PORT + "/extjs-control");
|
|
8762
|
-
} catch (e) {
|
|
8763
|
-
schedule();
|
|
8764
|
-
return;
|
|
8765
|
-
}
|
|
8766
|
-
socket.onopen = function () {
|
|
8767
|
-
open = true;
|
|
8768
|
-
backoff = 250;
|
|
8769
|
-
try {
|
|
8770
|
-
socket.send(JSON.stringify({type: "hello", v: 1, role: "producer", instanceId: INSTANCE_ID}));
|
|
8771
|
-
} catch (e) {}
|
|
8772
|
-
flush();
|
|
8773
|
-
};
|
|
8774
|
-
socket.onmessage = function (ev) {
|
|
8775
|
-
// Slice 2: the broker routes authorized command frames to this SW.
|
|
8776
|
-
var frame;
|
|
8777
|
-
try { frame = JSON.parse(typeof ev.data === "string" ? ev.data : ""); } catch (e) { return; }
|
|
8778
|
-
if (frame && frame.type === "command") {
|
|
8779
|
-
try { executeCommand(frame); } catch (e) { replyErr(frame.cmdId, "ExecutorError", e); }
|
|
8780
|
-
} else if (frame && frame.type === "reload") {
|
|
8781
|
-
// Dev-loop reload broadcast (see broker.broadcastReload).
|
|
8782
|
-
// Fire-and-forget: no result frame is expected.
|
|
8783
|
-
try { handleDevReloadFrame(frame); } catch (e) {}
|
|
8784
|
-
} else if (frame && frame.type === "ping") {
|
|
8785
|
-
// Server keepalive: merely RECEIVING this message resets the MV3
|
|
8786
|
-
// service worker's ~30s idle timer (Chrome 116+), keeping this SW
|
|
8787
|
-
// reachable for reload broadcasts. Nothing to do.
|
|
8788
|
-
}
|
|
8789
|
-
};
|
|
8790
|
-
socket.onclose = function () {
|
|
8791
|
-
open = false;
|
|
8792
|
-
socket = null;
|
|
8793
|
-
schedule();
|
|
8794
|
-
};
|
|
8795
|
-
socket.onerror = function () {
|
|
8796
|
-
try { socket && socket.close(); } catch (e) {}
|
|
8797
|
-
};
|
|
8798
|
-
}
|
|
8799
|
-
|
|
8800
|
-
LEVELS.forEach(function (level) {
|
|
8801
|
-
var orig = typeof consoleRef[level] === "function"
|
|
8802
|
-
? consoleRef[level].bind(consoleRef)
|
|
8803
|
-
: function () {};
|
|
8804
|
-
consoleRef[level] = function () {
|
|
8805
|
-
try {
|
|
8806
|
-
send({
|
|
8807
|
-
type: "log",
|
|
8808
|
-
event: {
|
|
8809
|
-
v: 1,
|
|
8810
|
-
id: nowId(),
|
|
8811
|
-
timestamp: Date.now(),
|
|
8812
|
-
level: level,
|
|
8813
|
-
context: CONTEXT,
|
|
8814
|
-
messageParts: sanitize([].slice.call(arguments)),
|
|
8815
|
-
runId: INSTANCE_ID
|
|
8816
|
-
}
|
|
8817
|
-
});
|
|
8818
|
-
} catch (e) {}
|
|
8819
|
-
return orig.apply(consoleRef, arguments);
|
|
8820
|
-
};
|
|
8821
|
-
});
|
|
8822
|
-
|
|
8823
|
-
// Multi-context console forwarding: other contexts (content scripts, surface
|
|
8824
|
-
// pages) can't reliably open ws://127.0.0.1 (page CSP / connect-src), so they
|
|
8825
|
-
// relay console to this SW, which owns the WS. The relay travels a NAMED
|
|
8826
|
-
// runtime.Port — never runtime.sendMessage — because port traffic is
|
|
8827
|
-
// invisible to the extension's own onMessage listeners. With sendMessage, an
|
|
8828
|
-
// extension whose SW echoes every message back to its tabs (wild newtube:
|
|
8829
|
-
// onMessage → tabs.sendMessage(msg) to all tabs) turned each relayed log
|
|
8830
|
-
// into a new tab message, whose subject-side console.log became another
|
|
8831
|
-
// relayed envelope — a self-sustaining dev-only message storm (25k rows/10min
|
|
8832
|
-
// observed) that starved the extension system and wedged Chromium's DevTools
|
|
8833
|
-
// endpoint (family B). We enrich with the real tabId/url from the port sender.
|
|
8834
|
-
function shipRelayedLog(ev, sender) {
|
|
8835
|
-
try {
|
|
8836
|
-
send({
|
|
8837
|
-
type: "log",
|
|
8838
|
-
event: {
|
|
8839
|
-
v: 1,
|
|
8840
|
-
id: nowId(),
|
|
8841
|
-
timestamp: Date.now(),
|
|
8842
|
-
level: ev.level || "log",
|
|
8843
|
-
context: ev.context || "content",
|
|
8844
|
-
messageParts: Array.isArray(ev.messageParts) ? ev.messageParts : [],
|
|
8845
|
-
url: ev.url || (sender ? sender.url : undefined),
|
|
8846
|
-
tabId: sender && sender.tab ? sender.tab.id : undefined,
|
|
8847
|
-
frameId: sender ? sender.frameId : undefined,
|
|
8848
|
-
runId: INSTANCE_ID
|
|
8849
|
-
}
|
|
8850
|
-
});
|
|
8851
|
-
} catch (e) {}
|
|
8852
|
-
}
|
|
8853
|
-
try {
|
|
8854
|
-
var rtPort = g.chrome;
|
|
8855
|
-
if (rtPort && rtPort.runtime && rtPort.runtime.onConnect) {
|
|
8856
|
-
rtPort.runtime.onConnect.addListener(function (port) {
|
|
8857
|
-
if (!port || port.name !== "__extjs-bridge-log__") return;
|
|
8858
|
-
try {
|
|
8859
|
-
port.onMessage.addListener(function (msg) {
|
|
8860
|
-
if (!msg || !msg.__extjsBridgeLog) return;
|
|
8861
|
-
shipRelayedLog(msg.__extjsBridgeLog, port.sender);
|
|
8862
|
-
});
|
|
8863
|
-
} catch (e) {}
|
|
8864
|
-
});
|
|
8865
|
-
}
|
|
8866
|
-
} catch (e) {}
|
|
8867
|
-
// Legacy sendMessage path: kept for any surface still relaying the old way
|
|
8868
|
-
// (harmless one-predicate listener; new relays never use it).
|
|
8869
|
-
try {
|
|
8870
|
-
var rt = g.chrome;
|
|
8871
|
-
if (rt && rt.runtime && rt.runtime.onMessage) {
|
|
8872
|
-
rt.runtime.onMessage.addListener(function (msg, sender) {
|
|
8873
|
-
if (!msg || !msg.__extjsBridgeLog) return;
|
|
8874
|
-
shipRelayedLog(msg.__extjsBridgeLog, sender);
|
|
8875
|
-
// No async response.
|
|
8876
|
-
});
|
|
8877
|
-
}
|
|
8878
|
-
} catch (e) {}
|
|
8879
|
-
|
|
8880
|
-
// Chrome never injects manifest content scripts into tabs that were
|
|
8881
|
-
// already open when the extension (re)loads, so after a dev full reload
|
|
8882
|
-
// (manifest edit, SW edit, chrome.runtime.reload) every open tab keeps the
|
|
8883
|
-
// PREVIOUS build's content-script DOM as a zombie: the nodes still render
|
|
8884
|
-
// but their listeners died with the old world, and nothing heals the tab
|
|
8885
|
-
// until the next recompile happens to reinject. Fire one producer-driven
|
|
8886
|
-
// reinject when this SW generation is a fresh install/reload so open tabs
|
|
8887
|
-
// converge to the new build immediately. onInstalled is the gate: it fires
|
|
8888
|
-
// for install/update/reload (fresh worlds) but NOT for idle-stop SW wakes,
|
|
8889
|
-
// where reinjecting would churn mounted UI for no reason.
|
|
8890
|
-
try {
|
|
8891
|
-
var rtBoot = g.chrome;
|
|
8892
|
-
if (rtBoot && rtBoot.runtime && rtBoot.runtime.onInstalled) {
|
|
8893
|
-
rtBoot.runtime.onInstalled.addListener(function () {
|
|
8894
|
-
try {
|
|
8895
|
-
setTimeout(function () {
|
|
8896
|
-
try { reinjectContentScripts(); } catch (e) {}
|
|
8897
|
-
}, 250);
|
|
8898
|
-
} catch (e) {}
|
|
8899
|
-
});
|
|
8900
|
-
}
|
|
8901
|
-
} catch (e) {}
|
|
8902
|
-
|
|
8903
|
-
// runtime.reload() does NOT fire onInstalled (verified Chromium 146), so
|
|
8904
|
-
// a dev-driven SW/full reload leaves the listener above silent and every
|
|
8905
|
-
// open tab keeps the previous build's content world. fullReload() stamps
|
|
8906
|
-
// __extjsDevPendingReinject into storage.local right before reloading;
|
|
8907
|
-
// consume it here (fresh flags only — a stale one from a crashed session
|
|
8908
|
-
// is dropped) and heal open tabs from the on-disk manifest. Idle-stop SW
|
|
8909
|
-
// wakes never see the flag, so this cannot churn mounted UI.
|
|
8910
|
-
try {
|
|
8911
|
-
var stBoot = g.chrome;
|
|
8912
|
-
if (stBoot && stBoot.storage && stBoot.storage.local) {
|
|
8913
|
-
stBoot.storage.local.get("__extjsDevPendingReinject", function (res) {
|
|
8914
|
-
noopLastError();
|
|
8915
|
-
var ts = res && res.__extjsDevPendingReinject;
|
|
8916
|
-
if (ts == null) return;
|
|
8917
|
-
try { stBoot.storage.local.remove("__extjsDevPendingReinject", noopLastError); } catch (e) {}
|
|
8918
|
-
if (typeof ts !== "number" || Date.now() - ts > 30000) return;
|
|
8919
|
-
setTimeout(function () {
|
|
8920
|
-
try { reinjectContentScripts(); } catch (e) {}
|
|
8921
|
-
}, 250);
|
|
8922
|
-
});
|
|
8923
|
-
}
|
|
8924
|
-
} catch (e) {}
|
|
8925
|
-
|
|
8926
|
-
connect();
|
|
8927
|
-
} catch (e) {}
|
|
8928
|
-
})();
|
|
8929
|
-
`;
|
|
8930
|
-
const BRIDGE_RELAY_SOURCE = `;(function () {
|
|
8931
|
-
try {
|
|
8932
|
-
var g = (typeof globalThis === "object" && globalThis) ? globalThis : this;
|
|
8933
|
-
if (!g || g.__extjsBridgeRelayInstalled) return;
|
|
8934
|
-
|
|
8935
|
-
var CONTEXT = "__EXTJS_CONTEXT__";
|
|
8936
|
-
var chrome = g.chrome;
|
|
8937
|
-
if (!chrome || !chrome.runtime) return;
|
|
8938
|
-
var canRelay = typeof chrome.runtime.connect === "function";
|
|
8939
|
-
|
|
8940
|
-
g.__extjsBridgeRelayInstalled = true;
|
|
8941
|
-
var consoleRef = g.console || {};
|
|
8942
|
-
var LEVELS = ["log", "info", "warn", "error", "debug", "trace"];
|
|
8943
|
-
|
|
8944
|
-
function sanitize(args) {
|
|
8945
|
-
var out = [];
|
|
8946
|
-
for (var i = 0; i < args.length; i++) {
|
|
8947
|
-
var p = args[i];
|
|
8948
|
-
try {
|
|
8949
|
-
if (typeof p === "string") out.push(p.length > 2048 ? p.slice(0, 2048) + "..." : p);
|
|
8950
|
-
else if (p instanceof Error) out.push(p.name + ": " + p.message);
|
|
8951
|
-
else out.push(JSON.stringify(p));
|
|
8952
|
-
} catch (e) { out.push(String(p)); }
|
|
8953
|
-
if (out.join(" ").length > 8192) break;
|
|
8954
|
-
}
|
|
8955
|
-
return out;
|
|
8956
|
-
}
|
|
8957
|
-
|
|
8958
|
-
function here() { try { return g.location ? g.location.href : undefined; } catch (e) { return undefined; } }
|
|
8959
|
-
|
|
8960
|
-
// Lazy named port to the SW producer. Connecting wakes an idle SW like
|
|
8961
|
-
// sendMessage does, but port frames never reach the extension's own
|
|
8962
|
-
// onMessage listeners (see the loop note above). Reconnect on demand: the
|
|
8963
|
-
// SW idling out (or reloading) disconnects the port; the next log redials.
|
|
8964
|
-
var logPort = null;
|
|
8965
|
-
function getLogPort() {
|
|
8966
|
-
if (!canRelay) return null;
|
|
8967
|
-
if (logPort) return logPort;
|
|
8968
|
-
try {
|
|
8969
|
-
logPort = chrome.runtime.connect({name: "__extjs-bridge-log__"});
|
|
8970
|
-
logPort.onDisconnect.addListener(function () {
|
|
8971
|
-
try { void chrome.runtime.lastError; } catch (e) {}
|
|
8972
|
-
logPort = null;
|
|
8973
|
-
});
|
|
8974
|
-
} catch (e) { logPort = null; }
|
|
8975
|
-
return logPort;
|
|
8976
|
-
}
|
|
8977
|
-
|
|
8978
|
-
LEVELS.forEach(function (level) {
|
|
8979
|
-
var orig = typeof consoleRef[level] === "function" ? consoleRef[level].bind(consoleRef) : function () {};
|
|
8980
|
-
consoleRef[level] = function () {
|
|
8981
|
-
try {
|
|
8982
|
-
var p = getLogPort();
|
|
8983
|
-
if (p) {
|
|
8984
|
-
try {
|
|
8985
|
-
p.postMessage({__extjsBridgeLog: {level: level, context: CONTEXT, messageParts: sanitize([].slice.call(arguments)), url: here()}});
|
|
8986
|
-
} catch (e) {
|
|
8987
|
-
// stale port (SW restarted): drop it and redial once
|
|
8988
|
-
logPort = null;
|
|
8989
|
-
var p2 = getLogPort();
|
|
8990
|
-
if (p2) { try { p2.postMessage({__extjsBridgeLog: {level: level, context: CONTEXT, messageParts: sanitize([].slice.call(arguments)), url: here()}}); } catch (e2) {} }
|
|
8991
|
-
}
|
|
8992
|
-
}
|
|
8993
|
-
} catch (e) {}
|
|
8994
|
-
return orig.apply(consoleRef, arguments);
|
|
8995
|
-
};
|
|
8996
|
-
});
|
|
8997
|
-
|
|
8998
|
-
// Surface DOM inspection: the SW executor can't reach popup/options/sidebar
|
|
8999
|
-
// DOM (separate extension pages), and the sidecar can't either (cross-extension
|
|
9000
|
-
// isolation). So THIS page — the user extension's own surface — answers an
|
|
9001
|
-
// inspect request for its own context. The SW broadcasts the request; only the
|
|
9002
|
-
// matching-context surface responds with its DOM snapshot.
|
|
9003
|
-
try {
|
|
9004
|
-
if (chrome.runtime && chrome.runtime.onMessage) {
|
|
9005
|
-
chrome.runtime.onMessage.addListener(function (msg, _sender, sendResponse) {
|
|
9006
|
-
if (!msg || !msg.__extjsInspectRequest) return;
|
|
9007
|
-
if (!msg.target || msg.target.context !== CONTEXT) return; // not for me
|
|
9008
|
-
try {
|
|
9009
|
-
var args = msg.args || {};
|
|
9010
|
-
var wantHtml = !args.include || args.include.indexOf("html") !== -1;
|
|
9011
|
-
var cap = args.maxBytes || 262144;
|
|
9012
|
-
function countShadow(root) {
|
|
9013
|
-
var n = 0, els = root.querySelectorAll("*");
|
|
9014
|
-
for (var i = 0; i < els.length; i++) { if (els[i].shadowRoot) { n++; n += countShadow(els[i].shadowRoot); } }
|
|
9015
|
-
return n;
|
|
9016
|
-
}
|
|
9017
|
-
var doc = g.document;
|
|
9018
|
-
var roots = doc.querySelectorAll('#extension-root,[data-extension-root]');
|
|
9019
|
-
var snap = {
|
|
9020
|
-
context: CONTEXT,
|
|
9021
|
-
url: here(),
|
|
9022
|
-
title: doc.title,
|
|
9023
|
-
summary: {
|
|
9024
|
-
htmlLength: doc.documentElement.outerHTML.length,
|
|
9025
|
-
scriptCount: doc.querySelectorAll("script").length,
|
|
9026
|
-
styleCount: doc.querySelectorAll("style,link[rel=stylesheet]").length,
|
|
9027
|
-
extensionRootCount: roots.length,
|
|
9028
|
-
openShadowRoots: countShadow(doc),
|
|
9029
|
-
bodyChildCount: doc.body ? doc.body.children.length : 0
|
|
9030
|
-
}
|
|
9031
|
-
};
|
|
9032
|
-
if (wantHtml) {
|
|
9033
|
-
var html = doc.documentElement.outerHTML;
|
|
9034
|
-
if (cap > 0 && html.length > cap) { snap.html = html.slice(0, cap); snap.htmlTruncated = true; }
|
|
9035
|
-
else { snap.html = html; }
|
|
9036
|
-
}
|
|
9037
|
-
sendResponse({ok: true, value: snap});
|
|
9038
|
-
} catch (e) {
|
|
9039
|
-
sendResponse({ok: false, error: {name: "InspectError", message: String(e)}});
|
|
9040
|
-
}
|
|
9041
|
-
return true; // responded
|
|
9042
|
-
});
|
|
9043
|
-
}
|
|
9044
|
-
} catch (e) {}
|
|
9045
|
-
} catch (e) {}
|
|
9046
|
-
})();
|
|
9047
|
-
`;
|
|
9048
|
-
function buildBridgeRelaySource(opts) {
|
|
9049
|
-
return BRIDGE_RELAY_SOURCE.replace(/__EXTJS_CONTEXT__/g, String(opts.context || 'content'));
|
|
9050
|
-
}
|
|
9051
|
-
function buildBridgeProducerSource(opts) {
|
|
9052
|
-
if (!opts.controlPort || opts.controlPort < 1) return '';
|
|
9053
|
-
return BRIDGE_PRODUCER_SOURCE.replace(/__EXTJS_CONTROL_PORT__/g, String(opts.controlPort)).replace(/__EXTJS_INSTANCE_ID__/g, String(opts.instanceId)).replace(/__EXTJS_CONTEXT__/g, String(opts.context || 'background')).replace(/__EXTJS_CONTROL_HOST__/g, String(opts.host || '127.0.0.1'));
|
|
9054
|
-
}
|
|
9055
|
-
const inject_bridge_producer_BACKGROUND_ASSET = /(^|\/)background\/(?:service_worker|scripts?)\.js$/i;
|
|
9056
|
-
class InjectBridgeProducer {
|
|
9057
|
-
apply(compiler) {
|
|
9058
|
-
const controlPort = parseInt(String(process.env.EXTENSION_CONTROL_PORT || ''), 10);
|
|
9059
|
-
const instanceId = String(process.env.EXTENSION_INSTANCE_ID || '');
|
|
9060
|
-
const host = String(process.env.EXTENSION_DEV_SERVER_CONNECTABLE_HOST || '').trim() || '127.0.0.1';
|
|
9061
|
-
const source = buildBridgeProducerSource({
|
|
9062
|
-
controlPort: Number.isFinite(controlPort) ? controlPort : null,
|
|
9063
|
-
instanceId,
|
|
9064
|
-
context: 'background',
|
|
9065
|
-
host
|
|
9066
|
-
});
|
|
9067
|
-
if (!source) return;
|
|
9068
|
-
compiler.hooks.thisCompilation.tap(InjectBridgeProducer.name, (compilation)=>{
|
|
9069
|
-
compilation.hooks.processAssets.tap({
|
|
9070
|
-
name: InjectBridgeProducer.name,
|
|
9071
|
-
stage: core_Compilation.PROCESS_ASSETS_STAGE_REPORT + 101
|
|
9072
|
-
}, ()=>{
|
|
9073
|
-
for (const asset of compilation.getAssets()){
|
|
9074
|
-
if (!inject_bridge_producer_BACKGROUND_ASSET.test(asset.name)) continue;
|
|
9075
|
-
const original = asset.source.source().toString();
|
|
9076
|
-
if (-1 !== original.indexOf('__extjsBridgeProducerInstalled')) continue;
|
|
9077
|
-
const next = source + '\n' + original;
|
|
9078
|
-
compilation.updateAsset(asset.name, new core_sources.RawSource(next));
|
|
9079
|
-
}
|
|
9080
|
-
});
|
|
9081
|
-
});
|
|
9082
|
-
}
|
|
9083
|
-
}
|
|
9084
|
-
const RELAY_TARGETS = [
|
|
9085
|
-
{
|
|
9086
|
-
re: /(^|\/)content_scripts\/.+\.js$/i,
|
|
9087
|
-
context: 'content'
|
|
9088
|
-
},
|
|
9089
|
-
{
|
|
9090
|
-
re: /(^|\/)action\/index\.js$/i,
|
|
9091
|
-
context: 'popup'
|
|
9092
|
-
},
|
|
9093
|
-
{
|
|
9094
|
-
re: /(^|\/)options\/index\.js$/i,
|
|
9095
|
-
context: 'options'
|
|
9096
|
-
},
|
|
9097
|
-
{
|
|
9098
|
-
re: /(^|\/)sidebar\/index\.js$/i,
|
|
9099
|
-
context: 'sidebar'
|
|
9100
|
-
},
|
|
9101
|
-
{
|
|
9102
|
-
re: /(^|\/)devtools\/index\.js$/i,
|
|
9103
|
-
context: 'devtools'
|
|
9104
|
-
}
|
|
9105
|
-
];
|
|
9106
|
-
class InjectBridgeRelay {
|
|
9107
|
-
apply(compiler) {
|
|
9108
|
-
const controlPort = parseInt(String(process.env.EXTENSION_CONTROL_PORT || ''), 10);
|
|
9109
|
-
if (!Number.isFinite(controlPort) || controlPort < 1) return;
|
|
9110
|
-
const sourceFor = new Map();
|
|
9111
|
-
for (const t of RELAY_TARGETS)if (!sourceFor.has(t.context)) sourceFor.set(t.context, buildBridgeRelaySource({
|
|
9112
|
-
context: t.context
|
|
9113
|
-
}));
|
|
9114
|
-
compiler.hooks.thisCompilation.tap(InjectBridgeRelay.name, (compilation)=>{
|
|
9115
|
-
compilation.hooks.processAssets.tap({
|
|
9116
|
-
name: InjectBridgeRelay.name,
|
|
9117
|
-
stage: core_Compilation.PROCESS_ASSETS_STAGE_REPORT + 101
|
|
9118
|
-
}, ()=>{
|
|
9119
|
-
for (const asset of compilation.getAssets()){
|
|
9120
|
-
const target = RELAY_TARGETS.find((t)=>t.re.test(asset.name));
|
|
9121
|
-
if (!target) continue;
|
|
9122
|
-
const original = asset.source.source().toString();
|
|
9123
|
-
if (-1 !== original.indexOf('__extjsBridgeRelayInstalled')) continue;
|
|
9124
|
-
const next = sourceFor.get(target.context) + '\n' + original;
|
|
9125
|
-
compilation.updateAsset(asset.name, new core_sources.RawSource(next));
|
|
9126
|
-
}
|
|
9127
|
-
});
|
|
9128
|
-
});
|
|
9129
|
-
}
|
|
9130
|
-
}
|
|
9131
|
-
const DEV_SERVER_STRONG_MARKERS = [
|
|
9132
|
-
'@rspack/dev-server/client/index.js?',
|
|
9133
|
-
'@rspack/dev-server/client/utils/ansiHTML.js',
|
|
9134
|
-
'[HMR] Waiting for update signal from WDS...'
|
|
9135
|
-
];
|
|
9136
|
-
const DEV_SERVER_WEAK_MARKERS = [
|
|
9137
|
-
'webpack-dev-server',
|
|
9138
|
-
'WebSocketClient',
|
|
9139
|
-
'.hot.check()',
|
|
9140
|
-
'[HMR] Cannot find update. Need to do a full reload!'
|
|
9141
|
-
];
|
|
9142
|
-
function contentScriptRetainsDevServerRuntime(source) {
|
|
9143
|
-
return source.includes('@rspack/dev-server/client');
|
|
9144
|
-
}
|
|
9145
|
-
function stripDevServerStartupFromContentScript(source) {
|
|
9146
|
-
let nextSource = source;
|
|
9147
|
-
const startupModuleIds = getStartupModuleIds(source);
|
|
9148
|
-
for (const moduleId of startupModuleIds){
|
|
9149
|
-
const moduleBody = getModuleBody(source, moduleId);
|
|
9150
|
-
if (!moduleBody) continue;
|
|
9151
|
-
const strongHit = DEV_SERVER_STRONG_MARKERS.some((marker)=>moduleBody.includes(marker));
|
|
9152
|
-
const weakHits = DEV_SERVER_WEAK_MARKERS.filter((marker)=>moduleBody.includes(marker)).length;
|
|
9153
|
-
if (strongHit || weakHits >= 2) nextSource = stripStartupRequire(nextSource, moduleId);
|
|
9154
|
-
}
|
|
9155
|
-
return nextSource;
|
|
9156
|
-
}
|
|
9157
|
-
function getStartupModuleIds(source) {
|
|
9158
|
-
const startupIndex = source.indexOf('// startup');
|
|
9159
|
-
if (-1 === startupIndex) return [];
|
|
9160
|
-
const startupSection = source.slice(startupIndex);
|
|
9161
|
-
const requirePattern = /__webpack_require__\((\d+)\);/g;
|
|
9162
|
-
const ids = [];
|
|
9163
|
-
let match = null;
|
|
9164
|
-
while(match = requirePattern.exec(startupSection))ids.push(match[1]);
|
|
9165
|
-
return ids;
|
|
9166
|
-
}
|
|
9167
|
-
function getModuleBody(source, moduleId) {
|
|
9168
|
-
const moduleHeaderPattern = new RegExp(`(?:^|\\n)${moduleId}\\([^)]*\\)\\s*\\{`, 'm');
|
|
9169
|
-
const headerMatch = moduleHeaderPattern.exec(source);
|
|
9170
|
-
if (!headerMatch) return null;
|
|
9171
|
-
const moduleStart = headerMatch.index;
|
|
9172
|
-
const nextHeaderPattern = /(?:^|\n)\d+\([^)]*\)\s*\{/g;
|
|
9173
|
-
nextHeaderPattern.lastIndex = moduleStart + headerMatch[0].length;
|
|
9174
|
-
const nextHeaderMatch = nextHeaderPattern.exec(source);
|
|
9175
|
-
return source.slice(moduleStart, nextHeaderMatch ? nextHeaderMatch.index : source.length);
|
|
9176
|
-
}
|
|
9177
|
-
function stripStartupRequire(source, moduleId) {
|
|
9178
|
-
const startupRequirePattern = new RegExp(`^\\s*__webpack_require__\\(${moduleId}\\);\\n?`, 'm');
|
|
9179
|
-
return source.replace(startupRequirePattern, '');
|
|
9180
|
-
}
|
|
9181
|
-
const CONTENT_SCRIPT_ASSET = /(^|\/)content_scripts\/content-\d+(?:\.[a-f0-9]+)?\.js$/i;
|
|
9182
|
-
class StripContentScriptDevServerRuntime {
|
|
9183
|
-
apply(compiler) {
|
|
9184
|
-
compiler.hooks.thisCompilation.tap(StripContentScriptDevServerRuntime.name, (compilation)=>{
|
|
9185
|
-
compilation.hooks.processAssets.tap({
|
|
9186
|
-
name: StripContentScriptDevServerRuntime.name,
|
|
9187
|
-
stage: core_Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
9188
|
-
}, ()=>{
|
|
9189
|
-
for (const asset of compilation.getAssets()){
|
|
9190
|
-
if (!CONTENT_SCRIPT_ASSET.test(asset.name)) continue;
|
|
9191
|
-
const originalSource = asset.source.source().toString();
|
|
9192
|
-
const strippedSource = stripDevServerStartupFromContentScript(originalSource);
|
|
9193
|
-
if (strippedSource !== originalSource) compilation.updateAsset(asset.name, new core_sources.RawSource(strippedSource));
|
|
9194
|
-
if (contentScriptRetainsDevServerRuntime(strippedSource)) {
|
|
9195
|
-
const warning = new core_WebpackError(`Could not strip the dev-server runtime from ${asset.name}. This usually means the bundler's output format changed and Extension.js needs an update. The content script may try to open a dev-server connection on the host page. Please report this at https://github.com/extension-js/extension.js/issues.`);
|
|
9196
|
-
warning.name = 'ContentScriptDevServerRuntimeWarning';
|
|
9197
|
-
warning.file = asset.name;
|
|
9198
|
-
compilation.warnings ||= [];
|
|
9199
|
-
compilation.warnings.push(warning);
|
|
9200
|
-
}
|
|
9201
|
-
}
|
|
9202
|
-
});
|
|
9203
|
-
});
|
|
9204
|
-
}
|
|
9205
|
-
}
|
|
9206
|
-
class KeepGetURLImportsNative {
|
|
9207
|
-
manifestPath;
|
|
9208
|
-
constructor(options){
|
|
9209
|
-
this.manifestPath = options.manifestPath;
|
|
6174
|
+
class KeepGetURLImportsNative {
|
|
6175
|
+
manifestPath;
|
|
6176
|
+
constructor(options){
|
|
6177
|
+
this.manifestPath = options.manifestPath;
|
|
9210
6178
|
}
|
|
9211
6179
|
apply(compiler) {
|
|
9212
6180
|
const manifestDir = canonicalizeDir(__rspack_external_path.dirname(this.manifestPath));
|
|
@@ -9291,7 +6259,7 @@ class ValidateContentScriptSyntax {
|
|
|
9291
6259
|
compiler.hooks.thisCompilation.tap("scripts:validate-content-script-syntax", (compilation)=>{
|
|
9292
6260
|
compilation.hooks.processAssets.tap({
|
|
9293
6261
|
name: "scripts:validate-content-script-syntax",
|
|
9294
|
-
stage:
|
|
6262
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
9295
6263
|
}, ()=>{
|
|
9296
6264
|
const assets = 'function' == typeof compilation.getAssets ? compilation.getAssets() : [];
|
|
9297
6265
|
for (const asset of assets){
|
|
@@ -9308,7 +6276,7 @@ class ValidateContentScriptSyntax {
|
|
|
9308
6276
|
new Function(source);
|
|
9309
6277
|
} catch (error) {
|
|
9310
6278
|
if (error?.name !== 'SyntaxError') continue;
|
|
9311
|
-
const err = new
|
|
6279
|
+
const err = new WebpackError([
|
|
9312
6280
|
`${name} is not valid JavaScript: ${error.message}.`,
|
|
9313
6281
|
"The browser will silently skip an unparsable content script —",
|
|
9314
6282
|
'it never injects and reports no error anywhere. Fix the syntax',
|
|
@@ -9336,7 +6304,8 @@ class ScriptsPlugin {
|
|
|
9336
6304
|
if (!hasValidManifest) return;
|
|
9337
6305
|
new AddScripts({
|
|
9338
6306
|
manifestPath: this.manifestPath,
|
|
9339
|
-
includeList: this.includeList || {}
|
|
6307
|
+
includeList: this.includeList || {},
|
|
6308
|
+
browser: this.browser
|
|
9340
6309
|
}).apply(compiler);
|
|
9341
6310
|
new TraceRuntimeLoadedFiles({
|
|
9342
6311
|
manifestPath: this.manifestPath
|
|
@@ -9350,16 +6319,6 @@ class ScriptsPlugin {
|
|
|
9350
6319
|
}).apply(compiler);
|
|
9351
6320
|
if ('production' === compiler.options.mode) new AddPublicPathRuntimeModule().apply(compiler);
|
|
9352
6321
|
new ValidateContentScriptSyntax().apply(compiler);
|
|
9353
|
-
if ('production' !== compiler.options.mode && 'true' !== process.env.EXTENSION_NO_RELOAD) {
|
|
9354
|
-
new StripContentScriptDevServerRuntime().apply(compiler);
|
|
9355
|
-
new SetupReloadStrategy({
|
|
9356
|
-
manifestPath: this.manifestPath,
|
|
9357
|
-
browser: this.browser
|
|
9358
|
-
}).apply(compiler);
|
|
9359
|
-
new InjectScriptsReplayShim().apply(compiler);
|
|
9360
|
-
new InjectBridgeProducer().apply(compiler);
|
|
9361
|
-
new InjectBridgeRelay().apply(compiler);
|
|
9362
|
-
}
|
|
9363
6322
|
}
|
|
9364
6323
|
}
|
|
9365
6324
|
function manifestNotFoundMessageOnly(absPath) {
|
|
@@ -9611,7 +6570,7 @@ class LocalesPlugin {
|
|
|
9611
6570
|
compiler.hooks.thisCompilation.tap('locales:module', (compilation)=>{
|
|
9612
6571
|
compilation.hooks.processAssets.tap({
|
|
9613
6572
|
name: 'locales:module',
|
|
9614
|
-
stage:
|
|
6573
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
9615
6574
|
}, ()=>{
|
|
9616
6575
|
if (!__rspack_external_fs.existsSync(this.manifestPath)) {
|
|
9617
6576
|
const ErrorConstructor = compiler?.rspack?.WebpackError || Error;
|
|
@@ -9687,7 +6646,7 @@ function validateJsonAsset(compilation, feature, filePath, buf) {
|
|
|
9687
6646
|
try {
|
|
9688
6647
|
parsed = JSON.parse(stripBom(buf.toString('utf-8')));
|
|
9689
6648
|
} catch (e) {
|
|
9690
|
-
const err = new
|
|
6649
|
+
const err = new WebpackError(invalidJsonSyntax(feature, filePath, String(e?.message || e)));
|
|
9691
6650
|
err.file = filePath;
|
|
9692
6651
|
err.name = 'JSONInvalidSyntax';
|
|
9693
6652
|
compilation.errors.push(err);
|
|
@@ -9695,7 +6654,7 @@ function validateJsonAsset(compilation, feature, filePath, buf) {
|
|
|
9695
6654
|
}
|
|
9696
6655
|
if (feature.startsWith('declarative_net_request')) {
|
|
9697
6656
|
if (!Array.isArray(parsed)) {
|
|
9698
|
-
const err = new
|
|
6657
|
+
const err = new WebpackError(invalidRulesetStructure(feature, filePath));
|
|
9699
6658
|
err.file = filePath;
|
|
9700
6659
|
err.name = 'DNRInvalidRuleset';
|
|
9701
6660
|
compilation.errors.push(err);
|
|
@@ -9703,7 +6662,7 @@ function validateJsonAsset(compilation, feature, filePath, buf) {
|
|
|
9703
6662
|
}
|
|
9704
6663
|
} else if ('storage.managed_schema' === feature) {
|
|
9705
6664
|
if (null === parsed || Array.isArray(parsed) || 'object' != typeof parsed) {
|
|
9706
|
-
const err = new
|
|
6665
|
+
const err = new WebpackError(invalidManagedSchemaStructure(feature, filePath));
|
|
9707
6666
|
err.file = filePath;
|
|
9708
6667
|
err.name = 'ManagedSchemaInvalid';
|
|
9709
6668
|
compilation.errors.push(err);
|
|
@@ -9745,7 +6704,7 @@ function processJsonAssets(compilation, manifestPath, includeList) {
|
|
|
9745
6704
|
const isPublicRoot = rawRef.startsWith('/') && !__rspack_external_path.isAbsolute(rawRef);
|
|
9746
6705
|
const outputRoot = compilation?.options?.output?.path || '';
|
|
9747
6706
|
const displayPath = isPublicRoot ? __rspack_external_path.join(outputRoot, rawRef.slice(1)) : abs;
|
|
9748
|
-
const notFound = new
|
|
6707
|
+
const notFound = new WebpackError(jsonMissingFile(feature, displayPath, {
|
|
9749
6708
|
publicRootHint: isPublicRoot
|
|
9750
6709
|
}));
|
|
9751
6710
|
notFound.name = 'JSONMissingFile';
|
|
@@ -9827,7 +6786,7 @@ class JsonPlugin {
|
|
|
9827
6786
|
compiler.hooks.thisCompilation.tap('json:module', (compilation)=>{
|
|
9828
6787
|
compilation.hooks.processAssets.tap({
|
|
9829
6788
|
name: 'json:module',
|
|
9830
|
-
stage:
|
|
6789
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
9831
6790
|
}, ()=>{
|
|
9832
6791
|
processJsonAssets(compilation, this.manifestPath, this.includeList || {});
|
|
9833
6792
|
trackJsonDependencies(compilation, this.manifestPath, this.includeList || {});
|
|
@@ -9887,14 +6846,6 @@ function normalizeIconIncludeKeys(icons) {
|
|
|
9887
6846
|
else out[key] = value;
|
|
9888
6847
|
return out;
|
|
9889
6848
|
}
|
|
9890
|
-
function emit_file_reportToCompilation(compilation, message, compiler, opts) {
|
|
9891
|
-
const ErrorConstructor = compiler?.rspack?.WebpackError || Error;
|
|
9892
|
-
const errObj = new ErrorConstructor(message);
|
|
9893
|
-
const arrKey = opts?.type === 'warning' ? 'warnings' : 'errors';
|
|
9894
|
-
if (opts?.file) errObj.file = opts.file;
|
|
9895
|
-
if (!compilation[arrKey]) compilation[arrKey] = [];
|
|
9896
|
-
compilation[arrKey].push(errObj);
|
|
9897
|
-
}
|
|
9898
6849
|
class EmitFile {
|
|
9899
6850
|
manifestPath;
|
|
9900
6851
|
includeList;
|
|
@@ -9906,7 +6857,7 @@ class EmitFile {
|
|
|
9906
6857
|
compiler.hooks.thisCompilation.tap('icons:emit-file', (compilation)=>{
|
|
9907
6858
|
compilation.hooks.processAssets.tap({
|
|
9908
6859
|
name: 'icons:emit-file',
|
|
9909
|
-
stage:
|
|
6860
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
9910
6861
|
}, ()=>{
|
|
9911
6862
|
if (compilation.errors.length > 0) return;
|
|
9912
6863
|
const iconFields = this.includeList || {};
|
|
@@ -9967,12 +6918,9 @@ class EmitFile {
|
|
|
9967
6918
|
const displayPath = !__rspack_external_path.isAbsolute(entry) && isPublicRoot ? __rspack_external_path.join(projectPath, 'public', entry.slice(1)) : __rspack_external_path.isAbsolute(entry) ? entry : __rspack_external_path.join(projectPath, entry);
|
|
9968
6919
|
const isDefaultIconFamily = ('action' === group || 'browser_action' === group || 'page_action' === group || 'sidebar_action' === group) && 'default_icon' === sub;
|
|
9969
6920
|
const severity = 'icons' === group || isDefaultIconFamily ? 'error' : 'warning';
|
|
9970
|
-
|
|
6921
|
+
reportToCompilation(compilation, compiler, iconsMissingFile(feature, displayPath, {
|
|
9971
6922
|
publicRootHint: isPublicRoot
|
|
9972
|
-
}),
|
|
9973
|
-
type: severity,
|
|
9974
|
-
file: 'manifest.json'
|
|
9975
|
-
});
|
|
6923
|
+
}), severity, 'manifest.json');
|
|
9976
6924
|
missingCount++;
|
|
9977
6925
|
continue;
|
|
9978
6926
|
}
|
|
@@ -10023,7 +6971,7 @@ class add_to_file_dependencies_AddToFileDependencies {
|
|
|
10023
6971
|
compiler.hooks.thisCompilation.tap('icons:add-to-file-dependencies', (compilation)=>{
|
|
10024
6972
|
compilation.hooks.processAssets.tap({
|
|
10025
6973
|
name: 'icons:add-to-file-dependencies',
|
|
10026
|
-
stage:
|
|
6974
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
10027
6975
|
}, ()=>{
|
|
10028
6976
|
if (compilation.errors?.length) return;
|
|
10029
6977
|
const iconFields = this.includeList || {};
|
|
@@ -10155,7 +7103,7 @@ function collectContentScriptEntryImports(compilation, includeList) {
|
|
|
10155
7103
|
const name = entryImportsEntries[i][0];
|
|
10156
7104
|
const files = entryImportsEntries[i][1];
|
|
10157
7105
|
const normalizedFiles = [];
|
|
10158
|
-
for(let j = 0; j < files.length; j++)normalizedFiles.push(
|
|
7106
|
+
for(let j = 0; j < files.length; j++)normalizedFiles.push(paths_unixify(files[j]));
|
|
10159
7107
|
entryImports[name] = normalizedFiles;
|
|
10160
7108
|
}
|
|
10161
7109
|
return entryImports;
|
|
@@ -10169,7 +7117,7 @@ class CollectContentEntryImports {
|
|
|
10169
7117
|
compiler.hooks.thisCompilation.tap('plugin-extension:feature-web-resources:collect-entry-imports', (compilation)=>{
|
|
10170
7118
|
compilation.hooks.processAssets.tap({
|
|
10171
7119
|
name: 'plugin-extension:feature-web-resources:collect-entry-imports',
|
|
10172
|
-
stage:
|
|
7120
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
10173
7121
|
}, ()=>{
|
|
10174
7122
|
const entryImports = collectContentScriptEntryImports(compilation, this.includeList);
|
|
10175
7123
|
const shared = getSharedFor(compilation);
|
|
@@ -10253,7 +7201,7 @@ class ManifestFieldsChangeDetector {
|
|
|
10253
7201
|
});
|
|
10254
7202
|
const scriptsMap = fields.scripts || {};
|
|
10255
7203
|
const scripts = flattenValues(scriptsMap);
|
|
10256
|
-
const bridgeScripts = AddContentScriptWrapper.getBridgeScripts(this.manifestPath);
|
|
7204
|
+
const bridgeScripts = AddContentScriptWrapper.getBridgeScripts(this.manifestPath, this.browser);
|
|
10257
7205
|
for (const val of Object.values(bridgeScripts))if (Array.isArray(val)) scripts.push(...val.filter(Boolean));
|
|
10258
7206
|
else if (val) scripts.push(val);
|
|
10259
7207
|
const html = fields.html || {};
|
|
@@ -10306,7 +7254,7 @@ class ManifestFieldsChangeDetector {
|
|
|
10306
7254
|
compiler.hooks.thisCompilation.tap('manifest:fields-change-detector', (compilation)=>{
|
|
10307
7255
|
compilation.hooks.processAssets.tap({
|
|
10308
7256
|
name: 'manifest:fields-change-detector',
|
|
10309
|
-
stage:
|
|
7257
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY
|
|
10310
7258
|
}, ()=>{
|
|
10311
7259
|
this.emitErrors(compilation);
|
|
10312
7260
|
this.pending = {};
|
|
@@ -10317,21 +7265,21 @@ class ManifestFieldsChangeDetector {
|
|
|
10317
7265
|
if (this.pending.scripts) {
|
|
10318
7266
|
const p = this.pending.scripts;
|
|
10319
7267
|
const msg = serverRestartRequiredFromManifestError(p.pathAfter || '', p.pathBefore || '');
|
|
10320
|
-
const err = new
|
|
7268
|
+
const err = new WebpackError(msg);
|
|
10321
7269
|
err.file = 'manifest.json';
|
|
10322
7270
|
compilation.errors.push(err);
|
|
10323
7271
|
}
|
|
10324
7272
|
if (this.pending.html) {
|
|
10325
7273
|
const p = this.pending.html;
|
|
10326
7274
|
const msg = manifestHtmlEntrypointChange(p.manifestField, p.pathAfter, p.pathBefore);
|
|
10327
|
-
const err = new
|
|
7275
|
+
const err = new WebpackError(msg);
|
|
10328
7276
|
err.file = 'manifest.json';
|
|
10329
7277
|
compilation.errors.push(err);
|
|
10330
7278
|
}
|
|
10331
7279
|
if (this.pending.icons) {
|
|
10332
7280
|
const p = this.pending.icons;
|
|
10333
7281
|
const msg = manifestIconsEntrypointChange(p.manifestField, p.pathAfter, p.pathBefore);
|
|
10334
|
-
const err = new
|
|
7282
|
+
const err = new WebpackError(msg);
|
|
10335
7283
|
err.file = 'manifest.json';
|
|
10336
7284
|
compilation.errors.push(err);
|
|
10337
7285
|
}
|
|
@@ -10343,13 +7291,13 @@ class ManifestFieldsChangeDetector {
|
|
|
10343
7291
|
lines.push('');
|
|
10344
7292
|
if (p.pathBefore) lines.push(`PATH BEFORE ${p.pathBefore}`);
|
|
10345
7293
|
if (p.pathAfter) lines.push(`PATH AFTER ${p.pathAfter}`);
|
|
10346
|
-
const err = new
|
|
7294
|
+
const err = new WebpackError(lines.join('\n'));
|
|
10347
7295
|
err.file = 'manifest.json';
|
|
10348
7296
|
compilation.errors.push(err);
|
|
10349
7297
|
}
|
|
10350
7298
|
}
|
|
10351
7299
|
}
|
|
10352
|
-
class
|
|
7300
|
+
class WebExtensionPlugin {
|
|
10353
7301
|
static name = 'plugin-extension';
|
|
10354
7302
|
manifestPath;
|
|
10355
7303
|
browser;
|
|
@@ -10678,7 +7626,7 @@ function webpackConfig(projectStructure, devOptions) {
|
|
|
10678
7626
|
} catch (error) {
|
|
10679
7627
|
throw new Error(manifestInvalidJson(manifestPath, error));
|
|
10680
7628
|
}
|
|
10681
|
-
const manifest =
|
|
7629
|
+
const manifest = manifest_utils_filterKeysForThisBrowser(rawManifest, devOptions.browser);
|
|
10682
7630
|
const primaryExtensionOutputDir = asAbsolute(__rspack_external_path.isAbsolute(devOptions.output.path) ? devOptions.output.path : __rspack_external_path.resolve(packageJsonDir, devOptions.output.path));
|
|
10683
7631
|
const companionUnpackedExtensionDirs = resolveCompanionExtensionDirs({
|
|
10684
7632
|
projectRoot: packageJsonDir,
|
|
@@ -10733,7 +7681,11 @@ function webpackConfig(projectStructure, devOptions) {
|
|
|
10733
7681
|
browser: devOptions.browser,
|
|
10734
7682
|
polyfill: devOptions.polyfill
|
|
10735
7683
|
}),
|
|
10736
|
-
new
|
|
7684
|
+
new WebExtensionPlugin({
|
|
7685
|
+
manifestPath,
|
|
7686
|
+
browser: devOptions.browser
|
|
7687
|
+
}),
|
|
7688
|
+
new ReloadPlugin({
|
|
10737
7689
|
manifestPath,
|
|
10738
7690
|
browser: devOptions.browser
|
|
10739
7691
|
}),
|
|
@@ -10799,6 +7751,7 @@ function webpackConfig(projectStructure, devOptions) {
|
|
|
10799
7751
|
packageJsonDir,
|
|
10800
7752
|
browser: devOptions.browser,
|
|
10801
7753
|
mode: devOptions.mode,
|
|
7754
|
+
command: devOptions.metadataCommand,
|
|
10802
7755
|
outputPath: primaryExtensionOutputDir,
|
|
10803
7756
|
manifestPath,
|
|
10804
7757
|
port: devOptions.port,
|