Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Manifest V3 for Firefox #1121

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backgroundscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (typeof browser !== 'undefined') {
// Chromium/Chrome
genericBrowser = chrome;
}

// DEV: For a Mozilla MV3 extension, we have to change the event below to 'action'
genericBrowser.browserAction.onClicked.addListener(function () {
var newURL = chrome.runtime.getURL('www/index.html');
chrome.tabs.create({ url: newURL });
Expand Down
47 changes: 47 additions & 0 deletions manifest.fx.v3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"manifest_version": 3,
"name": "Kiwix",
"version": "3.10.2",

"description": "Kiwix Offline Browser",

"icons": {
"16": "www/img/icons/kiwix-16.png",
"19": "www/img/icons/kiwix-19.png",
"32": "www/img/icons/kiwix-32.png",
"38": "www/img/icons/kiwix-38.png",
"48": "www/img/icons/kiwix-48.png",
"64": "www/img/icons/kiwix-64.png",
"90": "www/img/icons/kiwix-90.png",
"128": "www/img/icons/kiwix-128.png"
},

"action": {
"default_icon": {
"16": "www/img/icons/kiwix-16.png",
"19": "www/img/icons/kiwix-19.png",
"32": "www/img/icons/kiwix-32.png",
"38": "www/img/icons/kiwix-38.png",
"64": "www/img/icons/kiwix-64.png"
},
"default_title": "Kiwix"
},

"background": {
"scripts": ["backgroundscript.js"]
},

"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';",
"sandbox": "sandbox allow-scripts allow-downloads allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';"
},

"web_accessible_resources": [{
"resources": ["www/index.html", "www/article.html"],
"matches": ["https://*.kiwix.org/*"]
}],

"author": "Kiwix",
"homepage_url": "https://www.kiwix.org",
"offline_enabled": true
}
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const config = {
},
{ src: ['node_modules/bootstrap/dist/css/bootstrap.min.*'], dest: 'dist/www/css' },
{ src: ['i18n/*'], dest: 'dist/i18n' },
{ src: ['archives', 'backgroundscript.js', 'index.html', 'manifest.json', 'manifest.v2.json', 'manifest.webapp', 'package.json', 'LICENSE-GPLv3.txt', 'CHANGELOG.md', 'README.md', '*.pfx', '*.cjs'], dest: 'dist' }
{ src: ['archives', 'backgroundscript.js', 'index.html', 'manifest.json', 'manifest.fx.v3.json', 'manifest.v2.json', 'manifest.webapp', 'package.json', 'LICENSE-GPLv3.txt', 'CHANGELOG.md', 'README.md', '*.pfx', '*.cjs'], dest: 'dist' }
],
flatten: true
})
Expand Down
35 changes: 21 additions & 14 deletions scripts/create_all_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,14 @@ fi
# Copy only the necessary files in a temporary directory
mkdir -p tmp
rm -rf tmp/*
cp -r www i18n manifest.json manifest.v2.json manifest.webapp LICENSE-GPLv3.txt service-worker.js README.md tmp/
cp -r www i18n manifest.json manifest.webapp LICENSE-GPLv3.txt service-worker.js README.md tmp/
# Remove unwanted files (this line should not be necessary if building from dist/)
rm -f tmp/www/js/lib/libzim-*dev.*

# Replace the version number everywhere
# But Chrome would only accept a numeric version number : if it's not, we only use the prefix in manifest.json
regexpNumericVersion='^[0-9\.]+$'
if [[ $VERSION =~ $regexpNumericVersion ]] ; then
sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/manifest.json
sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/manifest.v2.json
else
sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json
sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.v2.json
fi
sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json
sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/manifest.webapp
sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/service-worker.js
sed -i -E "s/$VERSION_TO_REPLACE/$VERSION/" tmp/www/js/init.js
Expand All @@ -85,23 +79,36 @@ rm -rf build/*
scripts/package_chrome_extension.sh -m 3 $DRYRUN $TAG -v $VERSION
# Package for Chromium/Chrome with Manifest V2
cp backgroundscript.js tmp/
rm tmp/manifest.json
mv tmp/manifest.v2.json tmp/manifest.json
cp manifest.v2.json tmp/manifest.json
sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json
scripts/package_chrome_extension.sh -m 2 $DRYRUN $TAG -v $VERSION
echo "The following extensions have been built so far:"
pwd & ls -l build

# Package for Firefox and Firefox OS
# Package for Firefox MV2
# We have to put a unique version string inside the manifest.json (which Chrome might not have accepted)
# So we take the original manifest v2 again, and replace the version inside it again
cp manifest.v2.json tmp/manifest.json
sed -i -E "s/$VERSION_TO_REPLACE/$VERSION_FOR_MOZILLA_MANIFEST/" tmp/manifest.json
echo "Manifest version for Firefox extension:"
echo "Manifest version for Firefox MV2 extension:"
cat tmp/manifest.json
echo -e "\nPacking for Firefox..."
scripts/package_firefox_extension.sh $DRYRUN $TAG -v $VERSION
echo -e "\nPacking for Firefox MV2..."
scripts/package_firefox_extension.sh -m 2 $DRYRUN $TAG -v $VERSION

# Package for Firefox MV3
cp manifest.fx.v3.json tmp/manifest.json
# Replace the browserAction key which is no longer supported in MV3
sed -i -E "s/browserAction/action/" tmp/backgroundscript.js
# Note that MV3 requires a numeric version number
sed -i -E "s/$VERSION_TO_REPLACE/$MAJOR_NUMERIC_VERSION/" tmp/manifest.json
echo "Manifest version for Firefox MV3 extension:"
cat tmp/manifest.json
echo -e "\nPacking for Firefox MV3..."
scripts/package_firefox_extension.sh -m 3 $DRYRUN $TAG -v $VERSION
echo "The following extensions have been built so far:"
pwd & ls -l build

# Package for Firefox OS
echo -e "\nPacking for Firefox OS..."
scripts/package_firefoxos_app.sh $DRYRUN $TAG -v $VERSION
cp -f ubuntu_touch/* tmp/
Expand Down
7 changes: 6 additions & 1 deletion scripts/package_firefox_extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ cd "$BASEDIR"
pwd

# Reading arguments
while getopts tdv: option; do
while getopts m:tdv: option; do
case "${option}" in
m) MV=$OPTARG;; # Optionally indicates the manifest version we're using (2 or 3); if present, the version will be added to filename
t) TAG="-t";; # Indicates that we're releasing a public version from a tag
d) DRYRUN="-d";; # Indicates a dryrun test, that does not modify anything on the network
v) VERSION=${OPTARG};;
esac
done
if [ -n $MV ]; then
echo -e "\nManifest version requested: $MV"
VERSION="mv$MV-$VERSION"
fi

# Install web-ext if it's not already installed (and if we're not doing a dryrun test)
if [ ! -f node_modules/web-ext/bin/web-ext ] && [ "${DRYRUN}zz" == "zz" ]; then
Expand Down