mcp-browser-dev-tools 0.1.0 → 0.2.0
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 +90 -355
- package/package.json +16 -2
- package/src/action-retry.mjs +50 -0
- package/src/browser-adapter.mjs +15 -4
- package/src/browser-requests.mjs +15 -0
- package/src/cdp-client.mjs +104 -10
- package/src/firefox-bidi-client.mjs +26 -3
- package/src/json-schema.mjs +99 -0
- package/src/mcp-server.mjs +34 -2013
- package/src/page-context.mjs +25 -1034
- package/src/page-script.mjs +1372 -0
- package/src/run-steps.mjs +510 -0
- package/src/run-tabs.mjs +291 -0
- package/src/screenshot-output.mjs +141 -0
- package/src/tool-results.mjs +34 -0
- package/src/tool-schemas.mjs +431 -0
- package/src/tools/action-tools.mjs +318 -0
- package/src/tools/browser-tools.mjs +221 -0
- package/src/tools/inspection-tools.mjs +287 -0
- package/src/tools/state-tools.mjs +327 -0
- package/src/top-level-await.mjs +260 -0
- package/src/wait-for.mjs +381 -71
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { DEFAULT_ACTION_TIMEOUT_MS } from "./action-retry.mjs";
|
|
2
|
+
import { supportedLaunchFamilies } from "./browser-launch-service.mjs";
|
|
3
|
+
import { screenshotFormatsFor } from "./screenshot-output.mjs";
|
|
4
|
+
|
|
5
|
+
export function emptyObjectSchema() {
|
|
6
|
+
return {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {},
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function sessionWithLimitSchema(description) {
|
|
14
|
+
return {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
sessionId: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Session id returned by attach_tab.",
|
|
20
|
+
},
|
|
21
|
+
limit: {
|
|
22
|
+
type: "integer",
|
|
23
|
+
minimum: 1,
|
|
24
|
+
description:
|
|
25
|
+
"Return the most recent N entries from the session buffer (default 50).",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
required: ["sessionId"],
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
description,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const LOCATOR_DESCRIPTION =
|
|
35
|
+
'Element locator. Plain CSS (or css=...) resolves to the first document.querySelector match. text=Foo resolves to the first visible element whose whitespace-normalized text equals Foo, falling back to the first whose text contains Foo; elements are scanned in document order, so this can resolve to a wrapper around the element you want. role=button or role=button[name="Save"] matches by explicit or implicit ARIA role and, optionally, accessible name (equal or containing), without a visibility check. name=Foo resolves to the first visible element whose accessible name (aria-label, aria-labelledby, associated label, alt, and so on) equals or contains Foo. Text comparisons are case-sensitive. Only the top-level document is searched: elements inside iframes or shadow roots are not found.';
|
|
36
|
+
|
|
37
|
+
export function selectorProperty() {
|
|
38
|
+
return {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: LOCATOR_DESCRIPTION,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function sessionSchema(properties, required, description) {
|
|
45
|
+
return {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
sessionId: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "Session id returned by attach_tab.",
|
|
51
|
+
},
|
|
52
|
+
...properties,
|
|
53
|
+
},
|
|
54
|
+
required: ["sessionId", ...required],
|
|
55
|
+
additionalProperties: false,
|
|
56
|
+
description,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function waitUntilProperty() {
|
|
61
|
+
return {
|
|
62
|
+
type: "string",
|
|
63
|
+
enum: ["none", "interactive", "complete"],
|
|
64
|
+
description:
|
|
65
|
+
"When to return: none returns once navigation starts, interactive after DOMContentLoaded, complete after the load event (default complete).",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// With expression, conditions also take a JavaScript expression; it is left
|
|
70
|
+
// out when evaluate_js is turned off.
|
|
71
|
+
export function pageConditionProperties({ expression = false } = {}) {
|
|
72
|
+
return {
|
|
73
|
+
selector: selectorProperty(),
|
|
74
|
+
state: {
|
|
75
|
+
type: "string",
|
|
76
|
+
enum: ["present", "visible", "hidden"],
|
|
77
|
+
description:
|
|
78
|
+
"Selector state (default visible). present: in the DOM. hidden: absent or not visible. Requires selector.",
|
|
79
|
+
},
|
|
80
|
+
url: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "The page URL equals this string exactly.",
|
|
83
|
+
},
|
|
84
|
+
urlIncludes: {
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "The page URL contains this string.",
|
|
87
|
+
},
|
|
88
|
+
readyState: {
|
|
89
|
+
type: "string",
|
|
90
|
+
enum: ["interactive", "complete"],
|
|
91
|
+
description: "document.readyState has reached this state or later.",
|
|
92
|
+
},
|
|
93
|
+
textEquals: {
|
|
94
|
+
type: "string",
|
|
95
|
+
description:
|
|
96
|
+
"The selector's full visible text equals this string, comparing with whitespace collapsed. Requires selector; not with state hidden.",
|
|
97
|
+
},
|
|
98
|
+
textIncludes: {
|
|
99
|
+
type: "string",
|
|
100
|
+
description:
|
|
101
|
+
"The selector's full visible text contains this string, comparing with whitespace collapsed. Requires selector; not with state hidden.",
|
|
102
|
+
},
|
|
103
|
+
textExcludes: {
|
|
104
|
+
type: "string",
|
|
105
|
+
description:
|
|
106
|
+
"The selector's visible text does not contain this string, for example to wait until a status no longer says Processing. Never holds for a missing element. Requires selector; not with state hidden.",
|
|
107
|
+
},
|
|
108
|
+
...(expression
|
|
109
|
+
? {
|
|
110
|
+
expression: {
|
|
111
|
+
type: "string",
|
|
112
|
+
description:
|
|
113
|
+
"JavaScript expression evaluated in the page's main world; holds when its result, awaited if it is a promise, is truthy, for example document.querySelectorAll('.row').length >= 5. An expression that throws fails the check. Each evaluation must settle within the wait's remaining time, or 5000ms in if and repeat.",
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
: {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function conditionSchema(options) {
|
|
121
|
+
return {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
...pageConditionProperties(options),
|
|
125
|
+
anyOf: anyOfProperty(options),
|
|
126
|
+
},
|
|
127
|
+
additionalProperties: false,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function anyOfProperty(options) {
|
|
132
|
+
return {
|
|
133
|
+
type: "array",
|
|
134
|
+
minItems: 1,
|
|
135
|
+
items: {
|
|
136
|
+
type: "object",
|
|
137
|
+
properties: pageConditionProperties(options),
|
|
138
|
+
additionalProperties: false,
|
|
139
|
+
},
|
|
140
|
+
description:
|
|
141
|
+
"Alternative conditions, each with the fields above; holds when any one holds, checked in order. Use instead of the fields above, for example to wait until a status says either Paid or Declined. The result reports matchedIndex.",
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function waitForInputSchema(options) {
|
|
146
|
+
return {
|
|
147
|
+
type: "object",
|
|
148
|
+
properties: {
|
|
149
|
+
sessionId: {
|
|
150
|
+
type: "string",
|
|
151
|
+
description: "Session id returned by attach_tab.",
|
|
152
|
+
},
|
|
153
|
+
...pageConditionProperties(options),
|
|
154
|
+
anyOf: anyOfProperty(options),
|
|
155
|
+
timeoutMs: {
|
|
156
|
+
type: "integer",
|
|
157
|
+
minimum: 1,
|
|
158
|
+
description: "How long to wait before failing (default 10000).",
|
|
159
|
+
},
|
|
160
|
+
pollIntervalMs: {
|
|
161
|
+
type: "integer",
|
|
162
|
+
minimum: 1,
|
|
163
|
+
description: "Delay between checks (default 100).",
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
required: ["sessionId"],
|
|
167
|
+
additionalProperties: false,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function actionTimeoutProperty(what) {
|
|
172
|
+
return {
|
|
173
|
+
type: "integer",
|
|
174
|
+
minimum: 0,
|
|
175
|
+
maximum: 30_000,
|
|
176
|
+
description: `How long to keep retrying while the element is missing${what}, before failing (default ${DEFAULT_ACTION_TIMEOUT_MS}; 0 fails at once).`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function compareSessionsSchema(properties, required) {
|
|
181
|
+
return {
|
|
182
|
+
type: "object",
|
|
183
|
+
properties: {
|
|
184
|
+
sessionIdA: {
|
|
185
|
+
type: "string",
|
|
186
|
+
description: "Session id returned by attach_tab.",
|
|
187
|
+
},
|
|
188
|
+
sessionIdB: {
|
|
189
|
+
type: "string",
|
|
190
|
+
description: "Session id returned by attach_tab.",
|
|
191
|
+
},
|
|
192
|
+
...properties,
|
|
193
|
+
},
|
|
194
|
+
required: ["sessionIdA", "sessionIdB", ...required],
|
|
195
|
+
additionalProperties: false,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function storageInputSchema() {
|
|
200
|
+
return {
|
|
201
|
+
type: "object",
|
|
202
|
+
properties: {
|
|
203
|
+
sessionId: {
|
|
204
|
+
type: "string",
|
|
205
|
+
description: "Session id returned by attach_tab.",
|
|
206
|
+
},
|
|
207
|
+
area: {
|
|
208
|
+
type: "string",
|
|
209
|
+
enum: ["all", "localStorage", "sessionStorage"],
|
|
210
|
+
description: "Which storage to return (default all).",
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
required: ["sessionId"],
|
|
214
|
+
additionalProperties: false,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function captureDebugReportInputSchema(browserFamily) {
|
|
219
|
+
return {
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: {
|
|
222
|
+
sessionId: {
|
|
223
|
+
type: "string",
|
|
224
|
+
description: "Session id returned by attach_tab.",
|
|
225
|
+
},
|
|
226
|
+
consoleLimit: {
|
|
227
|
+
type: "integer",
|
|
228
|
+
minimum: 1,
|
|
229
|
+
description: "Most recent console entries to include (default 20).",
|
|
230
|
+
},
|
|
231
|
+
networkLimit: {
|
|
232
|
+
type: "integer",
|
|
233
|
+
minimum: 1,
|
|
234
|
+
description: "Most recent network requests to include (default 20).",
|
|
235
|
+
},
|
|
236
|
+
includeScreenshot: {
|
|
237
|
+
type: "boolean",
|
|
238
|
+
description: "Include a viewport screenshot (default true).",
|
|
239
|
+
},
|
|
240
|
+
screenshotFormat: {
|
|
241
|
+
type: "string",
|
|
242
|
+
enum: screenshotFormatsFor(browserFamily),
|
|
243
|
+
description: "Screenshot image format (default png).",
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
required: ["sessionId"],
|
|
247
|
+
additionalProperties: false,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function restoreSessionSnapshotInputSchema() {
|
|
252
|
+
return {
|
|
253
|
+
type: "object",
|
|
254
|
+
properties: {
|
|
255
|
+
sessionId: {
|
|
256
|
+
type: "string",
|
|
257
|
+
description: "Session id returned by attach_tab.",
|
|
258
|
+
},
|
|
259
|
+
snapshot: {
|
|
260
|
+
type: "string",
|
|
261
|
+
description:
|
|
262
|
+
"The JSON output of capture_session_snapshot, as a string. Only entries for the current page origin are restored.",
|
|
263
|
+
},
|
|
264
|
+
clearStorage: {
|
|
265
|
+
type: "boolean",
|
|
266
|
+
description:
|
|
267
|
+
"Clear localStorage and sessionStorage before restoring (default false).",
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
required: ["sessionId", "snapshot"],
|
|
271
|
+
additionalProperties: false,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function newTabInputSchema(browserFamily) {
|
|
276
|
+
const properties = {
|
|
277
|
+
url: {
|
|
278
|
+
type: "string",
|
|
279
|
+
description: "URL to open (default about:blank).",
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
const required = [];
|
|
283
|
+
|
|
284
|
+
if (browserFamily === "auto") {
|
|
285
|
+
properties.browserFamily = {
|
|
286
|
+
type: "string",
|
|
287
|
+
enum: ["chromium", "firefox"],
|
|
288
|
+
description: "Browser to open the tab in.",
|
|
289
|
+
};
|
|
290
|
+
required.push("browserFamily");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return {
|
|
294
|
+
type: "object",
|
|
295
|
+
properties,
|
|
296
|
+
required,
|
|
297
|
+
additionalProperties: false,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function unsafeArgsProperty() {
|
|
302
|
+
return {
|
|
303
|
+
type: "array",
|
|
304
|
+
items: {
|
|
305
|
+
type: "string",
|
|
306
|
+
},
|
|
307
|
+
description:
|
|
308
|
+
"Extra browser command-line flags, each starting with -. Flags that conflict with broker-managed launch options (debugging port, address, profile) are rejected.",
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function launchBrowserInputSchema(
|
|
313
|
+
browserFamily,
|
|
314
|
+
enableUnsafeLaunchArgs,
|
|
315
|
+
) {
|
|
316
|
+
const properties = {
|
|
317
|
+
url: {
|
|
318
|
+
type: "string",
|
|
319
|
+
description: "URL to open in the launched browser (default about:blank).",
|
|
320
|
+
},
|
|
321
|
+
browserFamily: {
|
|
322
|
+
type: "string",
|
|
323
|
+
enum: supportedLaunchFamilies(browserFamily),
|
|
324
|
+
description:
|
|
325
|
+
"Browser to launch. Required when the broker runs in auto mode.",
|
|
326
|
+
},
|
|
327
|
+
port: {
|
|
328
|
+
type: "integer",
|
|
329
|
+
minimum: 1,
|
|
330
|
+
description:
|
|
331
|
+
"Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
|
|
332
|
+
},
|
|
333
|
+
address: {
|
|
334
|
+
type: "string",
|
|
335
|
+
description:
|
|
336
|
+
"Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
|
|
337
|
+
},
|
|
338
|
+
userDataDir: {
|
|
339
|
+
type: "string",
|
|
340
|
+
description:
|
|
341
|
+
"Browser profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR when set). Without either, Chromium and Edge get a fresh temporary profile if that browser is already running, and the default profile otherwise.",
|
|
342
|
+
},
|
|
343
|
+
waitMs: {
|
|
344
|
+
type: "integer",
|
|
345
|
+
minimum: 0,
|
|
346
|
+
description:
|
|
347
|
+
"How long to wait for the debugging endpoint to answer after launch (default 5000).",
|
|
348
|
+
},
|
|
349
|
+
skipDoctor: {
|
|
350
|
+
type: "boolean",
|
|
351
|
+
description:
|
|
352
|
+
"Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
if (enableUnsafeLaunchArgs) {
|
|
356
|
+
properties.unsafeArgs = unsafeArgsProperty();
|
|
357
|
+
}
|
|
358
|
+
const required = browserFamily === "auto" ? ["browserFamily"] : [];
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
type: "object",
|
|
362
|
+
properties,
|
|
363
|
+
required,
|
|
364
|
+
additionalProperties: false,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export function ensureBrowserInputSchema(
|
|
369
|
+
browserFamily,
|
|
370
|
+
enableUnsafeLaunchArgs,
|
|
371
|
+
) {
|
|
372
|
+
const properties = {
|
|
373
|
+
browserFamily: {
|
|
374
|
+
type: "string",
|
|
375
|
+
enum: supportedLaunchFamilies(browserFamily),
|
|
376
|
+
description:
|
|
377
|
+
"Browser to check or launch. Required when the broker runs in auto mode.",
|
|
378
|
+
},
|
|
379
|
+
url: {
|
|
380
|
+
type: "string",
|
|
381
|
+
description: "URL to open in a new tab once the browser is reachable.",
|
|
382
|
+
},
|
|
383
|
+
createTab: {
|
|
384
|
+
type: "boolean",
|
|
385
|
+
description:
|
|
386
|
+
"Open a tab after the browser is reachable (default: true when url is given).",
|
|
387
|
+
},
|
|
388
|
+
launchIfMissing: {
|
|
389
|
+
type: "boolean",
|
|
390
|
+
description:
|
|
391
|
+
"Launch a browser when none is reachable (default true). When false and none is reachable, return the status without launching or opening a tab.",
|
|
392
|
+
},
|
|
393
|
+
port: {
|
|
394
|
+
type: "integer",
|
|
395
|
+
minimum: 1,
|
|
396
|
+
description:
|
|
397
|
+
"Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
|
|
398
|
+
},
|
|
399
|
+
address: {
|
|
400
|
+
type: "string",
|
|
401
|
+
description:
|
|
402
|
+
"Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
|
|
403
|
+
},
|
|
404
|
+
userDataDir: {
|
|
405
|
+
type: "string",
|
|
406
|
+
description:
|
|
407
|
+
"Browser profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR when set). Without either, Chromium and Edge get a fresh temporary profile if that browser is already running, and the default profile otherwise.",
|
|
408
|
+
},
|
|
409
|
+
waitMs: {
|
|
410
|
+
type: "integer",
|
|
411
|
+
minimum: 0,
|
|
412
|
+
description:
|
|
413
|
+
"How long to wait for the debugging endpoint to answer after launch (default 5000).",
|
|
414
|
+
},
|
|
415
|
+
skipDoctor: {
|
|
416
|
+
type: "boolean",
|
|
417
|
+
description:
|
|
418
|
+
"Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
if (enableUnsafeLaunchArgs) {
|
|
422
|
+
properties.unsafeArgs = unsafeArgsProperty();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return {
|
|
426
|
+
type: "object",
|
|
427
|
+
properties,
|
|
428
|
+
required: browserFamily === "auto" ? ["browserFamily"] : [],
|
|
429
|
+
additionalProperties: false,
|
|
430
|
+
};
|
|
431
|
+
}
|