Skip to content

Commit

Permalink
Improved error handling -- ignoring benign errors. Fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
getvictor committed May 27, 2024
1 parent 6d52a7f commit 9d9b653
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ chrome.webNavigation.onCommitted.addListener(
tabId: details.tabId,
frameIds: [details.frameId],
}
void chrome.scripting.insertCSS({
chrome.scripting.insertCSS({
css: cssToInject,
target: target,
}).catch((error) => {
console.info("OpenBlur Could not inject CSS into tab %d", details.tabId, error)
})
}
}
Expand All @@ -46,9 +48,11 @@ chrome.runtime.onMessage.addListener(
if (sender.frameId !== undefined) {
target.frameIds = [sender.frameId]
}
void chrome.scripting.removeCSS({
chrome.scripting.removeCSS({
css: cssToInject,
target: target,
}).catch((error) => {
console.info("OpenBlur Could not remove CSS from tab %d", target.tabId, error)
})
}
if (request.mode) {
Expand Down
20 changes: 16 additions & 4 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ chrome.storage.sync.get(null, (data) => {
// Send message to content script in all tabs
const tabs = await chrome.tabs.query({})
for (const tab of tabs) {
console.debug("OpenBlur Sending message to tab id %d, url %s", tab.id, tab.url)
void chrome.tabs.sendMessage(tab.id!, {literals})
console.debug("OpenBlur Sending literals message to tab id %d, title '%s' url %s", tab.id, tab.title, tab.url)
chrome.tabs.sendMessage(tab.id!, {literals})
.catch((error) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info("OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?", tab.title, tab.url, error)
}
})
}
}
})
Expand All @@ -38,8 +44,14 @@ checkbox.addEventListener("change", async (event) => {
// Send message to content script in all tabs
const tabs = await chrome.tabs.query({})
for (const tab of tabs) {
console.debug("OpenBlur Sending message to tab id %d, url %s", tab.id, tab.url)
void chrome.tabs.sendMessage(tab.id!, {mode: mode})
console.debug("OpenBlur Sending mode message to tab id %d, title '%s' url %s", tab.id, tab.title, tab.url)
chrome.tabs.sendMessage(tab.id!, {mode: mode})
.catch((error) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info("OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?", tab.title, tab.url, error)
}
})
}
}
})

0 comments on commit 9d9b653

Please sign in to comment.