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

[311] Mozilla Add-ons manifest v3 #422

Merged
merged 4 commits into from
Oct 10, 2024

Conversation

klappradla
Copy link
Member

@klappradla klappradla commented Sep 19, 2024

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 the manifest.json file accepts both, scripts and service_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:

@klappradla klappradla added the work in progress This is currently being worked on label Sep 19, 2024
@klappradla klappradla force-pushed the feature/311-mozilla-add-ons-manifest-v3 branch from 4da6c04 to a87faa0 Compare September 20, 2024 10:32
This 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
Firefox does not support background service workers. They still want
scripts. So this setup still works fine in Firefox.
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
@klappradla klappradla force-pushed the feature/311-mozilla-add-ons-manifest-v3 branch from a87faa0 to e826ebd Compare September 20, 2024 10:34
@klappradla klappradla marked this pull request as ready for review September 20, 2024 10:34
@klappradla klappradla removed the work in progress This is currently being worked on label Sep 20, 2024
Copy link
Member

@andreasknoepfle andreasknoepfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat stuff!

@klappradla klappradla merged commit 1f33bc8 into main Oct 10, 2024
7 checks passed
@klappradla klappradla deleted the feature/311-mozilla-add-ons-manifest-v3 branch October 10, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mozilla Add-ons manifest v3
2 participants