more preparation for supporting both manifest v2 and v3
This commit is contained in:
parent
16bd3441df
commit
eca07d97a7
|
@ -1,19 +1,11 @@
|
||||||
{
|
{
|
||||||
"name": "<webpack managed>",
|
"name": "<webpack managed>",
|
||||||
"version": "<webpack managed>",
|
"version": "<webpack managed>",
|
||||||
"background": {
|
|
||||||
"scripts": [
|
|
||||||
"browser-polyfill.js",
|
|
||||||
"background.js"
|
|
||||||
],
|
|
||||||
"persistent": false
|
|
||||||
},
|
|
||||||
"options_ui": {
|
"options_ui": {
|
||||||
"page": "options.html",
|
"page": "options.html",
|
||||||
"open_in_tab": false
|
"open_in_tab": false
|
||||||
},
|
},
|
||||||
"icons": {
|
"icons": {
|
||||||
"128": "img/unicorn.png"
|
"128": "img/unicorn.png"
|
||||||
},
|
}
|
||||||
"manifest_version": 2
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,10 @@ const T = {
|
||||||
FIREFOX: 'firefox',
|
FIREFOX: 'firefox',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// TODO will be conditional on T.CHROME at some point
|
||||||
|
const v3 = false
|
||||||
|
|
||||||
const env = {
|
const env = {
|
||||||
TARGET : process.env.TARGET, // TODO assert not null?
|
TARGET : process.env.TARGET, // TODO assert not null?
|
||||||
RELEASE: process.env.RELEASE,
|
RELEASE: process.env.RELEASE,
|
||||||
|
@ -32,7 +36,7 @@ const name = "grasp" + (dev ? ' [dev]' : '');
|
||||||
// On the other hand, Chrome wouldn't let you use Alt
|
// On the other hand, Chrome wouldn't let you use Alt
|
||||||
const modifier = target === T.CHROME ? 'Shift' : 'Alt'
|
const modifier = target === T.CHROME ? 'Shift' : 'Alt'
|
||||||
|
|
||||||
const action_name = 'browser_action'
|
const action_name = v3 ? 'action' : 'browser_action'
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
"capture-simple": {
|
"capture-simple": {
|
||||||
|
@ -69,13 +73,11 @@ const host_permissions = [
|
||||||
"https://localhost/capture",
|
"https://localhost/capture",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const optional_host_permissions = [
|
||||||
const optional_permissions = [
|
|
||||||
"http://*/capture",
|
"http://*/capture",
|
||||||
"https://*/capture",
|
"https://*/capture",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
// TODO make permissions literate
|
// TODO make permissions literate
|
||||||
const permissions = [
|
const permissions = [
|
||||||
"storage",
|
"storage",
|
||||||
|
@ -83,10 +85,12 @@ const permissions = [
|
||||||
|
|
||||||
// need to query active tab and get its url/title
|
// need to query active tab and get its url/title
|
||||||
"activeTab",
|
"activeTab",
|
||||||
|
|
||||||
...host_permissions,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
const optional_permissions = []
|
||||||
|
|
||||||
|
|
||||||
if (target === T.FIREFOX) {
|
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
|
||||||
|
@ -102,17 +106,34 @@ const manifestExtra = {
|
||||||
permissions: permissions,
|
permissions: permissions,
|
||||||
commands: commands,
|
commands: commands,
|
||||||
optional_permissions: optional_permissions,
|
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
|
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) {
|
if (dev) {
|
||||||
manifestExtra.content_security_policy = "script-src 'self' 'unsafe-eval'; object-src 'self'";
|
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) {
|
if (target === T.FIREFOX) {
|
||||||
manifestExtra.options_ui = {browser_style: true};
|
manifestExtra.options_ui = {browser_style: true};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue