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
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,5 +182,5 @@ Anyone is welcome to submit a blog post on <https://wxt.dev/blog>!
182
182
> [!NOTE]
183
183
> Before starting on a blog post, please message Aaron on Discord or start a discussion on GitHub to get permission to write about a topic, but most topics are welcome: Major version updates, tutorials, etc.
184
184
185
-
-**English only**: Blog posts should be written in English. Unfortunately, our maintainers doesn't have the bandwidth right now to translate our docs, let alone blog posts. Sorry 😓
185
+
-**English only**: Blog posts should be written in English. Unfortunately, our maintainers don't have the bandwidth right now to translate our docs, let alone blog posts. Sorry 😓
186
186
-**AI**: Please only use AI to translate or proof-read your blog post. Don't generate the whole thing... We don't want to publish that.
Copy file name to clipboardExpand all lines: docs/guide/essentials/config/entrypoint-loaders.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ WXT does several pre-processing steps to try and prevent errors during this proc
10
10
2. Use `@webext-core/fake-browser` to create a fake version of the `chrome` and `browser` globals expected by extensions.
11
11
3. Pre-process the JS/TS code, stripping out the `main` function then tree-shaking unused code from the file
12
12
13
-
However, this process is not perfect. It doesn't setup all the globals found in the browser and the APIs may behave differently. As such, **_you should avoid using browser or extension APIs outside the `main` function of your entrypoints!_**
13
+
However, this process is not perfect. It doesn't setup all the globals found in the browser and the APIs may behave differently. As such, **_you should avoid using browser or extension APIs outside the `main` function of your entrypoints!_** See [Entrypoint Limitations](/guide/essentials/extension-apis#entrypoint-limitations) for more details.
14
14
15
15
:::tip
16
16
If you're running into errors while importing entrypoints, run `wxt prepare --debug` to see more details about this process. When debugging, WXT will print out the pre-processed code to help you identify issues.
Copy file name to clipboardExpand all lines: docs/guide/essentials/extension-apis.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,3 +75,63 @@ Alternatively, if you're trying to use similar APIs under different names (to su
75
75
//
76
76
});
77
77
```
78
+
79
+
## Entrypoint Limitations
80
+
81
+
Because WXT imports your entrypoint files into a NodeJS, non-extension environment, the `chrome`/`browser` variables provided to extensions by the browser **will not be available**.
82
+
83
+
To prevent some basic errors, WXT polyfills these globals with the same in-memory, fake implementation it uses for testing: [`@webext-core/fake-browser`](https://webext-core.aklinker1.io/fake-browser/installation/). However, not all the APIs have been implemented.
84
+
85
+
So it is extremely important to NEVER use `browser.*` extension APIs outside the main function of any JS/TS entrypoints (background, content scripts, and unlisted scripts). If you do, you'll see an error like this:
86
+
87
+
```plaintext
88
+
✖ Command failed after 440 ms
89
+
90
+
ERROR Browser.action.onClicked.addListener not implemented.
91
+
```
92
+
93
+
The fix is simple, just move your API usage into the entrypoint's main function:
94
+
95
+
:::code-group
96
+
97
+
```ts [background.ts]
98
+
browser.action.onClicked.addListener(() => {
99
+
/* ... */
100
+
}); // [!code --]
101
+
102
+
exportdefaultdefineBackground(() => {
103
+
browser.action.onClicked.addListener(() => {
104
+
/* ... */
105
+
}); // [!code ++]
106
+
});
107
+
```
108
+
109
+
```ts [content.ts]
110
+
browser.runtime.onMessage.addListener(() => {
111
+
/* ... */
112
+
}); // [!code --]
113
+
114
+
exportdefaultdefineContentScript({
115
+
main() {
116
+
browser.runtime.onMessage.addListener(() => {
117
+
/* ... */
118
+
}); // [!code ++]
119
+
},
120
+
});
121
+
```
122
+
123
+
```ts [unlisted.ts]
124
+
browser.runtime.onMessage.addListener(() => {
125
+
/* ... */
126
+
}); // [!code --]
127
+
128
+
exportdefaultdefineUnlistedScript(() => {
129
+
browser.runtime.onMessage.addListener(() => {
130
+
/* ... */
131
+
}); // [!code ++]
132
+
});
133
+
```
134
+
135
+
:::
136
+
137
+
Read [Entrypoint Loaders](/guide/essentials/config/entrypoint-loaders) for more technical details about this limitation.
0 commit comments