Skip to content

Commit 42b55f6

Browse files
authored
fix: Correct actionKey for Firefox in MV3 (#2274)
1 parent e64058b commit 42b55f6

2 files changed

Lines changed: 35 additions & 23 deletions

File tree

packages/wxt/src/core/utils/__tests__/manifest.test.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('Manifest Utils', () => {
3434
describe('generateManifest', () => {
3535
describe('popup', () => {
3636
type ActionType = 'browser_action' | 'page_action';
37+
type Mv3ActionType = 'action' | 'page_action';
3738
const popupEntrypoint = (type?: ActionType) =>
3839
fakePopupEntrypoint({
3940
options: {
@@ -107,29 +108,39 @@ describe('Manifest Utils', () => {
107108
},
108109
);
109110

110-
it('should allow converting action to page_action for Firefox MV3', async () => {
111-
const popup = popupEntrypoint('page_action');
112-
const buildOutput = fakeBuildOutput();
113-
setFakeWxt({
114-
config: {
115-
manifestVersion: 3,
116-
outDir,
117-
browser: 'firefox',
118-
},
119-
});
120-
const expected = {
121-
default_icon: popup.options.defaultIcon,
122-
default_title: popup.options.defaultTitle,
123-
default_popup: 'popup.html',
124-
};
111+
it.each<{
112+
inputType: ActionType | undefined;
113+
expectedType: Mv3ActionType;
114+
}>([
115+
{ inputType: undefined, expectedType: 'action' },
116+
{ inputType: 'browser_action', expectedType: 'action' },
117+
{ inputType: 'page_action', expectedType: 'page_action' },
118+
])(
119+
'should use the correct action for Firefox in mv3: %j',
120+
async ({ inputType, expectedType }) => {
121+
const popup = popupEntrypoint(inputType);
122+
const buildOutput = fakeBuildOutput();
123+
setFakeWxt({
124+
config: {
125+
manifestVersion: 3,
126+
outDir,
127+
browser: 'firefox',
128+
},
129+
});
130+
const expected = {
131+
default_icon: popup.options.defaultIcon,
132+
default_title: popup.options.defaultTitle,
133+
default_popup: 'popup.html',
134+
};
125135

126-
const { manifest: actual } = await generateManifest(
127-
[popup],
128-
buildOutput,
129-
);
136+
const { manifest: actual } = await generateManifest(
137+
[popup],
138+
buildOutput,
139+
);
130140

131-
expect(actual.page_action).toEqual(expected);
132-
});
141+
expect(actual[expectedType]).toEqual(expected);
142+
},
143+
);
133144

134145
it('should include default_area for Firefox in mv3', async () => {
135146
const popup = fakePopupEntrypoint({

packages/wxt/src/core/utils/manifest.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ function addEntrypoints(
307307
const actionKey =
308308
manifest.manifest_version === 2
309309
? (popup.options.actionType ?? 'browser_action')
310-
: wxt.config.browser === 'firefox'
311-
? (popup.options.actionType ?? 'action')
310+
: wxt.config.browser === 'firefox' &&
311+
popup.options.actionType === 'page_action'
312+
? 'page_action'
312313
: 'action';
313314

314315
manifest[actionKey] = {

0 commit comments

Comments
 (0)