Skip to content

Commit

Permalink
refactor: use try-catch block in sensor (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb authored Oct 19, 2023
1 parent 64ada61 commit d133eac
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions static/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand All @@ -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) });
}
}

0 comments on commit d133eac

Please sign in to comment.