From 1368f016fee5474aa8b8bbd2a0b49e824b8a63b7 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 20 Feb 2023 18:18:31 -0500 Subject: [PATCH] FIx Firefox check failing under Chromium --- js/background.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/background.js b/js/background.js index df7b684..296b3ec 100644 --- a/js/background.js +++ b/js/background.js @@ -1,3 +1,5 @@ +const isFirefox = chrome.runtime.getURL('').startsWith('moz-extension://') + // Initialize welcome message and context menu entry on extension load chrome.runtime.onInstalled.addListener(function (details) { // Show welcome message @@ -10,7 +12,7 @@ chrome.runtime.onInstalled.addListener(function (details) { message: "Click here to see what's new in this version." } // Firefox doesn't support buttons in notifications - if (!window.navigator.userAgent.includes('Firefox')) { + if (!isFirefox) { notification.buttons = [ { title: 'Open Settings' @@ -27,7 +29,7 @@ chrome.runtime.onInstalled.addListener(function (details) { chrome.tabs.create({ url: 'https://corbin.io/introducing-share-to-mastodon/' }) }) // Handle notification button clicks - if (!window.navigator.userAgent.includes('Firefox')) { + if (!isFirefox) { chrome.notifications.onButtonClicked.addListener(function (_, buttonIndex) { if (buttonIndex === 0) { chrome.runtime.openOptionsPage() @@ -49,7 +51,7 @@ chrome.runtime.onInstalled.addListener(function (details) { async function migrateOldData() { // Chrome/Edge version saved a single server in a "userServer" string in chrome.storage.sync // Firefox version saved it in the same "userServer" string, but in chrome.local.sync - if (window.navigator.userAgent.includes('Firefox')) { + if (isFirefox) { var data = await chrome.storage.local.get() } else { var data = await chrome.storage.sync.get()