Skip to content

Commit 9d9b653

Browse files
committed
Improved error handling -- ignoring benign errors. Fixes #11
1 parent 6d52a7f commit 9d9b653

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/background.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ chrome.webNavigation.onCommitted.addListener(
2828
tabId: details.tabId,
2929
frameIds: [details.frameId],
3030
}
31-
void chrome.scripting.insertCSS({
31+
chrome.scripting.insertCSS({
3232
css: cssToInject,
3333
target: target,
34+
}).catch((error) => {
35+
console.info("OpenBlur Could not inject CSS into tab %d", details.tabId, error)
3436
})
3537
}
3638
}
@@ -46,9 +48,11 @@ chrome.runtime.onMessage.addListener(
4648
if (sender.frameId !== undefined) {
4749
target.frameIds = [sender.frameId]
4850
}
49-
void chrome.scripting.removeCSS({
51+
chrome.scripting.removeCSS({
5052
css: cssToInject,
5153
target: target,
54+
}).catch((error) => {
55+
console.info("OpenBlur Could not remove CSS from tab %d", target.tabId, error)
5256
})
5357
}
5458
if (request.mode) {

src/popup.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ chrome.storage.sync.get(null, (data) => {
2222
// Send message to content script in all tabs
2323
const tabs = await chrome.tabs.query({})
2424
for (const tab of tabs) {
25-
console.debug("OpenBlur Sending message to tab id %d, url %s", tab.id, tab.url)
26-
void chrome.tabs.sendMessage(tab.id!, {literals})
25+
console.debug("OpenBlur Sending literals message to tab id %d, title '%s' url %s", tab.id, tab.title, tab.url)
26+
chrome.tabs.sendMessage(tab.id!, {literals})
27+
.catch((error) => {
28+
// We ignore tabs without a proper URL, like chrome://extensions/
29+
if (tab.url) {
30+
console.info("OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?", tab.title, tab.url, error)
31+
}
32+
})
2733
}
2834
}
2935
})
@@ -38,8 +44,14 @@ checkbox.addEventListener("change", async (event) => {
3844
// Send message to content script in all tabs
3945
const tabs = await chrome.tabs.query({})
4046
for (const tab of tabs) {
41-
console.debug("OpenBlur Sending message to tab id %d, url %s", tab.id, tab.url)
42-
void chrome.tabs.sendMessage(tab.id!, {mode: mode})
47+
console.debug("OpenBlur Sending mode message to tab id %d, title '%s' url %s", tab.id, tab.title, tab.url)
48+
chrome.tabs.sendMessage(tab.id!, {mode: mode})
49+
.catch((error) => {
50+
// We ignore tabs without a proper URL, like chrome://extensions/
51+
if (tab.url) {
52+
console.info("OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?", tab.title, tab.url, error)
53+
}
54+
})
4355
}
4456
}
4557
})

0 commit comments

Comments
 (0)