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
+86-45
Original file line number
Diff line number
Diff line change
@@ -26,13 +26,16 @@ Read through all the changes once before making any code changes.
26
26
27
27
### `webextension-polyfill` Removed
28
28
29
-
WXT no longer uses the `webextension-polyfill`!
29
+
WXT's `browser` no longer uses the `webextension-polyfill`!
30
30
31
-
Why? The polyfill doesn't add any value anymore. WXT's new `browser` supports the promise-based APIs on all browsers/manifest versions and all shared APIs behave the same way.
31
+
:::details Why?
32
+
See https://github.com/wxt-dev/wxt/issues/784
33
+
:::
32
34
33
35
To upgrade, you have two options:
34
36
35
37
1.**Stop using the polyfill** - No changes necessary, though you may want to do some manual testing to make sure everything continues to work. None of the early testers of this feature reported any runtime issues once they stopped using the polyfill.
38
+
- If you're already using `extensionApi: "chrome"`, then you don't need to test anything! You're already using the same `browser` object v0.20 provides by default.
36
39
2.**Continue using the polyfill** - If you want to keep using the polyfill, you can! One less thing to worry about during this upgrade.
37
40
- Install `webextension-polyfill` and WXT's [new polyfill module](https://www.npmjs.com/package/@wxt-dev/webextension-polyfill):
38
41
```sh
@@ -45,17 +48,27 @@ To upgrade, you have two options:
45
48
});
46
49
```
47
50
48
-
Regardless of your choice, the `extensionApi` config has been removed. Remove it from your `wxt.config.ts` file if present:
51
+
The new `browser` object (and types) is backed by WXT's new package: [`@wxt-dev/browser`](https://www.npmjs.com/package/@wxt-dev/browser). This package continues WXT's mission of providing useful packages forthe whole community. Just like [`@wxt-dev/storage`](https://www.npmjs.com/package/@wxt-dev/storage), [`@wxt-dev/i18n`](https://www.npmjs.com/package/@wxt-dev/i18n), [`@wxt-dev/analytics`](https://www.npmjs.com/package/@wxt-dev/analytics), it is designed to be easy to usein any web extension project, not just those using WXT, and provides a consistent API across all browsers and manifest versions.
52
+
53
+
### `extensionApi` Config Removed
54
+
55
+
The `extensionApi` config has been removed. Before, this config provided a way to opt into using the new `browser` object prior to v0.20.0.
56
+
57
+
Remove it from your `wxt.config.ts` file if present:
49
58
50
59
```ts [wxt.config.ts]
51
60
export default defineConfig({
52
61
extensionApi: 'chrome', // [!code --]
53
62
});
54
63
```
55
64
56
-
Additionally, how you consume extension API types have changed. `wxt/browser` now uses types based on `@types/chrome` instead of `@types/webextension-polyfill`.
65
+
### Extension API Type Changes
66
+
67
+
With the new `browser` introduced in v0.20, how you access types has changed. WXT now provides types based on `@types/chrome` instead of `@types/webextension-polyfill`.
57
68
58
-
Types are now accessed off the `Browser` namespace:
69
+
These types are more up-to-date with MV3 APIs, contain less bugs, are better organized, and don't have any auto-generated names.
70
+
71
+
To access types, use the new `Browser` namespace from `wxt/browser`:
59
72
60
73
<!-- prettier-ignore -->
61
74
```ts
@@ -68,23 +81,17 @@ function getMessageSenderUrl(sender: Browser.runtime.MessageSender): string { //
68
81
}
69
82
```
70
83
71
-
These new types contain up-to-date MV3 APIs, contain less bugs, and don't have any auto-generated names.
84
+
> If you use auto-imports, `Browser` will be available without manually importing it.
85
+
86
+
Not all type names will be the same as what `@types/webextension-polyfill` provides. You'll have to find the new type names by looking at the types of the `browser.*` API's you use.
72
87
73
88
### `public/` and `modules/` Directories Moved
74
89
75
-
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, not the src directory.
90
+
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**, not the src directory.
76
91
77
92
- If you follow the default folder structure, you don't need to make any changes.
78
93
- If you set a custom `srcDir`, you have two options:
79
-
1. Keep the folders in the same place and update your project config:
80
-
```ts [wxt.config.ts]
81
-
export default defineConfig({
82
-
srcDir: 'src',
83
-
publicDir: 'src/public', // [!code ++]
84
-
modulesDir: 'src/modules', // [!code ++]
85
-
});
86
-
```
87
-
2. Move the your `public/` and `modules/` directories to the project root:
94
+
1. Move the your `public/` and `modules/` directories to the project root:
88
95
```diff
89
96
<root>/
90
97
+ modules/
@@ -97,12 +104,32 @@ The default location for the `public/` and `modules/` directories have changed t
97
104
utils/
98
105
wxt.config.ts
99
106
```
107
+
2. Keep the folders in the same place and update your project config:
108
+
```ts [wxt.config.ts]
109
+
export default defineConfig({
110
+
srcDir: 'src',
111
+
publicDir: 'src/public', // [!code ++]
112
+
modulesDir: 'src/modules', // [!code ++]
113
+
});
114
+
```
115
+
116
+
### Import Path Changes and `#imports`
117
+
118
+
The APIs exported by `wxt/sandbox`, `wxt/client`, or `wxt/storage` have moved to individual exports under the `wxt/utils/*` path.
119
+
120
+
:::details Why?
121
+
As WXT grows and more utilities are added, any helper with side-effects will not be tree-shaken out of your final bundle.
100
122
101
-
### Import Path Changes
123
+
This can cause problems because not every API used by these side-effects is available in every type of entrypoint. Some APIs can only be used in the background, sandboxed pages can't use any extension API, etc. This was leading to JS throwing errors in the top-level scope, preventing your code from running.
102
124
103
-
The APIs exported by `wxt/sandbox`, `wxt/client`, or `wxt/storage` have moved to `wxt/utils/*`.
125
+
Splitting each util into it's own module solves this problem, making sure you're only importing APIs and side-effects into entrypoints they can run in.
126
+
:::
127
+
128
+
Refer to the updated [API Reference](/api/reference/) to see the list of new import paths.
129
+
130
+
However, you don't need to memorize or learn the new import paths! v0.20 introduces a new virtual module, `#imports`, that abstracts all this away from developers. See the [blog post](/blog/2024-12-06-using-imports-module) for more details about how this module works.
104
131
105
-
To upgrade, replace these imports with the new `#imports` module:
132
+
So to upgrade, just replace any imports from `wxt/storage`, `wxt/client`, and `wxt/sandbox` with an import to the new `#imports` module:
106
133
107
134
```ts
108
135
import { storage } from 'wxt/storage'; // [!code --]
You can combine the imports into a single import statement, but it's easier to just find/replace each statement.
117
144
145
+
```ts
146
+
import { storage } from 'wxt/storage'; // [!code --]
147
+
import { defineContentScript } from 'wxt/sandbox'; // [!code --]
148
+
import { ContentScriptContext, useAppConfig } from 'wxt/client'; // [!code --]
149
+
import {
150
+
// [!code ++]
151
+
storage, // [!code ++]
152
+
defineContentScript, // [!code ++]
153
+
ContentScriptContext, // [!code ++]
154
+
useAppConfig, // [!code ++]
155
+
} from '#imports'; // [!code ++]
156
+
```
157
+
118
158
:::tip
119
159
Before types will work, you'll need to run `wxt prepare` after installing v0.20 to generate the new TypeScript declarations.
120
160
:::
121
161
122
-
Read more about the new `#imports` module in the [blog post](/blog/2024-12-06-using-imports-module).
123
-
124
162
### `createShadowRootUi` CSS Changes
125
163
126
164
WXT now resets styles inherited from the webpage (`visibility`, `color`, `font-size`, etc.) by setting `all: initial` inside the shadow root.
127
165
166
+
:::warning
167
+
This doesn't effect `rem` units. You should continue using `postcss-rem-to-px` or an equivalent library if the webpage sets the HTML element's `font-size`.
168
+
:::
169
+
128
170
If you use `createShadowRootUi`:
129
171
130
-
1. Double check that your UI looks the same as before.
131
-
2. If you have any manual CSS resets to these styles, you can remove them. For example:
172
+
1. Remove any manual CSS overrides that reset the style of specific websites. For example:
132
173
133
174
<!-- prettier-ignore -->
134
175
```css [entrypoints/reddit.content/style.css]
@@ -138,9 +179,7 @@ If you use `createShadowRootUi`:
138
179
} /* [!code --] */
139
180
```
140
181
141
-
:::warning
142
-
This doesn't effect `rem` units. You should continue using `postcss-rem-to-px` or an equivalent library if the webpage sets the HTML element's `font-size`.
143
-
:::
182
+
2. Double check that your UI looks the same as before.
144
183
145
184
If you run into problems with the new behavior, you can disable it and continue using your current CSS:
146
185
@@ -159,7 +198,7 @@ The default value for the [`outDirTemplate`](/api/reference/wxt/interfaces/Inlin
159
198
- `--mode development`→`.output/chrome-mv3-dev`: Dev mode now has a `-dev` suffix so it doesn't overwrite production builds
160
199
- `--mode custom` → `.output/chrome-mv3-custom`: Other custom modes end with a `-[mode]` suffix
161
200
162
-
To use the old behavior, writing all output to the same directory, set`outDirTemplate` option:
201
+
To use the old behavior, writing all output to the same directory, set the `outDirTemplate` option:
If you've previously loaded the extension into your browser manually for development, you'll need to uninstall and re-install it from the new dev output directory.
172
211
:::
173
212
174
-
### `runner` APIs Renamed
213
+
### Deprecated APIs Removed
214
+
215
+
- `entrypointLoader` option: WXT now uses `vite-node` for importing entrypoints during the build process.
216
+
> This was deprecated in v0.19.0, see the [v0.19 section](#v0-18-5-rarr-v0-19-0) for migration steps.
217
+
- `transformManifest` option: Use the `build:manifestGenerated` hook to transform the manifest instead:
To improve consistency with the `web-ext.config.ts` filename, the "runner" API and config options have been renamed. You can continue using the old names, but they have been deprecated and will be removed in a future version:
177
235
@@ -195,23 +253,6 @@ To improve consistency with the `web-ext.config.ts` filename, the "runner" API a
195
253
import type { WebExtConfig } from 'wxt'; // [!code ++]
196
254
```
197
255
198
-
### Deprecated APIs Removed
199
-
200
-
- `entrypointLoader` option: WXT now uses `vite-node`for importing entrypoints during the build process.
201
-
> This was deprecated in v0.19.0, see the [v0.19 section](#v0-18-5-rarr-v0-19-0) for migration steps.
202
-
- `transformManifest` option: Use the `build:manifestGenerated` hook to transform the manifest instead:
0 commit comments