mirror of
https://github.com/AgentDeskAI/browser-tools-mcp.git
synced 2025-06-27 00:41:26 +00:00
Merge pull request #38 from AgentDeskAI/update-runtime-api
Update Chrome DevTools Runtime API and Fix Logging Issues
This commit is contained in:
commit
7eef5e0359
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import path from "path";
|
|
||||||
// import { z } from "zod";
|
|
||||||
// import fs from "fs";
|
|
||||||
|
|
||||||
// Create the MCP server
|
// Create the MCP server
|
||||||
const server = new McpServer({
|
const server = new McpServer({
|
||||||
@ -60,7 +57,7 @@ server.tool(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Return all HTTP errors (4xx/5xx)
|
// Return all HTTP errors (4xx/5xx)
|
||||||
server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
|
server.tool("getNetworkErrorLogs", "Check our network ERROR logs", async () => {
|
||||||
const response = await fetch(`http://127.0.0.1:${PORT}/network-errors`);
|
const response = await fetch(`http://127.0.0.1:${PORT}/network-errors`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
return {
|
return {
|
||||||
@ -74,6 +71,7 @@ server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// // Return all XHR/fetch requests
|
// // Return all XHR/fetch requests
|
||||||
|
// // DEPRECATED: Use getNetworkSuccessLogs and getNetworkErrorLogs instead
|
||||||
// server.tool("getNetworkSuccess", "Check our network SUCCESS logs", async () => {
|
// server.tool("getNetworkSuccess", "Check our network SUCCESS logs", async () => {
|
||||||
// const response = await fetch(`http://127.0.0.1:${PORT}/all-xhr`);
|
// const response = await fetch(`http://127.0.0.1:${PORT}/all-xhr`);
|
||||||
// const json = await response.json();
|
// const json = await response.json();
|
||||||
@ -88,8 +86,8 @@ server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
// Return all XHR/fetch requests
|
// Return all XHR/fetch requests
|
||||||
server.tool("getNetworkLogs", "Check ALL our network logs", async () => {
|
server.tool("getNetworkSuccessLogs", "Check ALL our network logs", async () => {
|
||||||
const response = await fetch(`http://127.0.0.1:${PORT}/all-xhr`);
|
const response = await fetch(`http://127.0.0.1:${PORT}/network-success`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
@ -117,6 +115,7 @@ server.tool(
|
|||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
// Removed path due to bug... will change later anyways
|
||||||
// const message = `Screenshot saved to: ${
|
// const message = `Screenshot saved to: ${
|
||||||
// result.path
|
// result.path
|
||||||
// }\nFilename: ${path.basename(result.path)}`;
|
// }\nFilename: ${path.basename(result.path)}`;
|
||||||
|
@ -340,14 +340,14 @@ function performAttach() {
|
|||||||
|
|
||||||
chrome.debugger.sendCommand(
|
chrome.debugger.sendCommand(
|
||||||
{ tabId: currentTabId },
|
{ tabId: currentTabId },
|
||||||
"Console.enable",
|
"Runtime.enable",
|
||||||
{},
|
{},
|
||||||
() => {
|
() => {
|
||||||
if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
console.error("Failed to enable console:", chrome.runtime.lastError);
|
console.error("Failed to enable runtime:", chrome.runtime.lastError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("Console API successfully enabled");
|
console.log("Runtime API successfully enabled");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -390,12 +390,57 @@ const consoleMessageListener = (source, method, params) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === "Console.messageAdded") {
|
if (method === "Runtime.exceptionThrown") {
|
||||||
console.log("Console message received:", params.message);
|
|
||||||
const entry = {
|
const entry = {
|
||||||
type: params.message.level === "error" ? "console-error" : "console-log",
|
type: "console-error",
|
||||||
level: params.message.level,
|
message:
|
||||||
message: params.message.text,
|
params.exceptionDetails.exception?.description ||
|
||||||
|
JSON.stringify(params.exceptionDetails),
|
||||||
|
level: "error",
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
console.log("Sending runtime exception:", entry);
|
||||||
|
sendToBrowserConnector(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method === "Runtime.consoleAPICalled") {
|
||||||
|
// Process all arguments from the console call
|
||||||
|
let formattedMessage = "";
|
||||||
|
const args = params.args || [];
|
||||||
|
|
||||||
|
// Extract all arguments and combine them
|
||||||
|
if (args.length > 0) {
|
||||||
|
// Try to build a meaningful representation of all arguments
|
||||||
|
try {
|
||||||
|
formattedMessage = args
|
||||||
|
.map((arg) => {
|
||||||
|
// Handle different types of arguments
|
||||||
|
if (arg.type === "string") {
|
||||||
|
return arg.value;
|
||||||
|
} else if (arg.type === "object" && arg.preview) {
|
||||||
|
// For objects, include their preview or description
|
||||||
|
return JSON.stringify(arg.preview);
|
||||||
|
} else if (arg.description) {
|
||||||
|
// Some objects have descriptions
|
||||||
|
return arg.description;
|
||||||
|
} else {
|
||||||
|
// Fallback for other types
|
||||||
|
return arg.value || arg.description || JSON.stringify(arg);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.join(" ");
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback if processing fails
|
||||||
|
console.error("Failed to process console arguments:", e);
|
||||||
|
formattedMessage =
|
||||||
|
args[0]?.value || "Unable to process console arguments";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry = {
|
||||||
|
type: params.type === "error" ? "console-error" : "console-log",
|
||||||
|
level: params.type,
|
||||||
|
message: formattedMessage,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
console.log("Sending console entry:", entry);
|
console.log("Sending console entry:", entry);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "BrowserTools MCP",
|
"name": "BrowserTools MCP",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "MCP tool for AI code editors to capture data from a browser such as console logs, network requests, screenshots and more",
|
"description": "MCP tool for AI code editors to capture data from a browser such as console logs, network requests, screenshots and more",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"devtools_page": "devtools.html",
|
"devtools_page": "devtools.html",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user