mcp-browser-dev-tools 0.0.2-beta.0 → 0.0.2
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 +93 -139
- package/package.json +3 -1
- package/src/app.mjs +22 -1
- package/src/browser-adapter.mjs +27 -0
- package/src/browser-launch-service.mjs +515 -0
- package/src/cdp-client.mjs +261 -5
- package/src/cli.mjs +57 -202
- package/src/config.mjs +1 -1
- package/src/firefox-bidi-client.mjs +180 -16
- package/src/mcp-server.mjs +553 -0
- package/src/page-context.mjs +217 -0
- package/src/serve-bootstrap.mjs +290 -0
- package/src/session-events.mjs +83 -0
package/src/mcp-server.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { encodeMessage, MessageBuffer } from "./json-rpc-stdio.mjs";
|
|
2
2
|
import { createLogger } from "./logger.mjs";
|
|
3
|
+
import {
|
|
4
|
+
launchBrowser as launchLocalBrowser,
|
|
5
|
+
supportedLaunchFamilies,
|
|
6
|
+
} from "./browser-launch-service.mjs";
|
|
3
7
|
import { PACKAGE_NAME, PACKAGE_VERSION } from "./package-info.mjs";
|
|
4
8
|
|
|
5
9
|
const SERVER_NAME = PACKAGE_NAME;
|
|
@@ -211,6 +215,87 @@ function waitForInputSchema() {
|
|
|
211
215
|
};
|
|
212
216
|
}
|
|
213
217
|
|
|
218
|
+
function compareSessionsSchema(properties, required) {
|
|
219
|
+
return {
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: {
|
|
222
|
+
sessionIdA: {
|
|
223
|
+
type: "string",
|
|
224
|
+
},
|
|
225
|
+
sessionIdB: {
|
|
226
|
+
type: "string",
|
|
227
|
+
},
|
|
228
|
+
...properties,
|
|
229
|
+
},
|
|
230
|
+
required: ["sessionIdA", "sessionIdB", ...required],
|
|
231
|
+
additionalProperties: false,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function storageInputSchema() {
|
|
236
|
+
return {
|
|
237
|
+
type: "object",
|
|
238
|
+
properties: {
|
|
239
|
+
sessionId: {
|
|
240
|
+
type: "string",
|
|
241
|
+
},
|
|
242
|
+
area: {
|
|
243
|
+
type: "string",
|
|
244
|
+
enum: ["all", "localStorage", "sessionStorage"],
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
required: ["sessionId"],
|
|
248
|
+
additionalProperties: false,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function captureDebugReportInputSchema(browserFamily) {
|
|
253
|
+
return {
|
|
254
|
+
type: "object",
|
|
255
|
+
properties: {
|
|
256
|
+
sessionId: {
|
|
257
|
+
type: "string",
|
|
258
|
+
},
|
|
259
|
+
consoleLimit: {
|
|
260
|
+
type: "integer",
|
|
261
|
+
minimum: 1,
|
|
262
|
+
},
|
|
263
|
+
networkLimit: {
|
|
264
|
+
type: "integer",
|
|
265
|
+
minimum: 1,
|
|
266
|
+
},
|
|
267
|
+
includeScreenshot: {
|
|
268
|
+
type: "boolean",
|
|
269
|
+
},
|
|
270
|
+
screenshotFormat: {
|
|
271
|
+
type: "string",
|
|
272
|
+
enum: screenshotFormatsFor(browserFamily),
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
required: ["sessionId"],
|
|
276
|
+
additionalProperties: false,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function restoreSessionSnapshotInputSchema() {
|
|
281
|
+
return {
|
|
282
|
+
type: "object",
|
|
283
|
+
properties: {
|
|
284
|
+
sessionId: {
|
|
285
|
+
type: "string",
|
|
286
|
+
},
|
|
287
|
+
snapshot: {
|
|
288
|
+
type: "string",
|
|
289
|
+
},
|
|
290
|
+
clearStorage: {
|
|
291
|
+
type: "boolean",
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
required: ["sessionId", "snapshot"],
|
|
295
|
+
additionalProperties: false,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
214
299
|
function newTabInputSchema(browserFamily) {
|
|
215
300
|
const properties = {
|
|
216
301
|
url: {
|
|
@@ -235,10 +320,161 @@ function newTabInputSchema(browserFamily) {
|
|
|
235
320
|
};
|
|
236
321
|
}
|
|
237
322
|
|
|
323
|
+
function launchBrowserInputSchema(browserFamily) {
|
|
324
|
+
const properties = {
|
|
325
|
+
url: {
|
|
326
|
+
type: "string",
|
|
327
|
+
},
|
|
328
|
+
browserFamily: {
|
|
329
|
+
type: "string",
|
|
330
|
+
enum: supportedLaunchFamilies(browserFamily),
|
|
331
|
+
},
|
|
332
|
+
port: {
|
|
333
|
+
type: "integer",
|
|
334
|
+
minimum: 1,
|
|
335
|
+
},
|
|
336
|
+
address: {
|
|
337
|
+
type: "string",
|
|
338
|
+
},
|
|
339
|
+
userDataDir: {
|
|
340
|
+
type: "string",
|
|
341
|
+
},
|
|
342
|
+
waitMs: {
|
|
343
|
+
type: "integer",
|
|
344
|
+
minimum: 0,
|
|
345
|
+
},
|
|
346
|
+
skipDoctor: {
|
|
347
|
+
type: "boolean",
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
const required = browserFamily === "auto" ? ["browserFamily"] : [];
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
type: "object",
|
|
354
|
+
properties,
|
|
355
|
+
required,
|
|
356
|
+
additionalProperties: false,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function ensureBrowserInputSchema(browserFamily) {
|
|
361
|
+
return {
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
browserFamily: {
|
|
365
|
+
type: "string",
|
|
366
|
+
enum: supportedLaunchFamilies(browserFamily),
|
|
367
|
+
},
|
|
368
|
+
url: {
|
|
369
|
+
type: "string",
|
|
370
|
+
},
|
|
371
|
+
createTab: {
|
|
372
|
+
type: "boolean",
|
|
373
|
+
},
|
|
374
|
+
launchIfMissing: {
|
|
375
|
+
type: "boolean",
|
|
376
|
+
},
|
|
377
|
+
port: {
|
|
378
|
+
type: "integer",
|
|
379
|
+
minimum: 1,
|
|
380
|
+
},
|
|
381
|
+
address: {
|
|
382
|
+
type: "string",
|
|
383
|
+
},
|
|
384
|
+
userDataDir: {
|
|
385
|
+
type: "string",
|
|
386
|
+
},
|
|
387
|
+
waitMs: {
|
|
388
|
+
type: "integer",
|
|
389
|
+
minimum: 0,
|
|
390
|
+
},
|
|
391
|
+
skipDoctor: {
|
|
392
|
+
type: "boolean",
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
required: browserFamily === "auto" ? ["browserFamily"] : [],
|
|
396
|
+
additionalProperties: false,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function requestedBrowserFamily(configuredFamily, requestedFamily) {
|
|
401
|
+
if (requestedFamily) {
|
|
402
|
+
return requestedFamily;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return configuredFamily === "auto" ? null : configuredFamily;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function isRequestedBrowserAvailable(
|
|
409
|
+
status,
|
|
410
|
+
configuredFamily,
|
|
411
|
+
requestedFamily,
|
|
412
|
+
) {
|
|
413
|
+
if (configuredFamily !== "auto" || !requestedFamily) {
|
|
414
|
+
return Boolean(status?.available);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return Boolean(status?.browsers?.[requestedFamily]?.available);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function shouldCreateBrowserTab(args) {
|
|
421
|
+
if (args.createTab !== undefined) {
|
|
422
|
+
return args.createTab;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return typeof args.url === "string" && args.url.trim() !== "";
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function sameValue(left, right) {
|
|
429
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function compareField(left, right) {
|
|
433
|
+
return {
|
|
434
|
+
equal: sameValue(left, right),
|
|
435
|
+
a: left,
|
|
436
|
+
b: right,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function summarizeComparablePageState(page = {}) {
|
|
441
|
+
return {
|
|
442
|
+
browserFamily: page.browserFamily ?? null,
|
|
443
|
+
url: page.url ?? null,
|
|
444
|
+
title: page.title ?? null,
|
|
445
|
+
readyState: page.readyState ?? null,
|
|
446
|
+
visibilityState: page.visibilityState ?? null,
|
|
447
|
+
viewport: page.viewport ?? null,
|
|
448
|
+
scroll: page.scroll ?? null,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function summarizeComparableElement(result = {}) {
|
|
453
|
+
if (!result.found || !result.node) {
|
|
454
|
+
return {
|
|
455
|
+
found: false,
|
|
456
|
+
selector: result.selector ?? null,
|
|
457
|
+
error: result.error ?? null,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return {
|
|
462
|
+
found: true,
|
|
463
|
+
selector: result.selector ?? null,
|
|
464
|
+
tagName: result.node.tagName ?? null,
|
|
465
|
+
accessibleName: result.node.accessibleName ?? null,
|
|
466
|
+
role: result.node.role ?? null,
|
|
467
|
+
visible: result.node.visible ?? null,
|
|
468
|
+
disabled: result.node.disabled ?? null,
|
|
469
|
+
textContent: result.node.textContent ?? null,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
238
473
|
export class McpBrowserDevToolsServer {
|
|
239
474
|
constructor({
|
|
240
475
|
config,
|
|
241
476
|
browserAdapter,
|
|
477
|
+
launchBrowser = launchLocalBrowser,
|
|
242
478
|
input = process.stdin,
|
|
243
479
|
output = process.stdout,
|
|
244
480
|
errorOutput = process.stderr,
|
|
@@ -250,6 +486,7 @@ export class McpBrowserDevToolsServer {
|
|
|
250
486
|
}) {
|
|
251
487
|
this.config = config;
|
|
252
488
|
this.browserAdapter = browserAdapter;
|
|
489
|
+
this.launchBrowser = launchBrowser;
|
|
253
490
|
this.input = input;
|
|
254
491
|
this.output = output;
|
|
255
492
|
this.errorOutput = errorOutput;
|
|
@@ -290,6 +527,97 @@ export class McpBrowserDevToolsServer {
|
|
|
290
527
|
}),
|
|
291
528
|
},
|
|
292
529
|
],
|
|
530
|
+
[
|
|
531
|
+
"launch_browser",
|
|
532
|
+
{
|
|
533
|
+
definition: {
|
|
534
|
+
name: "launch_browser",
|
|
535
|
+
description:
|
|
536
|
+
"Launch a local debug-enabled browser process that matches the current broker configuration and return launch details plus an optional doctor report.",
|
|
537
|
+
inputSchema: launchBrowserInputSchema(this.config.browserFamily),
|
|
538
|
+
},
|
|
539
|
+
handler: async (args) =>
|
|
540
|
+
this.launchBrowser({
|
|
541
|
+
config: this.config,
|
|
542
|
+
browserFamily: args.browserFamily,
|
|
543
|
+
url: args.url,
|
|
544
|
+
port: args.port,
|
|
545
|
+
address: args.address,
|
|
546
|
+
userDataDir: args.userDataDir,
|
|
547
|
+
waitMs: args.waitMs,
|
|
548
|
+
skipDoctor: args.skipDoctor,
|
|
549
|
+
}),
|
|
550
|
+
},
|
|
551
|
+
],
|
|
552
|
+
[
|
|
553
|
+
"ensure_browser",
|
|
554
|
+
{
|
|
555
|
+
definition: {
|
|
556
|
+
name: "ensure_browser",
|
|
557
|
+
description:
|
|
558
|
+
"Ensure a compatible browser is reachable through the current broker. If needed, launch one locally and optionally open a tab for the requested URL.",
|
|
559
|
+
inputSchema: ensureBrowserInputSchema(this.config.browserFamily),
|
|
560
|
+
},
|
|
561
|
+
handler: async (args) => {
|
|
562
|
+
const browserFamily = requestedBrowserFamily(
|
|
563
|
+
this.config.browserFamily,
|
|
564
|
+
args.browserFamily,
|
|
565
|
+
);
|
|
566
|
+
const currentStatus = await this.browserAdapter.getBrowserStatus();
|
|
567
|
+
const available = isRequestedBrowserAvailable(
|
|
568
|
+
currentStatus,
|
|
569
|
+
this.config.browserFamily,
|
|
570
|
+
browserFamily,
|
|
571
|
+
);
|
|
572
|
+
let launch = null;
|
|
573
|
+
let status = currentStatus;
|
|
574
|
+
|
|
575
|
+
if (!available) {
|
|
576
|
+
if (args.launchIfMissing === false) {
|
|
577
|
+
return {
|
|
578
|
+
browserFamily,
|
|
579
|
+
available: false,
|
|
580
|
+
launched: false,
|
|
581
|
+
status,
|
|
582
|
+
tab: null,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
launch = await this.launchBrowser({
|
|
587
|
+
config: this.config,
|
|
588
|
+
browserFamily,
|
|
589
|
+
url: args.url,
|
|
590
|
+
port: args.port,
|
|
591
|
+
address: args.address,
|
|
592
|
+
userDataDir: args.userDataDir,
|
|
593
|
+
waitMs: args.waitMs,
|
|
594
|
+
skipDoctor: args.skipDoctor,
|
|
595
|
+
});
|
|
596
|
+
status = await this.browserAdapter.getBrowserStatus();
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
let tab = null;
|
|
600
|
+
if (shouldCreateBrowserTab(args)) {
|
|
601
|
+
tab = await this.browserAdapter.createTab(args.url, {
|
|
602
|
+
browserFamily,
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return {
|
|
607
|
+
browserFamily,
|
|
608
|
+
available: isRequestedBrowserAvailable(
|
|
609
|
+
status,
|
|
610
|
+
this.config.browserFamily,
|
|
611
|
+
browserFamily,
|
|
612
|
+
),
|
|
613
|
+
launched: Boolean(launch),
|
|
614
|
+
launch,
|
|
615
|
+
status,
|
|
616
|
+
tab,
|
|
617
|
+
};
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
],
|
|
293
621
|
[
|
|
294
622
|
"list_sessions",
|
|
295
623
|
{
|
|
@@ -399,6 +727,111 @@ export class McpBrowserDevToolsServer {
|
|
|
399
727
|
this.browserAdapter.getPageState(args.sessionId),
|
|
400
728
|
},
|
|
401
729
|
],
|
|
730
|
+
[
|
|
731
|
+
"compare_page_state",
|
|
732
|
+
{
|
|
733
|
+
definition: {
|
|
734
|
+
name: "compare_page_state",
|
|
735
|
+
description:
|
|
736
|
+
"Compare bounded page state across two attached sessions, useful for cross-browser checks in auto mode.",
|
|
737
|
+
inputSchema: compareSessionsSchema({}, []),
|
|
738
|
+
},
|
|
739
|
+
handler: async (args) => {
|
|
740
|
+
const [pageA, pageB] = await Promise.all([
|
|
741
|
+
this.browserAdapter.getPageState(args.sessionIdA),
|
|
742
|
+
this.browserAdapter.getPageState(args.sessionIdB),
|
|
743
|
+
]);
|
|
744
|
+
const left = summarizeComparablePageState(pageA);
|
|
745
|
+
const right = summarizeComparablePageState(pageB);
|
|
746
|
+
const fields = {
|
|
747
|
+
browserFamily: compareField(
|
|
748
|
+
left.browserFamily,
|
|
749
|
+
right.browserFamily,
|
|
750
|
+
),
|
|
751
|
+
url: compareField(left.url, right.url),
|
|
752
|
+
title: compareField(left.title, right.title),
|
|
753
|
+
readyState: compareField(left.readyState, right.readyState),
|
|
754
|
+
visibilityState: compareField(
|
|
755
|
+
left.visibilityState,
|
|
756
|
+
right.visibilityState,
|
|
757
|
+
),
|
|
758
|
+
viewport: compareField(left.viewport, right.viewport),
|
|
759
|
+
scroll: compareField(left.scroll, right.scroll),
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
return {
|
|
763
|
+
matches: Object.values(fields).every((field) => field.equal),
|
|
764
|
+
a: left,
|
|
765
|
+
b: right,
|
|
766
|
+
fields,
|
|
767
|
+
};
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
],
|
|
771
|
+
[
|
|
772
|
+
"compare_selector",
|
|
773
|
+
{
|
|
774
|
+
definition: {
|
|
775
|
+
name: "compare_selector",
|
|
776
|
+
description:
|
|
777
|
+
"Compare a selector across two attached sessions using a bounded element summary.",
|
|
778
|
+
inputSchema: compareSessionsSchema(
|
|
779
|
+
{
|
|
780
|
+
selector: {
|
|
781
|
+
type: "string",
|
|
782
|
+
},
|
|
783
|
+
},
|
|
784
|
+
["selector"],
|
|
785
|
+
),
|
|
786
|
+
},
|
|
787
|
+
handler: async (args) => {
|
|
788
|
+
const [elementA, elementB] = await Promise.all([
|
|
789
|
+
this.browserAdapter.inspectElement(
|
|
790
|
+
args.sessionIdA,
|
|
791
|
+
args.selector,
|
|
792
|
+
),
|
|
793
|
+
this.browserAdapter.inspectElement(
|
|
794
|
+
args.sessionIdB,
|
|
795
|
+
args.selector,
|
|
796
|
+
),
|
|
797
|
+
]);
|
|
798
|
+
const left = summarizeComparableElement(elementA);
|
|
799
|
+
const right = summarizeComparableElement(elementB);
|
|
800
|
+
const fields = {
|
|
801
|
+
found: compareField(left.found, right.found),
|
|
802
|
+
tagName: compareField(
|
|
803
|
+
left.tagName ?? null,
|
|
804
|
+
right.tagName ?? null,
|
|
805
|
+
),
|
|
806
|
+
accessibleName: compareField(
|
|
807
|
+
left.accessibleName ?? null,
|
|
808
|
+
right.accessibleName ?? null,
|
|
809
|
+
),
|
|
810
|
+
role: compareField(left.role ?? null, right.role ?? null),
|
|
811
|
+
visible: compareField(
|
|
812
|
+
left.visible ?? null,
|
|
813
|
+
right.visible ?? null,
|
|
814
|
+
),
|
|
815
|
+
disabled: compareField(
|
|
816
|
+
left.disabled ?? null,
|
|
817
|
+
right.disabled ?? null,
|
|
818
|
+
),
|
|
819
|
+
textContent: compareField(
|
|
820
|
+
left.textContent ?? null,
|
|
821
|
+
right.textContent ?? null,
|
|
822
|
+
),
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
return {
|
|
826
|
+
selector: args.selector,
|
|
827
|
+
matches: Object.values(fields).every((field) => field.equal),
|
|
828
|
+
a: left,
|
|
829
|
+
b: right,
|
|
830
|
+
fields,
|
|
831
|
+
};
|
|
832
|
+
},
|
|
833
|
+
},
|
|
834
|
+
],
|
|
402
835
|
[
|
|
403
836
|
"wait_for",
|
|
404
837
|
{
|
|
@@ -436,6 +869,126 @@ export class McpBrowserDevToolsServer {
|
|
|
436
869
|
},
|
|
437
870
|
},
|
|
438
871
|
],
|
|
872
|
+
[
|
|
873
|
+
"get_cookies",
|
|
874
|
+
{
|
|
875
|
+
definition: {
|
|
876
|
+
name: "get_cookies",
|
|
877
|
+
description:
|
|
878
|
+
"Read bounded page-visible cookies for the attached session.",
|
|
879
|
+
inputSchema: sessionSchema({}, []),
|
|
880
|
+
},
|
|
881
|
+
handler: async (args) =>
|
|
882
|
+
this.browserAdapter.getCookies(args.sessionId),
|
|
883
|
+
},
|
|
884
|
+
],
|
|
885
|
+
[
|
|
886
|
+
"get_storage",
|
|
887
|
+
{
|
|
888
|
+
definition: {
|
|
889
|
+
name: "get_storage",
|
|
890
|
+
description:
|
|
891
|
+
"Read bounded localStorage and sessionStorage entries for the attached session.",
|
|
892
|
+
inputSchema: storageInputSchema(),
|
|
893
|
+
},
|
|
894
|
+
handler: async (args) => {
|
|
895
|
+
const result = await this.browserAdapter.getStorage(args.sessionId);
|
|
896
|
+
if (!args.area || args.area === "all") {
|
|
897
|
+
return result;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
return {
|
|
901
|
+
browserFamily: result.browserFamily,
|
|
902
|
+
storage: {
|
|
903
|
+
[args.area]: result.storage?.[args.area] ?? null,
|
|
904
|
+
},
|
|
905
|
+
};
|
|
906
|
+
},
|
|
907
|
+
},
|
|
908
|
+
],
|
|
909
|
+
[
|
|
910
|
+
"capture_debug_report",
|
|
911
|
+
{
|
|
912
|
+
definition: {
|
|
913
|
+
name: "capture_debug_report",
|
|
914
|
+
description:
|
|
915
|
+
"Capture a bounded debug bundle with page state, cookies/storage summary, recent console, recent network, and an optional screenshot.",
|
|
916
|
+
inputSchema: captureDebugReportInputSchema(
|
|
917
|
+
this.config.browserFamily,
|
|
918
|
+
),
|
|
919
|
+
},
|
|
920
|
+
handler: async (args) =>
|
|
921
|
+
this.browserAdapter.captureDebugReport(args.sessionId, {
|
|
922
|
+
consoleLimit: args.consoleLimit,
|
|
923
|
+
networkLimit: args.networkLimit,
|
|
924
|
+
includeScreenshot: args.includeScreenshot,
|
|
925
|
+
screenshotFormat: args.screenshotFormat,
|
|
926
|
+
}),
|
|
927
|
+
},
|
|
928
|
+
],
|
|
929
|
+
[
|
|
930
|
+
"capture_session_snapshot",
|
|
931
|
+
{
|
|
932
|
+
definition: {
|
|
933
|
+
name: "capture_session_snapshot",
|
|
934
|
+
description:
|
|
935
|
+
"Capture a bounded session snapshot with page state, cookies, and web storage for later bounded restore on the same origin.",
|
|
936
|
+
inputSchema: sessionSchema({}, []),
|
|
937
|
+
},
|
|
938
|
+
handler: async (args) =>
|
|
939
|
+
this.browserAdapter.captureSessionSnapshot(args.sessionId),
|
|
940
|
+
},
|
|
941
|
+
],
|
|
942
|
+
[
|
|
943
|
+
"restore_session_snapshot",
|
|
944
|
+
{
|
|
945
|
+
definition: {
|
|
946
|
+
name: "restore_session_snapshot",
|
|
947
|
+
description:
|
|
948
|
+
"Restore a bounded session snapshot into the currently attached page context. Restores only page-visible cookies plus localStorage/sessionStorage on the current origin.",
|
|
949
|
+
inputSchema: restoreSessionSnapshotInputSchema(),
|
|
950
|
+
},
|
|
951
|
+
handler: async (args) => {
|
|
952
|
+
let snapshot;
|
|
953
|
+
try {
|
|
954
|
+
snapshot = JSON.parse(args.snapshot);
|
|
955
|
+
} catch {
|
|
956
|
+
throw new Error(
|
|
957
|
+
"restore_session_snapshot snapshot must be valid JSON",
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
if (!snapshot || typeof snapshot !== "object") {
|
|
962
|
+
throw new Error(
|
|
963
|
+
"restore_session_snapshot snapshot must decode to an object",
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
return this.browserAdapter.restoreSessionSnapshot(
|
|
968
|
+
args.sessionId,
|
|
969
|
+
snapshot,
|
|
970
|
+
{
|
|
971
|
+
clearStorage: args.clearStorage,
|
|
972
|
+
},
|
|
973
|
+
);
|
|
974
|
+
},
|
|
975
|
+
},
|
|
976
|
+
],
|
|
977
|
+
[
|
|
978
|
+
"get_har",
|
|
979
|
+
{
|
|
980
|
+
definition: {
|
|
981
|
+
name: "get_har",
|
|
982
|
+
description:
|
|
983
|
+
"Export a bounded HAR-like summary from buffered network activity for an attached session.",
|
|
984
|
+
inputSchema: sessionWithLimitSchema(),
|
|
985
|
+
},
|
|
986
|
+
handler: async (args) =>
|
|
987
|
+
this.browserAdapter.getHar(args.sessionId, {
|
|
988
|
+
limit: args.limit ?? 50,
|
|
989
|
+
}),
|
|
990
|
+
},
|
|
991
|
+
],
|
|
439
992
|
[
|
|
440
993
|
"navigate",
|
|
441
994
|
{
|