From abebf6f57551994756b30e1fed3336fe05182757 Mon Sep 17 00:00:00 2001 From: Cameron Stokes Date: Sun, 17 May 2026 15:07:42 -0700 Subject: [PATCH] fix browser detection for install instructions Chrome added a `browser` namespace (https://developer.chrome.com/docs/extensions/develop/concepts/browser-namespace) so `go run ... --install=...` instructions provided to the end user were specific to Firefox and didn't work for Chrome. Signed-off-by: Cameron Stokes --- background.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 "?"; }