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
docs: document PerBrowser options for entrypoints (#2304)
Adds a 'Per-Browser Options' section to target-different-browsers.md
explaining PerBrowserOption<T> / PerBrowserMap<T> usage on entrypoint
config fields like matches, runAt, and defaultArea.
Closes#2304.
Copy file name to clipboardExpand all lines: docs/guide/essentials/target-different-browsers.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,3 +78,52 @@ Here are some examples:
78
78
```
79
79
80
80
Alternatively, you can use the [`filterEntrypoints` config](/api/reference/wxt/interfaces/InlineConfig#filterentrypoints) to list all the entrypoints you want to build.
81
+
82
+
## Per-Browser Options
83
+
84
+
Many entrypoint config options accept either a single value (applied to every browser build) or a per-browser map (a different value per build target). These are typed as `PerBrowserOption<T>` in the WXT source:
This applies to fields like `matches`, `runAt`, `matchAboutBlank`, `excludeMatches`, `includeGlobs`, `excludeGlobs`, `allFrames`, `matchOriginAsFallback`, `cssInjectionMode`, `registration`, `defaultTitle`, `defaultArea`, `persistent`, and several others on `BackgroundEntrypointOptions`, `BaseContentScriptEntrypointOptions`, `PopupEntrypointOptions`, `OptionsEntrypointOptions`, and `SidepanelEntrypointOptions`.
92
+
93
+
### Apply the same value to every build
94
+
95
+
Pass the value directly:
96
+
97
+
```ts
98
+
exportdefaultdefineContentScript({
99
+
matches: ['*://*.example.com/*'],
100
+
runAt: 'document_idle',
101
+
// ...
102
+
});
103
+
```
104
+
105
+
### Use a different value per browser
106
+
107
+
Pass a `PerBrowserMap` keyed by the [build target](/guide/essentials/target-different-browsers#target-a-browser) (`chrome`, `firefox`, `safari`, `edge`, `opera`, `custom`, or a custom target from `webExt.config.browserTargets`):
108
+
109
+
```ts
110
+
exportdefaultdefineContentScript({
111
+
matches: {
112
+
chrome: ['*://*.example.com/*'],
113
+
firefox: ['*://*.example.org/*'],
114
+
},
115
+
runAt: {
116
+
chrome: 'document_start',
117
+
firefox: 'document_idle',
118
+
},
119
+
// ...
120
+
});
121
+
```
122
+
123
+
If a build target is omitted from the map, that build inherits the build's default for that field (typically the same as if you didn't set the option at all). For example, the `safari` build above would fall back to WXT's default `runAt`.
124
+
125
+
:::tip Mixed forms
126
+
You can mix both styles inside the same entrypoint — some fields can be plain values and others maps — as long as each individual field is either a `T` or a `PerBrowserMap<T>`.
127
+
:::
128
+
129
+
For the manifest-level `default_icon` (a nested `Record<resolution, iconPath>` that doesn't fit the per-key shape), see [Manifest config](/guide/essentials/config/manifest) for the manual per-browser workaround.
0 commit comments