final changes for manifest v3 -- seems that everything works now both for v2 and v3

This commit is contained in:
Dima Gerasimov 2022-12-28 20:45:06 +00:00 committed by karlicoss
parent 4f0fbe9624
commit 32fb5ce108
2 changed files with 41 additions and 20 deletions

View file

@ -2,6 +2,23 @@
// TODO do I really need to annotate all files with @flow?? // 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 {COMMAND_CAPTURE_SIMPLE, METHOD_CAPTURE_WITH_EXTRAS, showNotification} from './common'
import {getOptions} from './options' import {getOptions} from './options'
import type {Options} from './options' import type {Options} from './options'

View file

@ -67,16 +67,16 @@ if (target == T.FIREFOX) {
} }
// prepare for manifest v3 const endpoints = (domain) => [
const host_permissions = [ "http://" + domain + "/capture",
"http://localhost/capture", "https://" + domain + "/capture",
"https://localhost/capture",
] ]
const optional_host_permissions = [
"http://*/capture", // prepare for manifest v3
"https://*/capture", const host_permissions = endpoints('localhost')
] const optional_host_permissions = endpoints('*')
// TODO make permissions literate // TODO make permissions literate
const permissions = [ const permissions = [
@ -99,6 +99,15 @@ if (target === T.FIREFOX) {
} }
const content_security_policy = [
"default-src 'self'",
"connect-src " + endpoints('*:*').join(' '),
// FFS, otherwise <style> directives on extension's pages not working??
"style-src 'unsafe-inline'",
].join('; ')
const manifestExtra = { const manifestExtra = {
name: name, name: name,
version: pkg.version, version: pkg.version,
@ -109,7 +118,6 @@ const manifestExtra = {
manifest_version: v3 ? 3 : 2, manifest_version: v3 ? 3 : 2,
background: (v3 ? { background: (v3 ? {
service_worker: 'background.js', service_worker: 'background.js',
type: "module",
} : { } : {
scripts: [ scripts: [
'browser-polyfill.js', 'browser-polyfill.js',
@ -117,6 +125,9 @@ const manifestExtra = {
], ],
persistent: false, persistent: false,
}), }),
content_security_policy: v3 ? {
extension_pages: content_security_policy,
} : content_security_policy,
} }
manifestExtra[action_name] = action manifestExtra[action_name] = action
@ -130,10 +141,6 @@ if (v3) {
} }
if (dev) {
manifestExtra.content_security_policy = "script-src 'self' 'unsafe-eval'; object-src 'self'";
}
if (target === T.FIREFOX) { if (target === T.FIREFOX) {
manifestExtra.options_ui = {browser_style: true}; manifestExtra.options_ui = {browser_style: true};
} }
@ -196,13 +203,10 @@ const options = {
extend: manifestExtra, extend: manifestExtra,
} }
}), }),
] ],
}; // docs claim it's the slowest but pretty fast anyway
devtool: 'source-map',
// TODO https://webpack.js.org/configuration/devtool
if (dev) {
// ??? don't remember what it was for, but webpack complains about it now
// options.devtool = "cheap-module-eval-source-map";
} }
module.exports = options; module.exports = options;