From d133eac4f4b6572e3a127befd76758c783e12f47 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 19 Oct 2023 12:49:36 +0700 Subject: [PATCH] refactor: use try-catch block in sensor (#164) --- static/background.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/static/background.js b/static/background.js index 624bf7a..b92fde7 100644 --- a/static/background.js +++ b/static/background.js @@ -108,9 +108,9 @@ chrome.tabs.onUpdated.addListener( ); /** @param {number} tabId */ -function sensor(tabId) { - chrome.scripting - .executeScript({ +async function sensor(tabId) { + try { + await chrome.scripting.executeScript({ target: { tabId }, func: () => { @@ -124,11 +124,11 @@ function sensor(tabId) { chrome.runtime.sendMessage(detail); }); }, - }) - .catch(() => { - // for internal URLs like `chrome://` or `edge://` and extension gallery - // https://chromium.googlesource.com/chromium/src/+/ee77a52baa1f8a98d15f9749996f90e9d3200f2d/chrome/common/extensions/chrome_extensions_client.cc#131 - const icons = [16, 24, 48, 96, 128].map((s) => [s, `icons/disabled-${s}.png`]); - chrome.action.setIcon({ path: Object.fromEntries(icons) }); }); + } catch { + // for internal URLs like `chrome://` or `edge://` and extension gallery + // https://chromium.googlesource.com/chromium/src/+/ee77a52baa1f8a98d15f9749996f90e9d3200f2d/chrome/common/extensions/chrome_extensions_client.cc#131 + const icons = [16, 24, 48, 96, 128].map((s) => [s, `icons/disabled-${s}.png`]); + chrome.action.setIcon({ path: Object.fromEntries(icons) }); + } }