diff --git a/background.js b/background.js index 9553ad8..7e55ed0 100644 --- a/background.js +++ b/background.js @@ -81,13 +81,13 @@ chrome.runtime.onConnect.addListener((port) => { // browserByte returns either "F" for Firefox or "C" for chrome. // Other browsers return "?". +// Firefox aliases `chrome.*` to its `browser.*` APIs, so +// `chrome.runtime.getURL` works on both; the returned scheme is what differs. +// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities function browserByte() { - if (typeof chrome !== "undefined") { - if (typeof browser !== "undefined") { - return "F"; // Firefox supports both `chrome` and `browser` - } - return "C"; - } + const url = chrome.runtime.getURL(""); + if (url.startsWith("moz-extension://")) return "F"; + if (url.startsWith("chrome-extension://")) return "C"; return "?"; }