Skip to content

Commit 7eef5e0

Browse files
authored
Merge pull request #38 from AgentDeskAI/update-runtime-api
Update Chrome DevTools Runtime API and Fix Logging Issues
2 parents aca07bc + 2b62059 commit 7eef5e0

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

browser-tools-mcp/mcp-server.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
44
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5-
import path from "path";
6-
// import { z } from "zod";
7-
// import fs from "fs";
85

96
// Create the MCP server
107
const server = new McpServer({
@@ -60,7 +57,7 @@ server.tool(
6057
);
6158

6259
// Return all HTTP errors (4xx/5xx)
63-
server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
60+
server.tool("getNetworkErrorLogs", "Check our network ERROR logs", async () => {
6461
const response = await fetch(`http://127.0.0.1:${PORT}/network-errors`);
6562
const json = await response.json();
6663
return {
@@ -74,6 +71,7 @@ server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
7471
});
7572

7673
// // Return all XHR/fetch requests
74+
// // DEPRECATED: Use getNetworkSuccessLogs and getNetworkErrorLogs instead
7775
// server.tool("getNetworkSuccess", "Check our network SUCCESS logs", async () => {
7876
// const response = await fetch(`http://127.0.0.1:${PORT}/all-xhr`);
7977
// const json = await response.json();
@@ -88,8 +86,8 @@ server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
8886
// });
8987

9088
// Return all XHR/fetch requests
91-
server.tool("getNetworkLogs", "Check ALL our network logs", async () => {
92-
const response = await fetch(`http://127.0.0.1:${PORT}/all-xhr`);
89+
server.tool("getNetworkSuccessLogs", "Check ALL our network logs", async () => {
90+
const response = await fetch(`http://127.0.0.1:${PORT}/network-success`);
9391
const json = await response.json();
9492
return {
9593
content: [
@@ -117,6 +115,7 @@ server.tool(
117115
const result = await response.json();
118116

119117
if (response.ok) {
118+
// Removed path due to bug... will change later anyways
120119
// const message = `Screenshot saved to: ${
121120
// result.path
122121
// }\nFilename: ${path.basename(result.path)}`;

chrome-extension/devtools.js

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ function performAttach() {
340340

341341
chrome.debugger.sendCommand(
342342
{ tabId: currentTabId },
343-
"Console.enable",
343+
"Runtime.enable",
344344
{},
345345
() => {
346346
if (chrome.runtime.lastError) {
347-
console.error("Failed to enable console:", chrome.runtime.lastError);
347+
console.error("Failed to enable runtime:", chrome.runtime.lastError);
348348
return;
349349
}
350-
console.log("Console API successfully enabled");
350+
console.log("Runtime API successfully enabled");
351351
}
352352
);
353353
});
@@ -390,12 +390,57 @@ const consoleMessageListener = (source, method, params) => {
390390
return;
391391
}
392392

393-
if (method === "Console.messageAdded") {
394-
console.log("Console message received:", params.message);
393+
if (method === "Runtime.exceptionThrown") {
395394
const entry = {
396-
type: params.message.level === "error" ? "console-error" : "console-log",
397-
level: params.message.level,
398-
message: params.message.text,
395+
type: "console-error",
396+
message:
397+
params.exceptionDetails.exception?.description ||
398+
JSON.stringify(params.exceptionDetails),
399+
level: "error",
400+
timestamp: Date.now(),
401+
};
402+
console.log("Sending runtime exception:", entry);
403+
sendToBrowserConnector(entry);
404+
}
405+
406+
if (method === "Runtime.consoleAPICalled") {
407+
// Process all arguments from the console call
408+
let formattedMessage = "";
409+
const args = params.args || [];
410+
411+
// Extract all arguments and combine them
412+
if (args.length > 0) {
413+
// Try to build a meaningful representation of all arguments
414+
try {
415+
formattedMessage = args
416+
.map((arg) => {
417+
// Handle different types of arguments
418+
if (arg.type === "string") {
419+
return arg.value;
420+
} else if (arg.type === "object" && arg.preview) {
421+
// For objects, include their preview or description
422+
return JSON.stringify(arg.preview);
423+
} else if (arg.description) {
424+
// Some objects have descriptions
425+
return arg.description;
426+
} else {
427+
// Fallback for other types
428+
return arg.value || arg.description || JSON.stringify(arg);
429+
}
430+
})
431+
.join(" ");
432+
} catch (e) {
433+
// Fallback if processing fails
434+
console.error("Failed to process console arguments:", e);
435+
formattedMessage =
436+
args[0]?.value || "Unable to process console arguments";
437+
}
438+
}
439+
440+
const entry = {
441+
type: params.type === "error" ? "console-error" : "console-log",
442+
level: params.type,
443+
message: formattedMessage,
399444
timestamp: Date.now(),
400445
};
401446
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)