Skip to content

Commit

Permalink
Add official Edge support
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Dec 5, 2023
1 parent ad6baa1 commit d2ad40f
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.bak
*.pem
/**/__pycache__/
/build/
/tmp/
21 changes: 21 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions tools/make-edge.mjs
Original file line number Diff line number Diff line change
@@ -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();

/******************************************************************************/
24 changes: 24 additions & 0 deletions tools/make-edge.sh
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit d2ad40f

Please sign in to comment.