diff --git a/extension/src/manifest.json b/extension/src/manifest.json index 06ab305..c740f1d 100644 --- a/extension/src/manifest.json +++ b/extension/src/manifest.json @@ -1,19 +1,11 @@ { "name": "", "version": "", - "background": { - "scripts": [ - "browser-polyfill.js", - "background.js" - ], - "persistent": false - }, "options_ui": { "page": "options.html", "open_in_tab": false }, "icons": { "128": "img/unicorn.png" - }, - "manifest_version": 2 + } } diff --git a/extension/webpack.config.js b/extension/webpack.config.js index 7653ef6..374e48f 100644 --- a/extension/webpack.config.js +++ b/extension/webpack.config.js @@ -9,6 +9,10 @@ const T = { FIREFOX: 'firefox', }; + +// TODO will be conditional on T.CHROME at some point +const v3 = false + const env = { TARGET : process.env.TARGET, // TODO assert not null? RELEASE: process.env.RELEASE, @@ -32,7 +36,7 @@ const name = "grasp" + (dev ? ' [dev]' : ''); // On the other hand, Chrome wouldn't let you use Alt const modifier = target === T.CHROME ? 'Shift' : 'Alt' -const action_name = 'browser_action' +const action_name = v3 ? 'action' : 'browser_action' const commands = { "capture-simple": { @@ -69,13 +73,11 @@ const host_permissions = [ "https://localhost/capture", ] - -const optional_permissions = [ +const optional_host_permissions = [ "http://*/capture", "https://*/capture", ] - // TODO make permissions literate const permissions = [ "storage", @@ -83,10 +85,12 @@ const permissions = [ // need to query active tab and get its url/title "activeTab", - - ...host_permissions, ] + +const optional_permissions = [] + + if (target === T.FIREFOX) { // chrome v2 doesn't support scripting api // code has a fallback just for that @@ -102,17 +106,34 @@ const manifestExtra = { permissions: permissions, commands: commands, optional_permissions: optional_permissions, + manifest_version: v3 ? 3 : 2, + background: (v3 ? { + service_worker: 'background.js', + type: "module", + } : { + scripts: [ + 'browser-polyfill.js', + 'background.js', + ], + persistent: false, + }), } manifestExtra[action_name] = action +if (v3) { + manifestExtra['host_permissions'] = host_permissions + manifestExtra['optional_host_permissions'] = optional_host_permissions + manifestExtra.permissions.push("scripting") +} else { + manifestExtra.permissions.push(...host_permissions) + manifestExtra.optional_permissions.push(...optional_host_permissions) +} + if (dev) { manifestExtra.content_security_policy = "script-src 'self' 'unsafe-eval'; object-src 'self'"; } -if (target === T.CHROME) { - manifestExtra.options_ui = {chrome_style: true}; -} if (target === T.FIREFOX) { manifestExtra.options_ui = {browser_style: true}; }