-
- Notifications
You must be signed in to change notification settings - Fork 412
Description
Describe the bug
Main world doesn't support browser APIs, but defineContentScript imports the polyfill because of ContentScriptContext.
Because these content scripts need sandboxed and can't have a ctx, WXT should export a separate function, defineMainWorldContentScript, from wxt/sandbox module, which doesn't include the webextension-polyfill, and thus avoids the error.
Alternatively, we could try and define globals inside content-script-entrypoint.ts and tree-shake the polyfill out. Not sure if that's possible though.
Or a third option, if the content script runs in the main world, alias webextension-polyfill to a noop module, similar to how we alias it for experimental.includeWebextensionPolyfill.
To Reproduce
pnpm devThen go to https://google.com and open the console.
Expected behavior
Main world content scripts shouldn't import the polyfill and the script shouldn't crash.
Environment
System: OS: macOS 13.4.1 CPU: (8) arm64 Apple M1 Pro Memory: 3.02 GB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.16.1 - ~/.asdf/installs/nodejs/18.16.1/bin/node Yarn: 1.22.19 - ~/.asdf/installs/nodejs/18.16.1/bin/yarn npm: 9.5.1 - ~/.asdf/plugins/nodejs/shims/npm pnpm: 8.9.0 - ~/.asdf/installs/nodejs/18.16.1/bin/pnpm Browsers: Chrome: 120.0.6099.71 Safari: 16.5.2 npmPackages: wxt: ^0.11.0 => 0.11.2 Additional context
CC @AndrewWalsh