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
{{ message }}
Repository navigation
defineContentScript doesn't work with world: "MAIN" #282
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.
Activity
aklinker1 commentedon Dec 13, 2023
Between the two options, there are pros and cons.
createMainWorldContentScriptworld: "MAIN"I think I'll go with the second approach. I don't want to create variants on variants of the different helper functions (also see #273).