Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion packages/wxt/src/core/utils/__tests__/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ describe('Manifest Utils', () => {
},
);

it('should allow converting action to page_action for Firefox MV3', async () => {
const popup = popupEntrypoint('page_action');
const buildOutput = fakeBuildOutput();
setFakeWxt({
config: {
manifestVersion: 3,
outDir,
browser: 'firefox',
},
});
const expected = {
default_icon: popup.options.defaultIcon,
default_title: popup.options.defaultTitle,
default_popup: 'popup.html',
};

const { manifest: actual } = await generateManifest(
[popup],
buildOutput,
);

expect(actual.page_action).toEqual(expected);
});

it('should include default_area for Firefox in mv3', async () => {
const popup = fakePopupEntrypoint({
options: {
Expand Down Expand Up @@ -1464,7 +1488,11 @@ describe('Manifest Utils', () => {
['chrome', 2, { ...mv2Manifest, ...hostPermissionsManifest }],
['safari', 2, { ...mv2Manifest, ...hostPermissionsManifest }],
['edge', 2, { ...mv2Manifest, ...hostPermissionsManifest }],
['firefox', 3, { ...mv3Manifest, ...hostPermissionsManifest }],
[
'firefox',
3,
{ ...mv3Manifest, ...hostPermissionsManifest, page_action: {} },
],
['chrome', 3, { ...mv3Manifest, ...hostPermissionsManifest }],
['safari', 3, { ...mv3Manifest, ...hostPermissionsManifest }],
['edge', 3, { ...mv3Manifest, ...hostPermissionsManifest }],
Expand Down
31 changes: 16 additions & 15 deletions packages/wxt/src/core/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,19 @@ function addEntrypoints(
if (popup.options.themeIcons)
// @ts-expect-error: Not typed by @wxt-dev/browser, but supported by Firefox
options.theme_icons = popup.options.themeIcons;
if (manifest.manifest_version === 3) {
manifest.action = {
...manifest.action,
...options,
default_popup,
};
} else {
const key = popup.options.mv2Key ?? 'browser_action';
manifest[key] = {
...manifest[key],
...options,
default_popup,
};
}

const actionKey =
manifest.manifest_version === 2
? (popup.options.mv2Key ?? 'browser_action')
: wxt.config.browser === 'firefox'
? (popup.options.mv2Key ?? 'action')
: 'action';

manifest[actionKey] = {
...manifest[actionKey],
...options,
default_popup,
};
}

if (devtools) {
Expand Down Expand Up @@ -699,6 +698,8 @@ function stripKeys(manifest: Browser.runtime.Manifest): void {
keysToRemove.push(...firefoxMv3OnlyKeys);
} else {
keysToRemove.push(...mv2OnlyKeys);
if (wxt.config.browser !== 'firefox')
keysToRemove.push(...chromeMv2OnlyKeys);
}

keysToRemove.forEach((key) => {
Expand All @@ -707,7 +708,6 @@ function stripKeys(manifest: Browser.runtime.Manifest): void {
}

const mv2OnlyKeys = [
'page_action',
'browser_action',
'automation',
'content_capabilities',
Expand All @@ -732,6 +732,7 @@ const mv3OnlyKeys = [
'optional_host_permissions',
'side_panel',
];
const chromeMv2OnlyKeys = ['page_action'];
const firefoxMv3OnlyKeys = ['host_permissions'];

const DEFAULT_MV3_EXTENSION_PAGES_CSP =
Expand Down
8 changes: 7 additions & 1 deletion packages/wxt/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,13 @@ export interface ThemeIcon {
}

export interface PopupEntrypointOptions extends BaseEntrypointOptions {
/** Defaults to "browser_action" to be equivalent to MV3's "action" key */
/**
* Defaults to "browser_action" to be equivalent to MV3's "action" key.
*
* This option name is bad - it is also respected for Firefox MV3 (though
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it then not make sense to add a better alias, say type? It's pretty confusing to have something called mv2 which then still applies to mv3

Copy link
Copy Markdown
Member

@aklinker1 aklinker1 Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered deprecating this property and creating a new field called actionType, yes. However, for modules that modify this field, they'll only modify one of the two properties and they'll be out-of-sync... So a simple second field wouldn't be enough.

I shouldn't be lazy though, I should use getter and setters as a workaround. I'll give that a go later today.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't wanted to put more work on your head 😸. Thanks for going the extra mile -- I really enjoy using wxt, especially since one can see this attention put into those small little details.

* `browser_action` is converted to `action`) to allow using a `page_action`
* in MV3.
*/
mv2Key?: PerBrowserOption<'browser_action' | 'page_action'>;
defaultIcon?: Record<string, string>;
defaultTitle?: PerBrowserOption<string>;
Expand Down
Loading