-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[311] Mozilla Add-ons manifest v3 (#422)
* [311] Mozilla Add-ons manifest v3 Ticket: #311 Closes #311 * Update web-ext to v7.12.0 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 * 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)
- Loading branch information
1 parent
e6f0579
commit 1f33bc8
Showing
9 changed files
with
200 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import browser from "webextension-polyfill"; | ||
|
||
import type { BackgroundMessage } from "../popup/types"; | ||
|
||
async function getTickets() { | ||
const [tab] = await browser.tabs.query({ active: true, currentWindow: true }); | ||
const results = await browser.tabs.sendMessage(tab.id!, { tickets: true }); // eslint-disable-line @typescript-eslint/no-non-null-assertion | ||
return results; | ||
} | ||
|
||
Object.assign(window, { getTickets }); | ||
async function handleMessage(msg: BackgroundMessage) { | ||
if (msg.getTickets) { | ||
return getTickets(); | ||
} | ||
return null; | ||
} | ||
|
||
browser.runtime.onMessage.addListener(handleMessage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.