mcp-browser-dev-tools 0.0.3 → 0.0.4
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 +1 -1
- package/src/app.mjs +21 -0
- package/src/cdp-client.mjs +23 -0
- package/src/firefox-bidi-client.mjs +25 -0
package/package.json
CHANGED
package/src/app.mjs
CHANGED
|
@@ -71,6 +71,27 @@ export function createBrowserDevToolsApp({
|
|
|
71
71
|
process.on("SIGTERM", () => {
|
|
72
72
|
void close("SIGTERM").finally(() => process.exit(0));
|
|
73
73
|
});
|
|
74
|
+
|
|
75
|
+
process.on("uncaughtException", (error) => {
|
|
76
|
+
logger.error(`uncaught exception: ${error?.stack ?? error}`, {
|
|
77
|
+
force: true,
|
|
78
|
+
});
|
|
79
|
+
void close("uncaughtException").finally(() => process.exit(1));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
process.on("unhandledRejection", (reason) => {
|
|
83
|
+
logger.error(
|
|
84
|
+
`unhandled rejection: ${reason instanceof Error ? (reason.stack ?? reason.message) : reason}`,
|
|
85
|
+
{ force: true },
|
|
86
|
+
);
|
|
87
|
+
void close("unhandledRejection").finally(() => process.exit(1));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
process.on("exit", (code) => {
|
|
91
|
+
if (code !== 0) {
|
|
92
|
+
logger.error(`process exiting with code ${code}`, { force: true });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
74
95
|
}
|
|
75
96
|
|
|
76
97
|
return {
|
package/src/cdp-client.mjs
CHANGED
|
@@ -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) {
|
|
@@ -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
|
});
|