diff --git a/extension/src/js/background.js b/extension/src/js/background.js index 3597fa8..aa0276f 100644 --- a/extension/src/js/background.js +++ b/extension/src/js/background.js @@ -2,6 +2,23 @@ // TODO do I really need to annotate all files with @flow?? +// hmm this works if you declare type: module in manifest +// but it injects the script's contents statically? +// I assume this is only processed with webpack +// import * as browser from "./browser-polyfill" + +const manifestVersion = chrome.runtime.getManifest().manifest_version +if (manifestVersion == 3) { + // for v3 it's provided via manifest + try { + /* eslint-disable no-undef */ + importScripts('./browser-polyfill.js') + } catch (e) { + console.error(e) + } +} + + import {COMMAND_CAPTURE_SIMPLE, METHOD_CAPTURE_WITH_EXTRAS, showNotification} from './common' import {getOptions} from './options' import type {Options} from './options' diff --git a/extension/webpack.config.js b/extension/webpack.config.js index 374e48f..1168880 100644 --- a/extension/webpack.config.js +++ b/extension/webpack.config.js @@ -67,16 +67,16 @@ if (target == T.FIREFOX) { } -// prepare for manifest v3 -const host_permissions = [ - "http://localhost/capture", - "https://localhost/capture", +const endpoints = (domain) => [ + "http://" + domain + "/capture", + "https://" + domain + "/capture", ] -const optional_host_permissions = [ - "http://*/capture", - "https://*/capture", -] + +// prepare for manifest v3 +const host_permissions = endpoints('localhost') +const optional_host_permissions = endpoints('*') + // TODO make permissions literate const permissions = [ @@ -99,6 +99,15 @@ if (target === T.FIREFOX) { } +const content_security_policy = [ + "default-src 'self'", + "connect-src " + endpoints('*:*').join(' '), + + // FFS, otherwise