Skip to content

Commit

Permalink
[ext] require MANIFEST_VERSION when configuring the extension with EX…
Browse files Browse the repository at this point in the history
…TENSION_BROWSER set
  • Loading branch information
amatissart committed Feb 15, 2024
1 parent dc7e8d0 commit cd3e12e
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions browser-extension/prepareExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ import {
} from './prepareTools.js';

const env = process.env.TOURNESOL_ENV || 'production';
const browser = process.env.EXTENSION_BROWSER || 'firefox';

const defaultManifestVersion = browser === 'firefox' ? 2 : 3;
const manifestVersion = parseInt(
process.env.MANIFEST_VERSION || defaultManifestVersion
);
const browser = process.env.EXTENSION_BROWSER || 'firefox';
if (process.env.EXTENSION_BROWSER && !process.env.MANIFEST_VERSION) {
throw new Error(`MANIFEST_VERSION is required with EXTENSION_BROWSER`);
}

const manifestVersion = parseInt(process.env.MANIFEST_VERSION || 2);
if (manifestVersion != 2 && manifestVersion != 3)
throw new Error(`Invalid manifest version: ${manifestVersion}`);
if (manifestVersion === 2) {
console.info(
`Extension will be configured with manifest version ${manifestVersion}.`
);
} else {
console.info(
`Extension will be configured for ${browser} with manifest version ${manifestVersion}.`
);
}

const { version } = await readPackage();

const hostPermissions = [
...selectValue(env, {
production: ['https://tournesol.app/', 'https://api.tournesol.app/'],
Expand All @@ -36,6 +44,11 @@ const permissions = [
'contextMenus',
'storage',
'webNavigation',
// webRequest and webReauestBlocking were used to overwrite
// headers in the API response. This is no longer the case
// with version > 3.5.2.
// These permissions can be removed as soon as we are confident
// the next release works as expected.
'webRequest',
'webRequestBlocking',
...selectValue(manifestVersion, { 2: [], 3: ['scripting'] }),
Expand Down

0 comments on commit cd3e12e

Please sign in to comment.