Skip to content

Commit 11882bb

Browse files
committed
fix(chrome.debugger): Error: Debugger is not attached to the tab with id: 1812797494.
1 parent a1da0aa commit 11882bb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/background/background.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IBytesRepository } from "../data/bytes/IBytesRepository";
22
import { addBytesTransferred } from "./backgroundHelpers";
33

4-
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
4+
chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
55
if (message === "getBytesTransferred") {
66
sendResponse(IBytesRepository.instance.getBytesTransferred());
77
}
@@ -28,7 +28,20 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
2828
}
2929

3030
if (message.command === "stopRecordingBytesTransferred") {
31-
chrome.debugger.detach({ tabId: tabId });
31+
try {
32+
await chrome.debugger.detach({ tabId: tabId });
33+
} catch (e: unknown) {
34+
if (e instanceof Error) {
35+
if (
36+
e.message ===
37+
`Debugger is not attached to the tab with id: ${tabId}.`
38+
) {
39+
console.warn(
40+
`Tried to detach debugger from tab (tabId: ${tabId}) when there was none attached. This is expected when a calculation starts, but should not be expected when a calculation is stopped.`
41+
);
42+
}
43+
}
44+
}
3245
sendResponse(true);
3346
}
3447
return true;

src/background/backgroundHelpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const addBytesTransferred = async (bytes: number) => {
1616
e.message ===
1717
"Could not establish connection. Receiving end does not exist."
1818
) {
19-
console.log(
19+
console.warn(
2020
`Error Caught: ${e}\nIf popup is open and this error is seen in the console, debugging is required.`
2121
);
2222
}

0 commit comments

Comments
 (0)