Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #311 and migrates the extension to use Manifest v3. The most important change from v2 to v3 is that Firefox and Safari use background scripts or background pages while Chrome uses service workers for any background activity. They don't have a common ground though: Firefox & Safari extensions do not support background service workers and Chrome extensions do not support background pages or scripts.
So the respective
background
key in themanifest.json
file accepts both,scripts
andservice_worker
while the browsers only read what they can understand.Tickety-Tick used a background script to load the ticket information from the current tab if there's any. Doing so it was using a global function assigned to the
window
object. Migrating to Manifest v3 we can't do this any more because Chrome's service workers don't have access to the DOM. The recommended mechanism of communication between the different parts of a browser extension (popup, content script, background script, etc.) are messages. So I updated our background script to use messages and work as both, a service worker and a background script.Changes in detail:
Update
web-ext
to v7.12.0This is the last version before the version change to v8.
Update to v8 requires a bit more action eventually:
/~https://github.com/mozilla/web-ext/releases/tag/8.0.0
Update manifest to v3 for Firefox
Firefox does not support background service workers. They still want
scripts. So this setup still works fine in Firefox.
Refactor background script
Instead of relying on the background page instance (which is not
recommended, see link to the docs), we communicate with the background
script (or service worker script in Chrome) via message passing.
This way, we can use the same script in both browsers.
Mozilla docs on the topic: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts#update_calls_for_background_script_functions), we