You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
aklinker1
added
pending-triage
Someone (usually a maintainer) needs to look into this to see if it's a bug
bug
Something isn't working
and removed
pending-triage
Someone (usually a maintainer) needs to look into this to see if it's a bug
labels
Dec 13, 2023
Describe the bug
Main world doesn't support browser APIs, but
defineContentScript
imports the polyfill because ofContentScriptContext
.Because these content scripts need sandboxed and can't have a
ctx
, WXT should export a separate function,defineMainWorldContentScript
, fromwxt/sandbox
module, which doesn't include thewebextension-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 forexperimental.includeWebextensionPolyfill
.To Reproduce
Archive.zip
Then 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
Additional context
CC @AndrewWalsh
The text was updated successfully, but these errors were encountered: