Skip to content

Commit bbf8118

Browse files
authored
Merge pull request AgentDeskAI#39 from AgentDeskAI/staging
Merge staging into main: Chrome DevTools API Upgrade & Logging Improvements
2 parents bae8299 + c72e277 commit bbf8118

File tree

5 files changed

+76
-28
lines changed

5 files changed

+76
-28
lines changed

browser-tools-mcp/mcp-server.ts

Lines changed: 20 additions & 17 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();
@@ -87,19 +85,23 @@ server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
8785
// };
8886
// });
8987

90-
// 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`);
93-
const json = await response.json();
94-
return {
95-
content: [
96-
{
97-
type: "text",
98-
text: JSON.stringify(json, null, 2),
99-
},
100-
],
101-
};
102-
});
88+
// Return network success logs
89+
server.tool(
90+
"getNetworkSuccessLogs",
91+
"Check our network SUCCESS logs",
92+
async () => {
93+
const response = await fetch(`http://127.0.0.1:${PORT}/network-success`);
94+
const json = await response.json();
95+
return {
96+
content: [
97+
{
98+
type: "text",
99+
text: JSON.stringify(json, null, 2),
100+
},
101+
],
102+
};
103+
}
104+
);
103105

104106
// Add new tool for taking screenshots
105107
server.tool(
@@ -117,6 +119,7 @@ server.tool(
117119
const result = await response.json();
118120

119121
if (response.ok) {
122+
// Removed path due to bug... will change later anyways
120123
// const message = `Screenshot saved to: ${
121124
// result.path
122125
// }\nFilename: ${path.basename(result.path)}`;

browser-tools-mcp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agentdeskai/browser-tools-mcp",
3-
"version": "1.0.11",
3+
"version": "1.1.0",
44
"description": "MCP (Model Context Protocol) server for browser tools integration",
55
"main": "dist/mcp-server.js",
66
"bin": {

browser-tools-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agentdeskai/browser-tools-server",
3-
"version": "1.0.5",
3+
"version": "1.1.0",
44
"description": "A browser tools server for capturing and managing browser events, logs, and screenshots",
55
"main": "dist/browser-connector.js",
66
"bin": {

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.1.0",
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)