uBlock/tools/make-mv3.sh
Raymond Hill cbfd2ad942
Create a MVP version of uBOLite for Firefox
What does not work at the time of commit:

Cosmetic filtering does not work:

The content scripts responsible for cosmetic filtering fail when
trying to inject the stylesheets through document.adoptedStyleSheets,
with the following error message:

  XrayWrapper denied access to property Symbol.iterator
  (reason: object is not safely Xrayable).
  See https://developer.mozilla.org/en-US/docs/Xray_vision for more
  information. ... css-declarative.js:106:8

A possible solution is to inject those content scripts in the
MAIN world. However Firefox scripting API does not support MAIN
world injection at the moment.

Scriptlet-filtering does not work:

Because scriptlet code needs to be injected in the MAIN world,
and this is currently not supported by Firefox's scripting API,
see https://bugzilla.mozilla.org/show_bug.cgi?id=1736575

There is no count badge on the toolbar icon in Firefox, as it
currently does not support the `DNR.setExtensionActionOptions`
method.

Other than the above issues, it does appear uBO is blocking
properly with no error reported in the dev console.

The adoptedStyleSheets issue though is worrisome, as the
cosmetic filtering content scripts were designed with ISOLATED
world injection in mind. Being forced to inject in MAIN world
(when available) make things a bit more complicated as uBO
has to ensure it's global variables do not leak into the page.
2023-04-07 10:19:43 -04:00

106 lines
2.6 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# This script assumes a linux environment
set -e
echo "*** uBOLite.mv3: Creating extension"
PLATFORM="chromium"
for i in "$@"; do
case $i in
quick)
QUICK="yes"
shift # past argument=value
;;
firefox)
PLATFORM="firefox"
shift # past argument=value
;;
chromium)
PLATFORM="chromium"
shift # past argument=value
;;
esac
done
DES="dist/build/uBOLite.$PLATFORM"
if [ "$QUICK" != "yes" ]; then
rm -rf $DES
fi
mkdir -p $DES
cd $DES
DES=$(pwd)
cd - > /dev/null
mkdir -p $DES/css/fonts
mkdir -p $DES/js
mkdir -p $DES/img
echo "*** uBOLite.mv3: Copying common files"
cp -R src/css/fonts/* $DES/css/fonts/
cp src/css/themes/default.css $DES/css/
cp src/css/common.css $DES/css/
cp src/css/dashboard-common.css $DES/css/
cp src/css/fa-icons.css $DES/css/
cp src/js/dom.js $DES/js/
cp src/js/fa-icons.js $DES/js/
cp src/js/i18n.js $DES/js/
cp LICENSE.txt $DES/
echo "*** uBOLite.mv3: Copying mv3-specific files"
if [ "$PLATFORM" = "firefox" ]; then
cp platform/mv3/firefox/background.html $DES/
fi
cp platform/mv3/extension/*.html $DES/
cp platform/mv3/extension/css/* $DES/css/
cp -R platform/mv3/extension/js/* $DES/js/
cp platform/mv3/extension/img/* $DES/img/
cp -R platform/mv3/extension/_locales $DES/
if [ "$QUICK" != "yes" ]; then
echo "*** uBOLite.mv3: Generating rulesets"
TMPDIR=$(mktemp -d)
mkdir -p $TMPDIR
if [ "$PLATFORM" = "chromium" ]; then
cp platform/mv3/chromium/manifest.json $DES/
elif [ "$PLATFORM" = "firefox" ]; then
cp platform/mv3/firefox/manifest.json $DES/
fi
./tools/make-nodejs.sh $TMPDIR
cp platform/mv3/package.json $TMPDIR/
cp platform/mv3/*.js $TMPDIR/
cp platform/mv3/extension/js/utils.js $TMPDIR/js/
cp assets/assets.json $TMPDIR/
cp -R platform/mv3/scriptlets $TMPDIR/
mkdir -p $TMPDIR/web_accessible_resources
cp src/web_accessible_resources/* $TMPDIR/web_accessible_resources/
cd $TMPDIR
node --no-warnings make-rulesets.js output=$DES platform="$PLATFORM"
cd - > /dev/null
rm -rf $TMPDIR
fi
echo "*** uBOLite.mv3: extension ready"
echo "Extension location: $DES/"
if [ "$1" = "full" ]; then
echo "*** uBOLite.mv3: Creating webstore package..."
PACKAGENAME=uBOLite_$(jq -r .version $DES/manifest.json).mv3.zip
TMPDIR=$(mktemp -d)
mkdir -p $TMPDIR
cp -R $DES/* $TMPDIR/
cd $TMPDIR > /dev/null
rm log.txt
zip $PACKAGENAME -qr ./*
cd - > /dev/null
cp $TMPDIR/$PACKAGENAME dist/build/
rm -rf $TMPDIR
echo "Package location: $(pwd)/dist/build/$PACKAGENAME"
fi