Skip to content

Commit 8d98b9a

Browse files
islahultedjames
authored andcommitted
Switch to runtime api to capture exceptions correctly
1 parent 168518c commit 8d98b9a

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

chrome-extension/devtools.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,14 @@ function performAttach() {
380380

381381
chrome.debugger.sendCommand(
382382
{ tabId: currentTabId },
383-
"Console.enable",
383+
"Runtime.enable",
384384
{},
385385
() => {
386386
if (chrome.runtime.lastError) {
387-
console.error("Failed to enable console:", chrome.runtime.lastError);
387+
console.error("Failed to enable runtime:", chrome.runtime.lastError);
388388
return;
389389
}
390-
console.log("Console API successfully enabled");
390+
console.log("Runtime API successfully enabled");
391391
}
392392
);
393393
});
@@ -430,12 +430,22 @@ const consoleMessageListener = (source, method, params) => {
430430
return;
431431
}
432432

433-
if (method === "Console.messageAdded") {
434-
console.log("Console message received:", params.message);
433+
if (method === "Runtime.exceptionThrown") {
435434
const entry = {
436-
type: params.message.level === "error" ? "console-error" : "console-log",
437-
level: params.message.level,
438-
message: params.message.text,
435+
type: "console-error",
436+
message: params.exceptionDetails.exception?.description || JSON.stringify(params.exceptionDetails),
437+
level: "error",
438+
timestamp: Date.now(),
439+
};
440+
console.log("Sending runtime exception:", entry);
441+
sendToBrowserConnector(entry);
442+
}
443+
444+
if (method === "Runtime.consoleAPICalled") {
445+
const entry = {
446+
type: params.type === "error" ? "console-error" : "console-log",
447+
level: params.type,
448+
message: params.args[0].value,
439449
timestamp: Date.now(),
440450
};
441451
console.log("Sending console entry:", entry);

chrome-extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "BrowserTools MCP",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "MCP tool for AI code editors to capture data from a browser such as console logs, network requests, screenshots and more",
55
"manifest_version": 3,
66
"devtools_page": "devtools.html",

0 commit comments

Comments
 (0)