Skip to content

Commit 233e1f1

Browse files
committed
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.
1 parent 7905cb3 commit 233e1f1

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

docs/guide/essentials/target-different-browsers.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,52 @@ Here are some examples:
7878
```
7979

8080
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:
85+
86+
```ts
87+
export type PerBrowserOption<T> = T | PerBrowserMap<T>;
88+
export type PerBrowserMap<T> = { [browser: TargetBrowser]: T };
89+
```
90+
91+
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+
export default defineContentScript({
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+
export default defineContentScript({
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

Comments
 (0)