fix!: Automatically move host_permissions to permissions for MV2 (#626)
BREAKING CHANGE: Out of an abundance of caution, I've marked this as a breaking change because permission generation has changed. ***If you list `host_permissions` in your `wxt.config.ts`'s manifest and have released your extension***, double check that your `permissions` and `host_permissions` have not changed for all browsers you target. Permission changes can cause the extension to be disabled on update, and can cause a drop in users, so be sure to double check for differences compared to the previous manifest version.
This commit is contained in:
@@ -1447,6 +1447,53 @@ describe('Manifest Utils', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('host_permissions', () => {
|
||||
it('should keep host_permissions as-is for MV3', async () => {
|
||||
const expectedHostPermissions = ['https://google.com/*'];
|
||||
const expectedPermissions = ['scripting'];
|
||||
setFakeWxt({
|
||||
config: {
|
||||
manifest: {
|
||||
host_permissions: expectedHostPermissions,
|
||||
permissions: expectedPermissions,
|
||||
},
|
||||
manifestVersion: 3,
|
||||
command: 'build',
|
||||
},
|
||||
});
|
||||
const output = fakeBuildOutput();
|
||||
|
||||
const { manifest: actual } = await generateManifest([], output);
|
||||
|
||||
expect(actual.permissions).toEqual(expectedPermissions);
|
||||
expect(actual.host_permissions).toEqual(expectedHostPermissions);
|
||||
});
|
||||
|
||||
it('should move host_permissions to permissions for MV2, ignoring duplicates', async () => {
|
||||
const expectedPermissions = [
|
||||
'scripting',
|
||||
'*://*.youtube.com/*',
|
||||
'https://google.com/*',
|
||||
];
|
||||
setFakeWxt({
|
||||
config: {
|
||||
manifest: {
|
||||
host_permissions: ['https://google.com/*', '*://*.youtube.com/*'],
|
||||
permissions: ['scripting', '*://*.youtube.com/*'],
|
||||
},
|
||||
manifestVersion: 2,
|
||||
command: 'build',
|
||||
},
|
||||
});
|
||||
const output = fakeBuildOutput();
|
||||
|
||||
const { manifest: actual } = await generateManifest([], output);
|
||||
|
||||
expect(actual.permissions).toEqual(expectedPermissions);
|
||||
expect(actual.host_permissions).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripPathFromMatchPattern', () => {
|
||||
|
||||
@@ -117,6 +117,7 @@ export async function generateManifest(
|
||||
if (wxt.config.manifestVersion === 2) {
|
||||
convertWebAccessibleResourcesToMv2(manifest);
|
||||
convertActionToMv2(manifest);
|
||||
moveHostPermissionsToPermissions(manifest);
|
||||
}
|
||||
|
||||
if (wxt.config.manifestVersion === 3) {
|
||||
@@ -617,6 +618,17 @@ export function convertWebAccessibleResourcesToMv2(
|
||||
);
|
||||
}
|
||||
|
||||
function moveHostPermissionsToPermissions(
|
||||
manifest: Manifest.WebExtensionManifest,
|
||||
): void {
|
||||
if (!manifest.host_permissions?.length) return;
|
||||
|
||||
manifest.host_permissions.forEach((permission) =>
|
||||
addPermission(manifest, permission),
|
||||
);
|
||||
delete manifest.host_permissions;
|
||||
}
|
||||
|
||||
function convertActionToMv2(manifest: Manifest.WebExtensionManifest): void {
|
||||
if (
|
||||
manifest.action == null ||
|
||||
|
||||
Reference in New Issue
Block a user