The dream of being able to produce one browser extension and deploy it for Firefox, Opera and Chrome is not quite realized, due different packaging, and slight differences in the manifest.json file for Firefox.
Regarding packaging, there are two options: .crx
and .zip
. Oddly, I have found that the Mozilla web store only works with the .crx
, and Opera and Chrome only with the .zip
. These are maybe bugs that may be fixed by the time you read this.
The manifest.json file for Firefox may contain an optional key, applications
, which prints a warning if used in a Chrome extension and therefore should not be present in what you publish to Chrome. However, as explained in Mozilla Bug 1378248, it's not really optional if you are using certain API such as Native Messaging. It is also not optional if you are hosting your Firefox extension on your own site (probably to avoid the weeks-long approval times for the AMO store) and want it to update automatically, because the update_url
key is also a sub-key of applications
.
So, anyhow, I finally realized I needed to bite the bullet and write the attached bash shell script which produces the different packages for Firefox, Opera and Chrome. The script is attached, in case others which to steal any lines.
The primary trick this script does is to combine a manifest additions JSON file, found in, say, a BrowserSpecial/Firefox
subfolder, into the BrowserCommon/manifest.json
file, but only when building for, say, Firefox. To do this, it requires that jq be installed on your system.
In the script directory and symbol names, I use the acronym W3CBE to mean World Wide Web Consortium Browser Extension. This is a placeholder for the dream that someday, the Mozilla team will get this to be a W3C standard, and we will refer to our cross-browser extensions as W3CBE Extensions.
There are at least a few things that you'll need to tweak.
-
This script packages my two extensions, BookMacsterButton and BookMacsterSync. Replace those with your own extension name(s).
-
Unless you're building this associated with another application, you probably won't want the section to # Verify that extension version….
-
I have placed this script in a Run Script Build Phase in Xcode, running on macOS, so it uses a several environment variables with $NAMES_FORMATTED_LIKE_THIS. In particular, two of them specify the source and destination directory paths. You'll need to replace these with your own environment variables or input parameters.
-
You will replace
$SOURCE_ROOT/../../Scripts/crxmake.sh
with the path tocrxmake.sh
, which you must have installed somewhere on your system.