wxt: Clarify code outside of `defineBackground` as related error
Feature Request
Suppose I have
// code
export default defineBackground(() => {
// code
});
it will throw an error that doesn’t clarify that I must not have code outside of defineBackground
Is your feature request related to a bug?
Not related to a particular bug, though this issue could be classified as a bug
What are the alternatives?
Knowledge of the situation according to the documentation, nothing else
Additional context
Having this issue clarified will benefit both WXT devs who are new to the framework and devs like me, who explore using an agentic AI to code the extension (e.g. OpenHands) Such an agent can often use errors to modify the code so that the error disappears
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 18 (14 by maintainers)
I polyfill the node environment with a
chromeandbrowserglobal from@webext-core/fake-browser.Ideally all APIs would have an in-memory implementation, for testing, but I haven’t implemented all of them.
So that’s why some APIs don’t throw an error, like storage, and some do, like the action APIs.
I don’t have much idea regarding this, @aklinker1 has much more idea regarding this. I’m assuming all the
chromeAPIs are monkey patched tobrowserLet me clone and check it myself.
Can you try separating the code in different files and importing them in the root file. Create
backgroundfolder entrypoint. Something like this?@avi12 I checked for this code as well. It is working for me.
Try