mcp-browser-dev-tools 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/app.mjs +52 -9
- package/src/logger.mjs +38 -5
package/README.md
CHANGED
|
@@ -152,7 +152,7 @@ Median of 3 runs on the current build, from the benchmark in [PERFORMANCE.md](PE
|
|
|
152
152
|
| Sign in, then change settings | 16.2 s · 11 turns | 17.5 s · 7 turns | 18.2 s · 8 turns |
|
|
153
153
|
| Read five pages from a results list | 27.7 s · 6 turns | 8.5 s · 4 turns | 11.8 s · 5 turns |
|
|
154
154
|
|
|
155
|
-
Every form run started with `get_snapshot` and acted by ref, without being told to. Each payment click waits for the page to settle and reports the decline or the receipt, so the agents could retry from each reply. The last row uses `run_tabs`.
|
|
155
|
+
Every form run started with `get_snapshot` and acted by ref, without being told to. Each payment click waits for the page to settle and reports the decline or the receipt, so the agents could retry from each reply. The last row uses `run_tabs`. Eight models (Claude Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5, and Haiku 4.5; GPT-6-Astra, GPT-6.1 Sol, and GPT-6-Luna) ran the same four tasks with the default tool set: 95 of those 96 runs passed, and PERFORMANCE.md has the time, cost, and turns for each, the charts, and how the runs were set up.
|
|
156
156
|
|
|
157
157
|
## Tools
|
|
158
158
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-browser-dev-tools",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Browser MCP server for AI agents: batch actions, waits, and checks into one call on Chrome, Edge, or Firefox (CDP and WebDriver BiDi)",
|
|
5
5
|
"author": "Hinaser <rindo.hinase@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
package/src/app.mjs
CHANGED
|
@@ -64,28 +64,71 @@ export function createBrowserDevToolsApp({
|
|
|
64
64
|
server.start();
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
let exitCode = null;
|
|
68
|
+
|
|
69
|
+
// Closes once and exits with the highest code asked for meanwhile.
|
|
70
|
+
function closeAndExit(signal, code) {
|
|
71
|
+
const first = exitCode == null;
|
|
72
|
+
exitCode = Math.max(exitCode ?? 0, code);
|
|
73
|
+
if (first) {
|
|
74
|
+
void close(signal).finally(() => process.exit(exitCode));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let fatal = false;
|
|
79
|
+
|
|
80
|
+
function handleFatal(signal, message) {
|
|
81
|
+
// Only the first one is logged: a fatal error raised by the logging
|
|
82
|
+
// itself would otherwise come back here forever.
|
|
83
|
+
if (fatal) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fatal = true;
|
|
88
|
+
logger.error(message, { force: true });
|
|
89
|
+
closeAndExit(signal, 1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function handleStreamError(name, stream, error) {
|
|
93
|
+
if (stream === errorOutput) {
|
|
94
|
+
logger.disableOutput();
|
|
95
|
+
}
|
|
96
|
+
logger.info(`${name} failed: ${error?.code ?? error?.message ?? error}`);
|
|
97
|
+
// EPIPE means the client closed its end, and without stdout the server
|
|
98
|
+
// cannot answer it anyway.
|
|
99
|
+
if (stream === output || error?.code === "EPIPE") {
|
|
100
|
+
closeAndExit(`${name} error`, 0);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
67
104
|
function installSignalHandlers() {
|
|
68
105
|
process.on("SIGINT", () => {
|
|
69
|
-
|
|
106
|
+
closeAndExit("SIGINT", 0);
|
|
70
107
|
});
|
|
71
108
|
|
|
72
109
|
process.on("SIGTERM", () => {
|
|
73
|
-
|
|
110
|
+
closeAndExit("SIGTERM", 0);
|
|
74
111
|
});
|
|
75
112
|
|
|
113
|
+
// Without a listener, a failed write to a closed pipe becomes an
|
|
114
|
+
// uncaught exception.
|
|
115
|
+
output.on?.("error", (error) => handleStreamError("stdout", output, error));
|
|
116
|
+
errorOutput.on?.("error", (error) =>
|
|
117
|
+
handleStreamError("stderr", errorOutput, error),
|
|
118
|
+
);
|
|
119
|
+
|
|
76
120
|
process.on("uncaughtException", (error) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
121
|
+
handleFatal(
|
|
122
|
+
"uncaughtException",
|
|
123
|
+
`uncaught exception: ${error?.stack ?? error}`,
|
|
124
|
+
);
|
|
81
125
|
});
|
|
82
126
|
|
|
83
127
|
process.on("unhandledRejection", (reason) => {
|
|
84
|
-
|
|
128
|
+
handleFatal(
|
|
129
|
+
"unhandledRejection",
|
|
85
130
|
`unhandled rejection: ${reason instanceof Error ? (reason.stack ?? reason.message) : reason}`,
|
|
86
|
-
{ force: true },
|
|
87
131
|
);
|
|
88
|
-
void close("unhandledRejection").finally(() => process.exit(1));
|
|
89
132
|
});
|
|
90
133
|
|
|
91
134
|
process.on("exit", (code) => {
|
package/src/logger.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { appendFileSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, renameSync, statSync } from "node:fs";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
|
|
4
4
|
import { PACKAGE_NAME } from "./package-info.mjs";
|
|
@@ -10,6 +10,18 @@ export const LOG_LEVELS = {
|
|
|
10
10
|
debug: 3,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// When the log file would grow past this, it is renamed to `<file>.1`
|
|
14
|
+
// (replacing any older one) and a new file is started.
|
|
15
|
+
export const LOG_FILE_MAX_BYTES = 10 * 1024 * 1024;
|
|
16
|
+
|
|
17
|
+
function fileSize(filePath) {
|
|
18
|
+
try {
|
|
19
|
+
return statSync(filePath).size;
|
|
20
|
+
} catch {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
function normalizeMessage(message) {
|
|
14
26
|
if (message instanceof Error) {
|
|
15
27
|
return message.message;
|
|
@@ -23,11 +35,30 @@ export function createLogger({
|
|
|
23
35
|
output = process.stderr,
|
|
24
36
|
name = PACKAGE_NAME,
|
|
25
37
|
filePath = null,
|
|
38
|
+
maxFileBytes = LOG_FILE_MAX_BYTES,
|
|
26
39
|
} = {}) {
|
|
27
40
|
const threshold = LOG_LEVELS[level] ?? LOG_LEVELS.error;
|
|
41
|
+
let outputEnabled = true;
|
|
42
|
+
|
|
43
|
+
function appendToFile(line) {
|
|
44
|
+
try {
|
|
45
|
+
const size = fileSize(filePath);
|
|
46
|
+
if (size > 0 && size + Buffer.byteLength(line) > maxFileBytes) {
|
|
47
|
+
renameSync(filePath, `${filePath}.1`);
|
|
48
|
+
}
|
|
49
|
+
appendFileSync(filePath, line);
|
|
50
|
+
} catch {
|
|
51
|
+
// ignore file write errors to avoid crashing the server
|
|
52
|
+
}
|
|
53
|
+
}
|
|
28
54
|
|
|
29
55
|
return {
|
|
30
56
|
level,
|
|
57
|
+
// Stops writing to `output`, for example once its reader is gone; the
|
|
58
|
+
// log file still gets every line.
|
|
59
|
+
disableOutput() {
|
|
60
|
+
outputEnabled = false;
|
|
61
|
+
},
|
|
31
62
|
enabled(messageLevel) {
|
|
32
63
|
return (LOG_LEVELS[messageLevel] ?? -1) <= threshold;
|
|
33
64
|
},
|
|
@@ -37,14 +68,16 @@ export function createLogger({
|
|
|
37
68
|
}
|
|
38
69
|
|
|
39
70
|
const line = `[${name}] ${messageLevel}: ${normalizeMessage(message)}\n`;
|
|
40
|
-
|
|
41
|
-
if (filePath != null) {
|
|
71
|
+
if (outputEnabled) {
|
|
42
72
|
try {
|
|
43
|
-
|
|
73
|
+
output.write(line);
|
|
44
74
|
} catch {
|
|
45
|
-
|
|
75
|
+
outputEnabled = false;
|
|
46
76
|
}
|
|
47
77
|
}
|
|
78
|
+
if (filePath != null) {
|
|
79
|
+
appendToFile(line);
|
|
80
|
+
}
|
|
48
81
|
return true;
|
|
49
82
|
},
|
|
50
83
|
error(message, options) {
|