From ef63bff914e145d589dd32873ad7f386559203df Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Fri, 10 May 2024 13:06:24 +0200 Subject: [PATCH] Allow both service_worker and scripts in MV3 Web Extensions (#9673) * Allow both service_worker and scripts in MV3 * support `background.page` and `background.persistent` in MV3 * Lint --------- Co-authored-by: 101arrowz --- .../test/integration/webextension-mv3/manifest.json | 4 +++- packages/core/integration-tests/test/webextension.js | 1 + .../transformers/webextension/src/WebExtensionTransformer.js | 3 ++- packages/transformers/webextension/src/schema.js | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/integration-tests/test/integration/webextension-mv3/manifest.json b/packages/core/integration-tests/test/integration/webextension-mv3/manifest.json index b8ff5f08993..08398794f2c 100644 --- a/packages/core/integration-tests/test/integration/webextension-mv3/manifest.json +++ b/packages/core/integration-tests/test/integration/webextension-mv3/manifest.json @@ -4,7 +4,9 @@ "version": "0.1", "manifest_version": 3, "background": { - "service_worker": "background.js" + "service_worker": "background.js", + "type": "module", + "scripts": [ "background.js" ] }, "permissions": [ "scripting", diff --git a/packages/core/integration-tests/test/webextension.js b/packages/core/integration-tests/test/webextension.js index f31629fffb7..2e2a681fbfc 100644 --- a/packages/core/integration-tests/test/webextension.js +++ b/packages/core/integration-tests/test/webextension.js @@ -111,6 +111,7 @@ describe('webextension', function () { assets: ['manifest.json'], }, {assets: ['background.js']}, + {assets: ['background.js']}, {assets: ['popup.html']}, {assets: ['popup.css']}, {assets: ['popup.js', 'esmodule-helpers.js', 'bundle-url.js']}, diff --git a/packages/transformers/webextension/src/WebExtensionTransformer.js b/packages/transformers/webextension/src/WebExtensionTransformer.js index 51cbe6a0ef7..3ee647fe8a9 100644 --- a/packages/transformers/webextension/src/WebExtensionTransformer.js +++ b/packages/transformers/webextension/src/WebExtensionTransformer.js @@ -273,7 +273,8 @@ async function collectDependencies( ...getJSONSourceLocation(ptrs['/background/page'], 'value'), }, }); - } else if (program.background?.service_worker) { + } + if (program.background?.service_worker) { program.background.service_worker = asset.addURLDependency( program.background.service_worker, { diff --git a/packages/transformers/webextension/src/schema.js b/packages/transformers/webextension/src/schema.js index 20f6dc6ca08..3f38853ef8b 100644 --- a/packages/transformers/webextension/src/schema.js +++ b/packages/transformers/webextension/src/schema.js @@ -473,6 +473,10 @@ export const MV3Schema = ({ type: 'string', enum: ['classic', 'module'], }, + // to support both Chrome and Firefox + scripts: arrStr, + page: string, + persistent: boolean, }, additionalProperties: false, required: ['service_worker'],