-
-
Notifications
You must be signed in to change notification settings - Fork 301
Clarify code outside of defineBackground
as related error
#1569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@avi12 Can you show me an example I'm not able to reproduce it. Is it something like this? Cause this is working just fine. const foo = () => {
console.log(browser.runtime.getURL("/"));
};
export default defineBackground(() => {
console.log("Hello background!", { id: browser.runtime.id });
console.log(foo());
}); |
Try const foo = "bar";
export default defineBackground(() => {
console.log(foo);
}); |
@avi12 I checked for this code as well. It is working for me. |
@nishu-murmu According to that logic, this code should be perfectly valid: console.log("background");
export default defineBackground(() => {}); |
Suppose I want to do browser.runtime.onMessage.addListener(() => {});
export default defineBackground(() => {}); the WXT compiler will yell at me |
Yeah, this is perfectly valid. |
To be fair, the project I linked is a puppet project that I let AI code it |
Let me clone and check it myself. |
@avi12 I checked the code. |
Another question is why do all of the |
I don't have much idea regarding this, @aklinker1 has much more idea regarding this. |
I polyfill the node environment with a 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. |
Feature Request
Suppose I have
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
The text was updated successfully, but these errors were encountered: