From af88ebc38bc5496c21e3126d44f6dca486e8bbf2 Mon Sep 17 00:00:00 2001 From: hackademix Date: Mon, 18 Nov 2024 10:07:29 +0100 Subject: [PATCH] Adapt build scripts to mixed MV3/MV2 12.x development cycles. --- build.sh | 27 ++++--------------------- manifest.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/nscl | 2 +- 3 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 manifest.js diff --git a/build.sh b/build.sh index 81a43f9..7fdfcea 100644 --- a/build.sh +++ b/build.sh @@ -172,34 +172,15 @@ strip_rc_ver "$MANIFEST_OUT" # manifest.json patching for Chromium: -EXTRA_PERMS="" -if grep 'patchWorkers.js' "$MANIFEST_OUT" >/dev/null 2>&1; then - EXTRA_PERMS='"debugger",' -fi +GECKO_PERMS="dns||webRequestBlocking" -# skip "application" manifest key -(grep -B1000 '"name": "NoScript"' "$MANIFEST_OUT"; \ - grep -A2000 '"version":' "$MANIFEST_OUT") | \ - # auto-update URL for the Edge version on the Microsoft Store - sed -e '/"name":/a\' -e ' "update_url": "'$EDGE_UPDATE_URL'",' | \ - # skip embeddingDocument.js and dns permission - grep -Pv 'content/embeddingDocument.js|"dns",' | \ - # add "debugger" permission for patchWorkers.js - sed -re 's/( *)"webRequestBlocking",/&\n\1'"$EXTRA_PERMS"'/' | \ - # add origin fallback for content scripts - sed -re 's/( *)"match_about_blank": *true/\1"match_origin_as_fallback": true,\n&/' > \ - "$MANIFEST_OUT".tmp && \ - mv "$MANIFEST_OUT.tmp" "$MANIFEST_OUT" +node manifest.js $MANIFEST_OUT CHROME_ZIP=$(build | grep 'ready: .*\.zip' | sed -re 's/.* ready: //') if [ -f "$CHROME_ZIP" ]; then - mv "$CHROME_ZIP" "$XPI$DBG-edge.zip" - # remove Edge-specific manifest lines and package for generic Chromium - grep -v '"update_url":' "$MANIFEST_OUT" > "$MANIFEST_OUT.tmp" && \ - mv "$MANIFEST_OUT.tmp" "$MANIFEST_OUT" && \ - build - mv "$CHROME_ZIP" "$XPI$DBG-chrome.zip" + node manifest.js mv3 $MANIFEST_OUT && build + mv "$CHROME_ZIP" "$XPI$DBG-chrome.zip" fi mv "$BUILD" "$CHROMIUM_UNPACKED" diff --git a/manifest.js b/manifest.js new file mode 100644 index 0000000..ae88ff6 --- /dev/null +++ b/manifest.js @@ -0,0 +1,58 @@ +/* + * NoScript Commons Library + * Reusable building blocks for cross-browser security/privacy WebExtensions. + * Copyright (C) 2020-2024 Giorgio Maone + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +"use strict"; + +const fs = require('fs'); +const path = require('path'); +const args = process.argv.slice(2); +const MANIFEST_VER = /^m?v?[2-3]$/i.test(args[0]) ? args.shift() : "mv3edge"; +const MANIFEST_SRC = args[0] || "src/manifest.json"; +const MANIFEST_DEST = args[1] || args[0] || "build/manifest.json"; + +const EDGE_UPDATE_URL = "https://edge.microsoft.com/extensionwebstorebase/v1/crx"; + +console.log(`${MANIFEST_SRC} --[${MANIFEST_VER}]--> ${MANIFEST_DEST}`); + +const srcContent = fs.readFileSync(MANIFEST_SRC, 'utf8'); +const json = JSON.parse(srcContent); + +if (MANIFEST_VER.includes(3)) { + delete json.browser_specific_settings; + if (MANIFEST_VER.includes("edge")) { + json.update_url = EDGE_UPDATE_URL; + } else if (json.update_url === EDGE_UPDATE_URL) { + delete json.update_url; + } + json.permissions = json.permissions + .filter(p => ! + /^(?:|webRequestBlocking)$/ + .test(p) + ); + for (const cs of json.content_scripts) { + cs.js = cs.js.filter(js => !js.includes("content/embeddingDocument.js")) + } + delete json.browser_action; + delete json.commands._execute_browser_action +} + +const destContent = JSON.stringify(json, null, 2); +fs.writeFileSync(MANIFEST_DEST, destContent); +console.log(`Written ${MANIFEST_DEST}`); diff --git a/src/nscl b/src/nscl index ec68d37..b9610d4 160000 --- a/src/nscl +++ b/src/nscl @@ -1 +1 @@ -Subproject commit ec68d37aaf9279a81aa5970942e166777a1ab9f4 +Subproject commit b9610d41876354963584737b3ce668e6583e0546