more attempts for v3 and v2 simultaneous support

so far v3 works in firefox
but doesn't work with chrome, for some reason it refuses to import the webpack chunk
This commit is contained in:
Dima Gerasimov 2022-12-30 03:48:59 +00:00 committed by karlicoss
parent 5ec8bcb822
commit 60bdc0ae15
3 changed files with 32 additions and 14 deletions

View file

@ -47,9 +47,10 @@ def main():
], **kwargs) ], **kwargs)
env = { env = {
'TARGET': target, 'TARGET' : target,
'RELEASE': 'YES' if args.release else 'NO', 'RELEASE': 'YES' if args.release else 'NO',
'PUBLISH': 'YES' if args.publish else 'NO', 'PUBLISH': 'YES' if args.publish else 'NO',
'EXT_ID' : IDS[target],
**os.environ, **os.environ,
} }

View file

@ -6,7 +6,8 @@
// I assume this is only processed with webpack // I assume this is only processed with webpack
// import * as browser from "./browser-polyfill" // import * as browser from "./browser-polyfill"
// this works with v3 if you need to // this works with v3 but NOT if type: module
// also unclear how to make it work with webpack??
// const manifestVersion = chrome.runtime.getManifest().manifest_version // const manifestVersion = chrome.runtime.getManifest().manifest_version
// if (manifestVersion == 3) { // if (manifestVersion == 3) {
// // for v3 it's provided via manifest // // for v3 it's provided via manifest
@ -18,6 +19,14 @@
// } // }
// } // }
// this works for v2 both in chrome and firefox
// for v3
// - in chrome it works if type: module, but somehow NOT if we define chunks??
// without type: module this isn't working
// - in firefox it just works :shrug:
// but firefox foesn't allow type: module??
// could it be bug in chrome??
import * as browser from "webextension-polyfill" import * as browser from "webextension-polyfill"

View file

@ -14,10 +14,11 @@ const T = {
const v3 = false const v3 = false
const env = { const env = {
TARGET : process.env.TARGET, // TODO assert not null? TARGET : process.env.TARGET,
RELEASE: process.env.RELEASE, RELEASE: process.env.RELEASE,
PUBLISH: process.env.PUBLISH, PUBLISH: process.env.PUBLISH,
}; }
const ext_id = process.env.EXT_ID
const pkg = require('./package.json'); const pkg = require('./package.json');
const baseManifest = require('./src/manifest.json'); const baseManifest = require('./src/manifest.json');
@ -90,12 +91,11 @@ const permissions = [
const optional_permissions = [] const optional_permissions = []
if (target === T.FIREFOX || v3) {
if (target === T.FIREFOX) { // chrome v2 doesn't support scripting api
// chrome v2 doesn't support scripting api // code has a fallback just for that
// code has a fallback just for that // (needed to get selected text)
// need to get selected text permissions.push("scripting")
permissions.push("scripting")
} }
@ -118,7 +118,9 @@ 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', // wtf -- firefox doesn't support module??
// it just fails to load manifest in this case atm
...(target === T.FIREFOX? {} : {type: 'module'}),
} : { } : {
scripts: [ scripts: [
'webextension-polyfill.js', 'webextension-polyfill.js',
@ -135,7 +137,13 @@ manifestExtra[action_name] = action
if (v3) { if (v3) {
manifestExtra['host_permissions'] = host_permissions manifestExtra['host_permissions'] = host_permissions
manifestExtra['optional_host_permissions'] = optional_host_permissions manifestExtra['optional_host_permissions'] = optional_host_permissions
manifestExtra.permissions.push("scripting") if (target === T.FIREFOX) {
manifestExtra['browser_specific_settings'] = {
"gecko": {
"id": ext_id,
},
}
}
} else { } else {
manifestExtra.permissions.push(...host_permissions) manifestExtra.permissions.push(...host_permissions)
manifestExtra.optional_permissions.push(...optional_host_permissions) manifestExtra.optional_permissions.push(...optional_host_permissions)