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: docs/guide/resources/upgrading.md
+19-5Lines changed: 19 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,12 +31,11 @@ WXT no longer uses the `webextension-polyfill` internally and `wxt/browser` uses
31
31
To upgrade, you have two options:
32
32
33
33
1.**Stop using the polyfill**
34
-
-No changes required, this is the default behavior of v0.20. Your extension will likely continue to work, but do some manual testing to confirm.
34
+
-Replace any manual imports from `wxt/browser/chrome` with `wxt/browser`
35
35
2.**Continue using the polyfill**
36
-
- Install the polyfill, types (if you use typescript), and WXT's [new polyfill module](https://www.npmjs.com/package/@wxt-dev/webextension-polyfill):
36
+
- Install the polyfill and WXT's [new polyfill module](https://www.npmjs.com/package/@wxt-dev/webextension-polyfill):
37
37
```sh
38
-
pnpm i webextension-polyfill
39
-
pnpm i -D @types/webextension-polyfill @wxt-dev/webextension-polyfill
38
+
pnpm i webextension-polyfill @wxt-dev/webextension-polyfill
40
39
```
41
40
- Add the WXT module to your config:
42
41
```ts
@@ -46,7 +45,7 @@ To upgrade, you have two options:
46
45
});
47
46
```
48
47
49
-
Additionally, the `extensionApi` config has been removed. Remove it from your `wxt.config.ts` file if present:
48
+
Regardless of your choice, the `extensionApi` config has been removed. Remove it from your `wxt.config.ts` file if present:
50
49
51
50
```ts
52
51
// wxt.config.ts
@@ -55,6 +54,21 @@ export default defineConfig({
55
54
});
56
55
```
57
56
57
+
Additionally, extension API types have changed. `wxt/browser` now uses types from `@types/chrome` instead of `@types/webextension-polyfill`. You will have to migrate any type imports to use `@types/chrome`'s namespace approach:
58
+
59
+
<!-- prettier-ignore -->
60
+
```ts
61
+
import type { Runtime } from 'wxt/browser'; // [!code --]
62
+
import { browser } from 'wxt/browser'; // [!code ++]
63
+
64
+
function getMessageSenderUrl(sender: Runtime.MessageSender): string { // [!code --]
65
+
function getMessageSenderUrl(sender: browser.runtime.MessageSender): string { // [!code ++]
66
+
// ...
67
+
}
68
+
```
69
+
70
+
`@types/chrome` are more up-to-date, contain less bugs, and don't have any auto-generated names. So even if you continue to use the polyfill, you will need to update your types to use these types.
71
+
58
72
### `public/` and `modules/` Directories Moved
59
73
60
74
The default location for the `public/` and `modules/` directories have changed to better align with standards set by other frameworks (Nuxt, Next, Astro, etc). Now, each path is relative to the project's root directory.
Configures `wxt/browser` to import `browser` from [`webextension-polyfill`](https://github.com/mozilla/webextension-polyfill) instead of using the regular `chrome`/`browser` globals WXT normally provides.
4
+
5
+
## Usage
6
+
7
+
```sh
8
+
pnpm i @wxt-dev/webextension-polyfill webextension-polyfill
0 commit comments