mcp-browser-dev-tools 0.0.3 → 0.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-browser-dev-tools",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
5
5
  "author": "Hinaser <rindo.hinase@gmail.com>",
6
6
  "license": "MIT",
package/src/app.mjs CHANGED
@@ -16,6 +16,7 @@ export function createBrowserDevToolsApp({
16
16
  level: config.logLevel,
17
17
  output: errorOutput,
18
18
  name: PACKAGE_NAME,
19
+ filePath: config.logFile,
19
20
  });
20
21
  const browserAdapter = createBrowserAdapter(config);
21
22
  const server = new McpBrowserDevToolsServer({
@@ -71,6 +72,27 @@ export function createBrowserDevToolsApp({
71
72
  process.on("SIGTERM", () => {
72
73
  void close("SIGTERM").finally(() => process.exit(0));
73
74
  });
75
+
76
+ process.on("uncaughtException", (error) => {
77
+ logger.error(`uncaught exception: ${error?.stack ?? error}`, {
78
+ force: true,
79
+ });
80
+ void close("uncaughtException").finally(() => process.exit(1));
81
+ });
82
+
83
+ process.on("unhandledRejection", (reason) => {
84
+ logger.error(
85
+ `unhandled rejection: ${reason instanceof Error ? (reason.stack ?? reason.message) : reason}`,
86
+ { force: true },
87
+ );
88
+ void close("unhandledRejection").finally(() => process.exit(1));
89
+ });
90
+
91
+ process.on("exit", (code) => {
92
+ if (code !== 0) {
93
+ logger.error(`process exiting with code ${code}`, { force: true });
94
+ }
95
+ });
74
96
  }
75
97
 
76
98
  return {
@@ -302,6 +302,20 @@ function normalizeEvent(method, params) {
302
302
  };
303
303
  }
304
304
 
305
+ if (
306
+ method === "Page.javascriptDialogOpening" ||
307
+ method === "Page.javascriptDialogClosed"
308
+ ) {
309
+ return {
310
+ kind: "dialog",
311
+ phase: method === "Page.javascriptDialogOpening" ? "opened" : "closed",
312
+ dialogType: params.type ?? null,
313
+ message: params.message ?? null,
314
+ defaultPrompt: params.defaultPrompt ?? null,
315
+ url: params.url ?? null,
316
+ };
317
+ }
318
+
305
319
  return {
306
320
  kind: "raw",
307
321
  method,
@@ -486,6 +500,10 @@ export class CdpSession {
486
500
  this.lastNavigationAt = capturedAt;
487
501
  }
488
502
 
503
+ if (method === "Page.javascriptDialogOpening") {
504
+ this.autoDismissDialog(params);
505
+ }
506
+
489
507
  this.pushEvent({
490
508
  method,
491
509
  capturedAt,
@@ -494,6 +512,11 @@ export class CdpSession {
494
512
  this.resolveEventWaiters(method, params);
495
513
  }
496
514
 
515
+ autoDismissDialog(params) {
516
+ const accept = params.type !== "prompt";
517
+ this.send("Page.handleJavaScriptDialog", { accept }).catch(() => {});
518
+ }
519
+
497
520
  pushEvent(event) {
498
521
  this.bufferedEvents.push(event);
499
522
  if (this.bufferedEvents.length > this.eventBufferSize) {
package/src/cli.mjs CHANGED
@@ -186,6 +186,7 @@ async function runRelay(options) {
186
186
  level: logging.logLevel,
187
187
  output: process.stderr,
188
188
  name: PACKAGE_NAME,
189
+ filePath: logging.logFile,
189
190
  });
190
191
  const relayOptions = resolveRelayOptions(options);
191
192
  const relay = await startTcpRelay({
package/src/config.mjs CHANGED
@@ -78,6 +78,7 @@ export function loadLoggingConfig(env = process.env) {
78
78
  return {
79
79
  logLevel: parseLogLevel(env.MCP_BROWSER_LOG_LEVEL),
80
80
  debugStdio: isTruthyFlag(env.MCP_BROWSER_DEBUG_STDIO),
81
+ logFile: env.MCP_BROWSER_LOG_FILE?.trim() || null,
81
82
  };
82
83
  }
83
84
 
@@ -123,6 +124,7 @@ export function loadConfig(env = process.env) {
123
124
  ),
124
125
  logLevel: logging.logLevel,
125
126
  debugStdio: logging.debugStdio,
127
+ logFile: logging.logFile,
126
128
  protocolVersion:
127
129
  env.MCP_PROTOCOL_VERSION?.trim() || DEFAULT_PROTOCOL_VERSION,
128
130
  };
@@ -220,6 +220,21 @@ function normalizeFirefoxEvent(method, params = {}) {
220
220
  };
221
221
  }
222
222
 
223
+ if (
224
+ method === "browsingContext.userPromptOpened" ||
225
+ method === "browsingContext.userPromptClosed"
226
+ ) {
227
+ return {
228
+ kind: "dialog",
229
+ phase:
230
+ method === "browsingContext.userPromptOpened" ? "opened" : "closed",
231
+ dialogType: params.type ?? null,
232
+ message: params.message ?? null,
233
+ defaultValue: params.defaultValue ?? null,
234
+ context: params.context ?? null,
235
+ };
236
+ }
237
+
223
238
  return {
224
239
  kind: "raw",
225
240
  params,
@@ -656,6 +671,14 @@ export class FirefoxBidiSessionManager {
656
671
  return;
657
672
  }
658
673
 
674
+ if (message.method === "browsingContext.userPromptOpened") {
675
+ const accept = message.params?.type !== "prompt";
676
+ this.send("browsingContext.handleUserPrompt", {
677
+ context: contextId,
678
+ accept,
679
+ }).catch(() => {});
680
+ }
681
+
659
682
  for (const session of this.sessions.values()) {
660
683
  if (session.target.targetId === contextId) {
661
684
  session.bufferEvent(message.method, message.params ?? {});
@@ -774,6 +797,8 @@ export class FirefoxBidiSessionManager {
774
797
  "network.responseCompleted",
775
798
  "browsingContext.load",
776
799
  "browsingContext.contextDestroyed",
800
+ "browsingContext.userPromptOpened",
801
+ "browsingContext.userPromptClosed",
777
802
  ],
778
803
  contexts: [targetId],
779
804
  });
package/src/logger.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { appendFileSync } from "node:fs";
1
2
  import process from "node:process";
2
3
 
3
4
  import { PACKAGE_NAME } from "./package-info.mjs";
@@ -21,6 +22,7 @@ export function createLogger({
21
22
  level = "error",
22
23
  output = process.stderr,
23
24
  name = PACKAGE_NAME,
25
+ filePath = null,
24
26
  } = {}) {
25
27
  const threshold = LOG_LEVELS[level] ?? LOG_LEVELS.error;
26
28
 
@@ -34,7 +36,15 @@ export function createLogger({
34
36
  return false;
35
37
  }
36
38
 
37
- output.write(`[${name}] ${messageLevel}: ${normalizeMessage(message)}\n`);
39
+ const line = `[${name}] ${messageLevel}: ${normalizeMessage(message)}\n`;
40
+ output.write(line);
41
+ if (filePath != null) {
42
+ try {
43
+ appendFileSync(filePath, line);
44
+ } catch {
45
+ // ignore file write errors to avoid crashing the server
46
+ }
47
+ }
38
48
  return true;
39
49
  },
40
50
  error(message, options) {