From b35a7c78c97ba808fc2065e3dcf7fb25cb7beeb9 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 10 Nov 2022 21:46:51 -0800 Subject: [PATCH] Eliminate spurious uncaught exception --- extension/background.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/extension/background.js b/extension/background.js index 37de1b2..2b847e1 100644 --- a/extension/background.js +++ b/extension/background.js @@ -1,6 +1,12 @@ // chrome.action for Chrome, browser.browserAction for Firefox (chrome.action || browser.browserAction).onClicked.addListener(() => { - chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => - chrome.tabs.sendMessage(tabs[0].id, { event: "hypercastInit" }) - ); + chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + try { + chrome.tabs.sendMessage(tabs[0].id, { event: "hypercastInit" }); + } catch (err) { + console.error( + "User clicked extension icon but content script was not active" + ); + } + }); });