From d2ad40facf291a3c4eb5652b9740f920bb9dc72b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 5 Dec 2023 11:00:23 -0500 Subject: [PATCH] Add official Edge support --- .github/workflows/create_release.yml | 16 +++++++++ .gitignore | 1 + .jshintrc | 21 +++++++++++ Makefile | 12 +++++++ tools/make-edge.mjs | 54 ++++++++++++++++++++++++++++ tools/make-edge.sh | 24 +++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 .jshintrc create mode 100644 Makefile create mode 100644 tools/make-edge.mjs create mode 100755 tools/make-edge.sh diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 9990b414c..bb4b79524 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -57,6 +57,14 @@ jobs: rm -rf firefox mv "$UBLOCK_REPO_DIR/dist/build/uBOLite.firefox" firefox cp "$UBLOCK_REPO_DIR/dist/build/mv3-data/log.txt" firefox/ + # Edge + - name: Build Edge uBOLite MV3 packages + run: | + make edge + pushd build/uBOLite.edge/ > /dev/null + zip ../${{ env.TAGNAME }}.edge.mv3.zip -qr ./* + popd > /dev/null + echo "EDGE_PACKAGE=${{ env.TAGNAME }}.edge.mv3.zip" >> $GITHUB_ENV - name: Commit uBOLite MV3 package files # https://github.com/marketplace/actions/github-action-for-committing-changes-to-a-repository uses: devops-infra/action-commit-push@master @@ -87,6 +95,7 @@ jobs: - Chromium-based browsers: Install [from the Chrome Web Store](https://chrome.google.com/webstore/detail/ddkjiahejlhfcafbddmgiahcphecmpfh) - Firefox: [Install from AMO](https://addons.mozilla.org/firefox/addon/ublock-origin-lite/) + - Microsoft Edge: Install [from the Egde Add-ons store](https://microsoftedge.microsoft.com/addons/detail/ublock-origin-lite/cimighlppcgcoapaliogpjjdehbnofhn) The extension will auto-update when a new version is published. @@ -110,3 +119,10 @@ jobs: with: tag_name: ${{ env.TAGNAME }} files: ${{ env.UBLOCK_REPO_DIR }}/dist/build/${{ env.FIREFOX_PACKAGE }} + - name: Upload Edge uBOLite MV3 package + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.TAGNAME }} + files: build/${{ env.EDGE_PACKAGE }} diff --git a/.gitignore b/.gitignore index fb644b27e..7477aaee0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.bak *.pem /**/__pycache__/ +/build/ /tmp/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 000000000..8fdf7a69a --- /dev/null +++ b/.jshintrc @@ -0,0 +1,21 @@ +{ + "browser": true, + "devel": true, + "eqeqeq": true, + "esversion": 11, + "globals": { + "chrome": false, // global variable in Chromium, Chrome, Opera + "globalThis": false, + "self": false, + "URLSearchParams": false, + "WebAssembly": false + }, + "laxbreak": true, + "newcap": false, + "nonew": false, + "strict": "global", + "sub": true, + "undef": true, + "unused": true, + "validthis": true +} diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..29d8fee2a --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +.PHONY: clean edge + +chromium-sources := $(wildcard chromium/* chromium/*/* chromium/*/*/* chromium/*/*/*/*) +firefox-sources := $(wildcard firefox/* firefox/*/* firefox/*/*/* firefox/*/*/*/*) + +build/uBlock0.edge: tools/make-edge.sh tools/make-edge.mjs $(chromium-sources) + tools/make-edge.sh + +edge: build/uBlock0.edge + +clean: + rm -rf build diff --git a/tools/make-edge.mjs b/tools/make-edge.mjs new file mode 100644 index 000000000..4b073af57 --- /dev/null +++ b/tools/make-edge.mjs @@ -0,0 +1,54 @@ +/******************************************************************************* + + uBlock Origin Lite - a comprehensive, MV3-compliant content blocker + Copyright (C) 2022-present Raymond Hill + + 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 {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +'use strict'; + +/******************************************************************************/ + +import fs from 'fs/promises'; + +/******************************************************************************/ + +async function main() { + const manifestPath = 'build/uBOLite.edge/manifest.json'; + + // Get manifest content + const manifest = await fs.readFile(manifestPath, { encoding: 'utf8' + }).then(text => + JSON.parse(text) + ); + + // https://learn.microsoft.com/answers/questions/918426/cant-update-extension-with-declarative-net-request + // Set all ruleset path to package root + for ( const ruleset of manifest.declarative_net_request.rule_resources ) { + const pos = ruleset.path.lastIndexOf('/'); + if ( pos === -1 ) { continue; } + ruleset.path = ruleset.path.slice(pos + 1); + } + // Commit changes + await fs.writeFile(manifestPath, + JSON.stringify(manifest, null, 2) + '\n' + ); +} + +main(); + +/******************************************************************************/ diff --git a/tools/make-edge.sh b/tools/make-edge.sh new file mode 100755 index 000000000..1ec7d2ae1 --- /dev/null +++ b/tools/make-edge.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# This script assumes a linux environment + +set -e + +echo "*** uBOLite.edge: Creating web store package" + +DES=build/uBOLite.edge +rm -rf $DES +mkdir -p $DES + +echo "*** uBOLite.edge: Copying reference chromium-based files" +cp -R chromium/* $DES/ + +# Edge store requires that all DNR rulesets are at the root of the package +# https://learn.microsoft.com/answers/questions/918426/cant-update-extension-with-declarative-net-request +echo "*** uBOLite.edge: Modify reference implementation for Edge compatibility" +mv $DES/rulesets/main/* $DES/ +rmdir $DES/rulesets/main +# Patch manifest.json +node tools/make-edge.mjs + +echo "*** uBOLite.edge: Package done."