cdp-toolkit 3.0.3 → 3.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/CHANGELOG.md +28 -0
- package/CONTRACT.md +2 -2
- package/README.md +122 -1
- package/dist/bidi/mux-daemon.js +675 -130
- package/dist/cli.js +1432 -635
- package/dist/index.js +1110 -116
- package/dist/mcp.js +1474 -658
- package/package.json +3 -1
- package/src/bidi/snapshot.ts +123 -113
- package/src/cdp/driver.ts +55 -41
- package/src/cdp/endpoint.ts +200 -0
- package/src/cdp/session.ts +246 -0
- package/src/cli.ts +17 -4
- package/src/client.ts +140 -16
- package/src/endpoints.ts +428 -0
- package/src/leases-tools.ts +6 -3
- package/src/leases.ts +28 -4
- package/src/manifest.ts +54 -42
- package/src/mcp.ts +52 -8
- package/src/origins.ts +5 -2
- package/src/policy.ts +163 -0
- package/src/reap.ts +14 -0
- package/src/shared-tools.ts +164 -25
- package/src/toolDocs.ts +41 -38
- package/src/tools/browser-session.ts +26 -12
- package/src/tools/dispatch-mouse.ts +2 -1
- package/src/tools/evaluate.ts +3 -3
- package/src/tools/focus-emulation.ts +5 -3
- package/src/tools/lighthouse.ts +4 -2
- package/src/tools/navigation.ts +3 -3
- package/src/tools/network_mock.ts +2 -2
- package/src/tools/performance.ts +5 -5
- package/src/tools/recorder.ts +3 -3
- package/src/tools/screencast.ts +46 -6
- package/src/tools/snapshot.ts +2 -2
- package/src/version.ts +1 -1
package/dist/mcp.js
CHANGED
|
@@ -11,11 +11,308 @@ var __esm = (fn, res, err) => () => {
|
|
|
11
11
|
return res;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
// src/
|
|
14
|
+
// src/endpoints.ts
|
|
15
15
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
function checkName(name, where) {
|
|
18
|
+
if (!NAME_RE.test(name)) {
|
|
19
|
+
throw new EndpointConfigError(`${where}: endpoint name '${name}' is invalid; names are letters, digits and '_' only (no '-', '/', ':' or spaces)`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function sameBase(a, b) {
|
|
23
|
+
return a.replace(/\/+$/, "") === b.replace(/\/+$/, "");
|
|
24
|
+
}
|
|
25
|
+
function parseBase(raw, where) {
|
|
26
|
+
let url;
|
|
27
|
+
try {
|
|
28
|
+
url = new URL(raw);
|
|
29
|
+
} catch {
|
|
30
|
+
throw new EndpointConfigError(`${where}: '${raw}' is not a valid URL (expected e.g. http://127.0.0.1:9222)`);
|
|
31
|
+
}
|
|
32
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
33
|
+
throw new EndpointConfigError(`${where}: '${raw}' must be an http:// or https:// DevTools origin, not ${url.protocol}`);
|
|
34
|
+
}
|
|
35
|
+
if (url.hash)
|
|
36
|
+
throw new EndpointConfigError(`${where}: '${raw}' must not carry a #fragment`);
|
|
37
|
+
let mode;
|
|
38
|
+
for (const [key, value] of url.searchParams) {
|
|
39
|
+
if (key !== "mode") {
|
|
40
|
+
throw new EndpointConfigError(`${where}: unknown query parameter '${key}' in '${raw}' (only ?mode=read or ?mode=write is understood)`);
|
|
41
|
+
}
|
|
42
|
+
if (value !== "read" && value !== "write") {
|
|
43
|
+
throw new EndpointConfigError(`${where}: unknown mode '${value}' in '${raw}' (use mode=read or mode=write)`);
|
|
44
|
+
}
|
|
45
|
+
mode = value;
|
|
46
|
+
}
|
|
47
|
+
const path = url.pathname.replace(/\/+$/, "");
|
|
48
|
+
return { base: `${url.protocol}//${url.host}${path}`, mode };
|
|
49
|
+
}
|
|
50
|
+
function parseEnvString(spec) {
|
|
51
|
+
const out = [];
|
|
52
|
+
const seen = new Set;
|
|
53
|
+
for (const part of spec.split(",")) {
|
|
54
|
+
const entry = part.trim();
|
|
55
|
+
if (!entry)
|
|
56
|
+
continue;
|
|
57
|
+
const eq = entry.indexOf("=");
|
|
58
|
+
if (eq <= 0) {
|
|
59
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS: entry '${entry}' is not name=url (e.g. teams=http://127.0.0.1:9333)`);
|
|
60
|
+
}
|
|
61
|
+
const name = entry.slice(0, eq).trim();
|
|
62
|
+
checkName(name, "CDP_ENDPOINTS");
|
|
63
|
+
if (seen.has(name))
|
|
64
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS: duplicate endpoint name '${name}'`);
|
|
65
|
+
seen.add(name);
|
|
66
|
+
const { base, mode } = parseBase(entry.slice(eq + 1).trim(), `CDP_ENDPOINTS endpoint '${name}'`);
|
|
67
|
+
out.push({ name, base, readOnly: mode === "read" });
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function parseFile(path) {
|
|
72
|
+
let text;
|
|
73
|
+
try {
|
|
74
|
+
text = readFileSync(path, "utf8");
|
|
75
|
+
} catch (err) {
|
|
76
|
+
const code = err.code ?? String(err);
|
|
77
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS_FILE: cannot read '${path}' (${code})`);
|
|
78
|
+
}
|
|
79
|
+
let json;
|
|
80
|
+
try {
|
|
81
|
+
json = JSON.parse(text);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS_FILE: '${path}' is not valid JSON (${err instanceof Error ? err.message : String(err)})`);
|
|
84
|
+
}
|
|
85
|
+
const where = `CDP_ENDPOINTS_FILE '${path}'`;
|
|
86
|
+
if (!json || typeof json !== "object" || Array.isArray(json)) {
|
|
87
|
+
throw new EndpointConfigError(`${where}: top level must be an object {"default"?, "endpoints": {...}}`);
|
|
88
|
+
}
|
|
89
|
+
const top = json;
|
|
90
|
+
for (const key of Object.keys(top)) {
|
|
91
|
+
if (key !== "default" && key !== "endpoints")
|
|
92
|
+
throw new EndpointConfigError(`${where}: unknown top-level key '${key}'`);
|
|
93
|
+
}
|
|
94
|
+
if (top.default !== undefined && typeof top.default !== "string") {
|
|
95
|
+
throw new EndpointConfigError(`${where}: "default" must be an endpoint name string`);
|
|
96
|
+
}
|
|
97
|
+
const raw = top.endpoints ?? {};
|
|
98
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
99
|
+
throw new EndpointConfigError(`${where}: "endpoints" must be an object keyed by endpoint name`);
|
|
100
|
+
}
|
|
101
|
+
const endpoints = [];
|
|
102
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
103
|
+
checkName(name, where);
|
|
104
|
+
const at = `${where} endpoint '${name}'`;
|
|
105
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
106
|
+
throw new EndpointConfigError(`${at}: must be an object like {"base":"http://127.0.0.1:9333"}`);
|
|
107
|
+
}
|
|
108
|
+
const v = value;
|
|
109
|
+
for (const key of Object.keys(v)) {
|
|
110
|
+
if (key !== "base" && key !== "readOnly" && key !== "mode") {
|
|
111
|
+
throw new EndpointConfigError(`${at}: unknown key '${key}' (known: base, readOnly, mode)`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (typeof v.base !== "string")
|
|
115
|
+
throw new EndpointConfigError(`${at}: "base" is required and must be a URL string`);
|
|
116
|
+
if (v.readOnly !== undefined && typeof v.readOnly !== "boolean")
|
|
117
|
+
throw new EndpointConfigError(`${at}: "readOnly" must be a boolean`);
|
|
118
|
+
if (v.mode !== undefined && v.mode !== "read" && v.mode !== "write") {
|
|
119
|
+
throw new EndpointConfigError(`${at}: unknown mode '${String(v.mode)}' (use "read" or "write")`);
|
|
120
|
+
}
|
|
121
|
+
const parsed = parseBase(v.base, at);
|
|
122
|
+
const votes = [parsed.mode, v.mode, v.readOnly === undefined ? undefined : v.readOnly ? "read" : "write"].filter((x) => x !== undefined);
|
|
123
|
+
if (new Set(votes).size > 1)
|
|
124
|
+
throw new EndpointConfigError(`${at}: readOnly / mode settings contradict each other`);
|
|
125
|
+
endpoints.push({ name, base: parsed.base, readOnly: votes[0] === "read" });
|
|
126
|
+
}
|
|
127
|
+
return { endpoints, defaultName: top.default };
|
|
128
|
+
}
|
|
129
|
+
function loadEndpoints(env = process.env) {
|
|
130
|
+
const fromEnv = env.CDP_ENDPOINTS !== undefined ? parseEnvString(env.CDP_ENDPOINTS) : [];
|
|
131
|
+
const file = env.CDP_ENDPOINTS_FILE ? parseFile(env.CDP_ENDPOINTS_FILE) : { endpoints: [], defaultName: undefined };
|
|
132
|
+
const merged = new Map;
|
|
133
|
+
for (const ep of fromEnv)
|
|
134
|
+
merged.set(ep.name, ep);
|
|
135
|
+
for (const ep of file.endpoints) {
|
|
136
|
+
const prior = merged.get(ep.name);
|
|
137
|
+
if (prior && (prior.base !== ep.base || prior.readOnly !== ep.readOnly)) {
|
|
138
|
+
throw new EndpointConfigError(`endpoint '${ep.name}' is defined differently in CDP_ENDPOINTS (${prior.base}${prior.readOnly ? " read-only" : ""}) and CDP_ENDPOINTS_FILE (${ep.base}${ep.readOnly ? " read-only" : ""})`);
|
|
139
|
+
}
|
|
140
|
+
if (!prior)
|
|
141
|
+
merged.set(ep.name, ep);
|
|
142
|
+
}
|
|
143
|
+
const cdpBase = env.CDP_BASE;
|
|
144
|
+
if (cdpBase !== undefined) {
|
|
145
|
+
const configured = merged.get("default");
|
|
146
|
+
if (configured && !sameBase(configured.base, cdpBase)) {
|
|
147
|
+
throw new EndpointConfigError(`CDP_BASE (${cdpBase}) and the configured endpoint 'default' (${configured.base}) disagree; drop one or make them match`);
|
|
148
|
+
}
|
|
149
|
+
merged.set("default", { name: "default", base: cdpBase, readOnly: configured?.readOnly ?? false });
|
|
150
|
+
}
|
|
151
|
+
const defaultName = file.defaultName ?? "default";
|
|
152
|
+
if (!merged.has(defaultName)) {
|
|
153
|
+
if (file.defaultName !== undefined) {
|
|
154
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS_FILE names default endpoint '${file.defaultName}', which is not defined (known: ${[...merged.keys()].join(", ") || "none"})`);
|
|
155
|
+
}
|
|
156
|
+
merged.set("default", { name: "default", base: DEFAULT_CDP_BASE, readOnly: false });
|
|
157
|
+
}
|
|
158
|
+
const def = merged.get(defaultName);
|
|
159
|
+
const byName = new Map([[def.name, def]]);
|
|
160
|
+
for (const [name, ep] of merged)
|
|
161
|
+
if (name !== def.name)
|
|
162
|
+
byName.set(name, ep);
|
|
163
|
+
return { default: def, byName };
|
|
164
|
+
}
|
|
165
|
+
function signature(env) {
|
|
166
|
+
return JSON.stringify([env.CDP_BASE ?? null, env.CDP_ENDPOINTS ?? null, env.CDP_ENDPOINTS_FILE ?? null]);
|
|
167
|
+
}
|
|
168
|
+
function endpointConfig() {
|
|
169
|
+
const sig = signature(process.env);
|
|
170
|
+
if (cache?.sig === sig)
|
|
171
|
+
return cache.config;
|
|
172
|
+
const config = loadEndpoints(process.env);
|
|
173
|
+
cache = { sig, config };
|
|
174
|
+
return config;
|
|
175
|
+
}
|
|
176
|
+
function defaultEndpoint() {
|
|
177
|
+
return endpointConfig().default;
|
|
178
|
+
}
|
|
179
|
+
function allEndpoints() {
|
|
180
|
+
return [...endpointConfig().byName.values()];
|
|
181
|
+
}
|
|
182
|
+
function getEndpoint(name) {
|
|
183
|
+
const { byName } = endpointConfig();
|
|
184
|
+
const ep = byName.get(name);
|
|
185
|
+
if (!ep) {
|
|
186
|
+
throw new EndpointConfigError(`unknown endpoint '${name}' (known: ${[...byName.keys()].join(", ")}). Configure it with CDP_ENDPOINTS or CDP_ENDPOINTS_FILE.`);
|
|
187
|
+
}
|
|
188
|
+
return ep;
|
|
189
|
+
}
|
|
190
|
+
function leaseNamespace(ep) {
|
|
191
|
+
const { default: def, byName } = endpointConfig();
|
|
192
|
+
if (sameBase(ep.base, def.base))
|
|
193
|
+
return;
|
|
194
|
+
for (const other of byName.values())
|
|
195
|
+
if (sameBase(other.base, ep.base))
|
|
196
|
+
return other.name;
|
|
197
|
+
return ep.name;
|
|
198
|
+
}
|
|
199
|
+
function hasEndpointPrefix(target) {
|
|
200
|
+
return typeof target === "string" && target.startsWith(ENDPOINT_PREFIX);
|
|
201
|
+
}
|
|
202
|
+
function splitEndpointSelector(target) {
|
|
203
|
+
if (!hasEndpointPrefix(target))
|
|
204
|
+
return { endpoint: defaultEndpoint(), rest: target };
|
|
205
|
+
const body = target.slice(ENDPOINT_PREFIX.length);
|
|
206
|
+
const slash = body.indexOf("/");
|
|
207
|
+
const name = slash < 0 ? body : body.slice(0, slash);
|
|
208
|
+
if (!name)
|
|
209
|
+
throw new EndpointConfigError(`selector '${target}' has an empty endpoint name; use endpoint:<name>/<selector>`);
|
|
210
|
+
const rest = slash < 0 ? undefined : body.slice(slash + 1);
|
|
211
|
+
return { endpoint: getEndpoint(name), rest: rest === "" ? undefined : rest };
|
|
212
|
+
}
|
|
213
|
+
function usesEndpointArgs(args) {
|
|
214
|
+
if (!args || typeof args !== "object")
|
|
215
|
+
return false;
|
|
216
|
+
const a = args;
|
|
217
|
+
return SELECTOR_KEYS.some((k) => hasEndpointPrefix(a[k])) || a.endpoint !== undefined || a.allEndpoints === true;
|
|
218
|
+
}
|
|
219
|
+
function stripEndpointArgs(args) {
|
|
220
|
+
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
221
|
+
return { endpoint: defaultEndpoint(), args };
|
|
222
|
+
const a = args;
|
|
223
|
+
const picks = [];
|
|
224
|
+
let out;
|
|
225
|
+
for (const key of SELECTOR_KEYS) {
|
|
226
|
+
const v = a[key];
|
|
227
|
+
if (!hasEndpointPrefix(v))
|
|
228
|
+
continue;
|
|
229
|
+
const { endpoint, rest } = splitEndpointSelector(v);
|
|
230
|
+
picks.push({ from: `${key} '${v}'`, endpoint });
|
|
231
|
+
out ??= { ...a };
|
|
232
|
+
if (rest === undefined)
|
|
233
|
+
delete out[key];
|
|
234
|
+
else
|
|
235
|
+
out[key] = rest;
|
|
236
|
+
}
|
|
237
|
+
if (a.endpoint !== undefined) {
|
|
238
|
+
if (typeof a.endpoint !== "string" || a.endpoint === "") {
|
|
239
|
+
throw new EndpointConfigError("`endpoint` must be a non-empty endpoint name string");
|
|
240
|
+
}
|
|
241
|
+
picks.push({ from: `endpoint '${a.endpoint}'`, endpoint: getEndpoint(a.endpoint) });
|
|
242
|
+
out ??= { ...a };
|
|
243
|
+
delete out.endpoint;
|
|
244
|
+
}
|
|
245
|
+
const token = leaseTokenNamespace(a.lease);
|
|
246
|
+
if (!picks.length) {
|
|
247
|
+
if (token?.ns === undefined)
|
|
248
|
+
return { endpoint: defaultEndpoint(), args };
|
|
249
|
+
return { endpoint: endpointForNamespace(token.ns), args };
|
|
250
|
+
}
|
|
251
|
+
const first = picks[0];
|
|
252
|
+
for (const p of picks.slice(1)) {
|
|
253
|
+
if (p.endpoint.name !== first.endpoint.name) {
|
|
254
|
+
throw new EndpointConfigError(`conflicting endpoints: ${first.from} vs ${p.from}; name one endpoint per call`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (token && leaseNamespace(first.endpoint) !== token.ns) {
|
|
258
|
+
throw new EndpointConfigError(`conflicting endpoints: ${first.from} vs the lease token, which belongs to ${token.ns === undefined ? "the default endpoint" : `endpoint '${token.ns}'`}; name one endpoint per call`);
|
|
259
|
+
}
|
|
260
|
+
return { endpoint: first.endpoint, args: out ?? a };
|
|
261
|
+
}
|
|
262
|
+
function leaseTokenNamespace(lease) {
|
|
263
|
+
if (typeof lease !== "string")
|
|
264
|
+
return null;
|
|
265
|
+
const colon = lease.indexOf(":");
|
|
266
|
+
if (colon <= 0)
|
|
267
|
+
return null;
|
|
268
|
+
const head = lease.slice(0, colon);
|
|
269
|
+
if (head === "chrome")
|
|
270
|
+
return { ns: undefined };
|
|
271
|
+
if (!head.startsWith("chrome@"))
|
|
272
|
+
return null;
|
|
273
|
+
const ns = head.slice("chrome@".length);
|
|
274
|
+
return NAME_RE.test(ns) ? { ns } : null;
|
|
275
|
+
}
|
|
276
|
+
function endpointForNamespace(ns) {
|
|
277
|
+
for (const ep of endpointConfig().byName.values())
|
|
278
|
+
if (leaseNamespace(ep) === ns)
|
|
279
|
+
return ep;
|
|
280
|
+
throw new EndpointConfigError(`the lease token belongs to endpoint '${ns}', which is not configured (known: ${[...endpointConfig().byName.keys()].join(", ")})`);
|
|
281
|
+
}
|
|
282
|
+
function currentEndpoint() {
|
|
283
|
+
return endpointScope.getStore() ?? defaultEndpoint();
|
|
284
|
+
}
|
|
285
|
+
function isDefaultEndpoint(ep) {
|
|
286
|
+
return ep.name === defaultEndpoint().name;
|
|
287
|
+
}
|
|
288
|
+
function withEndpointScope(ep, fn) {
|
|
289
|
+
return endpointScope.run(ep, fn);
|
|
290
|
+
}
|
|
291
|
+
var EndpointConfigError, DEFAULT_CDP_BASE = "http://127.0.0.1:9222", ENDPOINT_PREFIX = "endpoint:", NAME_RE, cache, SELECTOR_KEYS, ENDPOINTS_FIREFOX_MESSAGE = "named CDP endpoints (an 'endpoint:<name>/' selector prefix, the endpoint arg, list_pages allEndpoints) need the Chrome backend; the Firefox BiDi backend has one session and no endpoints", endpointScope;
|
|
292
|
+
var init_endpoints = __esm(() => {
|
|
293
|
+
EndpointConfigError = class EndpointConfigError extends Error {
|
|
294
|
+
constructor(message) {
|
|
295
|
+
super(message);
|
|
296
|
+
this.name = "EndpointConfigError";
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
NAME_RE = /^[A-Za-z0-9_]+$/;
|
|
300
|
+
SELECTOR_KEYS = ["target", "targetId"];
|
|
301
|
+
endpointScope = new AsyncLocalStorage;
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// src/leases.ts
|
|
305
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
16
306
|
import { randomBytes } from "node:crypto";
|
|
17
307
|
import { mkdir, readFile, readdir, unlink, writeFile } from "node:fs/promises";
|
|
18
308
|
import { join } from "node:path";
|
|
309
|
+
function chromeLeaseBackend(ep = currentEndpoint()) {
|
|
310
|
+
const ns = leaseNamespace(ep);
|
|
311
|
+
return ns === undefined ? "chrome" : `chrome@${ns}`;
|
|
312
|
+
}
|
|
313
|
+
function isLeaseBackend(value) {
|
|
314
|
+
return BACKEND_KEY_RE.test(value);
|
|
315
|
+
}
|
|
19
316
|
function leaseDir() {
|
|
20
317
|
return process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
21
318
|
}
|
|
@@ -52,7 +349,7 @@ function tokenParts(token) {
|
|
|
52
349
|
if (first <= 0 || last <= first)
|
|
53
350
|
return;
|
|
54
351
|
const backend = token.slice(0, first);
|
|
55
|
-
if (backend
|
|
352
|
+
if (!isLeaseBackend(backend))
|
|
56
353
|
return;
|
|
57
354
|
const targetId = token.slice(first + 1, last);
|
|
58
355
|
const nonce = token.slice(last + 1);
|
|
@@ -273,8 +570,10 @@ async function listLeases(opts = {}) {
|
|
|
273
570
|
}
|
|
274
571
|
return out;
|
|
275
572
|
}
|
|
276
|
-
var DEFAULT_LEASE_TTL_MS = 900000, longLived = false, LeaseConflictError, leaseScope, LEASE_FILE_RE;
|
|
573
|
+
var BACKEND_KEY_SOURCE = "chrome@[A-Za-z0-9_]+|chrome|firefox", BACKEND_KEY_RE, DEFAULT_LEASE_TTL_MS = 900000, longLived = false, LeaseConflictError, leaseScope, LEASE_FILE_RE;
|
|
277
574
|
var init_leases = __esm(() => {
|
|
575
|
+
init_endpoints();
|
|
576
|
+
BACKEND_KEY_RE = new RegExp(`^(?:${BACKEND_KEY_SOURCE})$`);
|
|
278
577
|
LeaseConflictError = class LeaseConflictError extends Error {
|
|
279
578
|
targetId;
|
|
280
579
|
holder;
|
|
@@ -285,8 +584,8 @@ var init_leases = __esm(() => {
|
|
|
285
584
|
this.name = "LeaseConflictError";
|
|
286
585
|
}
|
|
287
586
|
};
|
|
288
|
-
leaseScope = new
|
|
289
|
-
LEASE_FILE_RE =
|
|
587
|
+
leaseScope = new AsyncLocalStorage2;
|
|
588
|
+
LEASE_FILE_RE = new RegExp(`^lease-(${BACKEND_KEY_SOURCE})-(.+)\\.json$`);
|
|
290
589
|
});
|
|
291
590
|
|
|
292
591
|
// src/origins.ts
|
|
@@ -416,7 +715,7 @@ async function resolveLiveLabel(backend, label, liveIds) {
|
|
|
416
715
|
var ORIGIN_FILE_RE;
|
|
417
716
|
var init_origins = __esm(() => {
|
|
418
717
|
init_leases();
|
|
419
|
-
ORIGIN_FILE_RE =
|
|
718
|
+
ORIGIN_FILE_RE = new RegExp(`^origin-(${BACKEND_KEY_SOURCE})-(.+)\\.json$`);
|
|
420
719
|
});
|
|
421
720
|
|
|
422
721
|
// src/workers.ts
|
|
@@ -504,6 +803,204 @@ var init_frames = __esm(() => {
|
|
|
504
803
|
FRAME_SELECTOR_PAGE_ONLY_MESSAGE = "target 'frame:<substring>' selects an out-of-process iframe, and this tool is page-only " + "(closing, selecting, releasing or claiming an iframe is meaningless; these act on the embedder tab). " + `The page-only tools are ${FRAME_PAGE_ONLY_TOOLS.join(", ")}; every other tool that takes a 'target' ` + "accepts a frame: selector.";
|
|
505
804
|
});
|
|
506
805
|
|
|
806
|
+
// src/cdp/endpoint.ts
|
|
807
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
808
|
+
import { join as join3 } from "node:path";
|
|
809
|
+
async function browserWsFromPortFile(dir, base) {
|
|
810
|
+
const raw = await readFile3(join3(dir, "DevToolsActivePort"), "utf8").catch(() => {
|
|
811
|
+
return;
|
|
812
|
+
});
|
|
813
|
+
if (!raw)
|
|
814
|
+
return;
|
|
815
|
+
const [port, path] = raw.split(`
|
|
816
|
+
`);
|
|
817
|
+
if (!port?.trim() || !path?.trim())
|
|
818
|
+
return;
|
|
819
|
+
const host = new URL(base).hostname;
|
|
820
|
+
return `ws://${host}:${port.trim()}${path.trim()}`;
|
|
821
|
+
}
|
|
822
|
+
async function discoverBrowserWs(base) {
|
|
823
|
+
const dir = process.env.CDP_USER_DATA_DIR;
|
|
824
|
+
return dir ? browserWsFromPortFile(dir, base) : undefined;
|
|
825
|
+
}
|
|
826
|
+
async function handshake(url, timeoutMs) {
|
|
827
|
+
const conn = new CdpConnection(url, { timeoutMs });
|
|
828
|
+
try {
|
|
829
|
+
await conn.connect();
|
|
830
|
+
return true;
|
|
831
|
+
} catch {
|
|
832
|
+
return false;
|
|
833
|
+
} finally {
|
|
834
|
+
conn.close();
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
function detectEndpoint() {
|
|
838
|
+
const endpoint = currentEndpoint();
|
|
839
|
+
const base = endpoint.base;
|
|
840
|
+
const isDefault = isDefaultEndpoint(endpoint);
|
|
841
|
+
const hit = cached.get(base);
|
|
842
|
+
if (hit)
|
|
843
|
+
return hit;
|
|
844
|
+
const detection = (async () => {
|
|
845
|
+
const forced = isDefault ? process.env.CDP_BROWSER_WS : undefined;
|
|
846
|
+
if (forced)
|
|
847
|
+
return { transport: "browser-ws", browserWsUrl: forced };
|
|
848
|
+
const discovered = isDefault ? await discoverBrowserWs(base) : undefined;
|
|
849
|
+
if (discovered && await handshake(discovered, 5000)) {
|
|
850
|
+
return { transport: "browser-ws", browserWsUrl: discovered };
|
|
851
|
+
}
|
|
852
|
+
const version = await fetch(`${base}/json/version`, { signal: AbortSignal.timeout(5000) }).then((r) => r.ok ? r.json() : undefined).catch(() => {
|
|
853
|
+
return;
|
|
854
|
+
});
|
|
855
|
+
if (version?.webSocketDebuggerUrl) {
|
|
856
|
+
return { transport: "http", browserWsUrl: version.webSocketDebuggerUrl };
|
|
857
|
+
}
|
|
858
|
+
const dir = isDefault ? process.env.CDP_USER_DATA_DIR : undefined;
|
|
859
|
+
throw new Error(`no DevTools endpoint at ${base}: GET /json/version did not answer and ` + (dir ? `no live browser socket was named by ${dir}/DevToolsActivePort. ` : `no profile was searched — CDP_USER_DATA_DIR is unset, and no profile is ever scanned unless you name one. `) + `Set CDP_BROWSER_WS to the ws://.../devtools/browser/<uuid> URL, or CDP_USER_DATA_DIR to the profile in use.`);
|
|
860
|
+
})().then((info) => {
|
|
861
|
+
if (info.transport === "http")
|
|
862
|
+
cached.delete(base);
|
|
863
|
+
return info;
|
|
864
|
+
}, (error) => {
|
|
865
|
+
cached.delete(base);
|
|
866
|
+
throw error;
|
|
867
|
+
});
|
|
868
|
+
cached.set(base, detection);
|
|
869
|
+
return detection;
|
|
870
|
+
}
|
|
871
|
+
function forgetEndpoint() {
|
|
872
|
+
cached.delete(currentEndpoint().base);
|
|
873
|
+
}
|
|
874
|
+
var cached;
|
|
875
|
+
var init_endpoint = __esm(() => {
|
|
876
|
+
init_endpoints();
|
|
877
|
+
init_client();
|
|
878
|
+
cached = new Map;
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
// src/cdp/session.ts
|
|
882
|
+
async function acquireBrowserConn() {
|
|
883
|
+
if (shared) {
|
|
884
|
+
shared.refs++;
|
|
885
|
+
return shared.conn;
|
|
886
|
+
}
|
|
887
|
+
if (!opening) {
|
|
888
|
+
opening = (async () => {
|
|
889
|
+
let { browserWsUrl } = await detectEndpoint();
|
|
890
|
+
let conn;
|
|
891
|
+
try {
|
|
892
|
+
conn = await new CdpConnection(browserWsUrl).connect();
|
|
893
|
+
} catch (error) {
|
|
894
|
+
forgetEndpoint();
|
|
895
|
+
const fresh = (await detectEndpoint().catch(() => {
|
|
896
|
+
return;
|
|
897
|
+
}))?.browserWsUrl;
|
|
898
|
+
if (!fresh || fresh === browserWsUrl)
|
|
899
|
+
throw error;
|
|
900
|
+
browserWsUrl = fresh;
|
|
901
|
+
conn = await new CdpConnection(browserWsUrl).connect();
|
|
902
|
+
}
|
|
903
|
+
shared = { conn, refs: 0, url: browserWsUrl };
|
|
904
|
+
return conn;
|
|
905
|
+
})().finally(() => {
|
|
906
|
+
opening = undefined;
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
const conn = await opening;
|
|
910
|
+
shared.refs++;
|
|
911
|
+
return conn;
|
|
912
|
+
}
|
|
913
|
+
function releaseBrowserConn() {
|
|
914
|
+
if (!shared)
|
|
915
|
+
return;
|
|
916
|
+
shared.refs--;
|
|
917
|
+
if (shared.refs <= 0) {
|
|
918
|
+
const { conn } = shared;
|
|
919
|
+
shared = undefined;
|
|
920
|
+
conn.close();
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
async function withBrowserSocket(fn) {
|
|
924
|
+
const conn = await acquireBrowserConn();
|
|
925
|
+
try {
|
|
926
|
+
return await fn(conn);
|
|
927
|
+
} finally {
|
|
928
|
+
releaseBrowserConn();
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
class SessionConnection {
|
|
933
|
+
browser;
|
|
934
|
+
sessionId;
|
|
935
|
+
opts;
|
|
936
|
+
detached = false;
|
|
937
|
+
offs = [];
|
|
938
|
+
constructor(browser, sessionId, opts = {}) {
|
|
939
|
+
this.browser = browser;
|
|
940
|
+
this.sessionId = sessionId;
|
|
941
|
+
this.opts = opts;
|
|
942
|
+
}
|
|
943
|
+
send(method, params = {}, opts = {}) {
|
|
944
|
+
if (this.detached)
|
|
945
|
+
return Promise.reject(new CdpError("connection not open"));
|
|
946
|
+
return this.browser.send(method, params, {
|
|
947
|
+
timeoutMs: opts.timeoutMs ?? this.opts.timeoutMs,
|
|
948
|
+
sessionId: opts.sessionId ?? this.sessionId
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
on(method, handler) {
|
|
952
|
+
const off = this.browser.on(method, (params, sessionId) => {
|
|
953
|
+
if (sessionId && sessionId !== this.sessionId)
|
|
954
|
+
return;
|
|
955
|
+
handler(params, sessionId);
|
|
956
|
+
});
|
|
957
|
+
this.offs.push(off);
|
|
958
|
+
return off;
|
|
959
|
+
}
|
|
960
|
+
waitFor(method, predicate, timeoutMs = this.opts.timeoutMs ?? DEFAULT_TIMEOUT_MS) {
|
|
961
|
+
return new Promise((resolve, reject) => {
|
|
962
|
+
const timer = setTimeout(() => {
|
|
963
|
+
off();
|
|
964
|
+
reject(new CdpError(`waitFor('${method}') timed out after ${timeoutMs}ms`));
|
|
965
|
+
}, timeoutMs);
|
|
966
|
+
const off = this.on(method, (params) => {
|
|
967
|
+
if (!predicate || predicate(params)) {
|
|
968
|
+
clearTimeout(timer);
|
|
969
|
+
off();
|
|
970
|
+
resolve(params);
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
close() {
|
|
976
|
+
if (this.detached)
|
|
977
|
+
return;
|
|
978
|
+
this.detached = true;
|
|
979
|
+
for (const off of this.offs)
|
|
980
|
+
off();
|
|
981
|
+
this.offs.length = 0;
|
|
982
|
+
this.browser.send("Target.detachFromTarget", { sessionId: this.sessionId }).catch(() => {});
|
|
983
|
+
releaseBrowserConn();
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
async function openSession(targetId, opts = {}) {
|
|
987
|
+
const browser = await acquireBrowserConn();
|
|
988
|
+
try {
|
|
989
|
+
const { sessionId } = await browser.send("Target.attachToTarget", { targetId, flatten: true }, { timeoutMs: opts.timeoutMs });
|
|
990
|
+
if (!sessionId)
|
|
991
|
+
throw new CdpError(`Target.attachToTarget returned no sessionId for ${targetId}`);
|
|
992
|
+
return new SessionConnection(browser, sessionId, opts);
|
|
993
|
+
} catch (e) {
|
|
994
|
+
releaseBrowserConn();
|
|
995
|
+
throw e;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
var shared, opening;
|
|
999
|
+
var init_session = __esm(() => {
|
|
1000
|
+
init_client();
|
|
1001
|
+
init_endpoint();
|
|
1002
|
+
});
|
|
1003
|
+
|
|
507
1004
|
// src/client.ts
|
|
508
1005
|
class CdpConnection {
|
|
509
1006
|
wsUrl;
|
|
@@ -631,24 +1128,59 @@ class CdpConnection {
|
|
|
631
1128
|
}
|
|
632
1129
|
}
|
|
633
1130
|
async function httpJson(path) {
|
|
634
|
-
const res = await fetch(`${
|
|
1131
|
+
const res = await fetch(`${currentEndpoint().base}${path}`);
|
|
635
1132
|
if (!res.ok)
|
|
636
1133
|
throw new CdpError(`${path} -> HTTP ${res.status}`);
|
|
637
1134
|
return await res.json();
|
|
638
1135
|
}
|
|
639
|
-
function
|
|
640
|
-
|
|
1136
|
+
async function getTargetsOverBrowserWs() {
|
|
1137
|
+
const { targetInfos } = await withBrowserSocket((conn) => conn.send("Target.getTargets", { filter: [{}] }));
|
|
1138
|
+
return targetInfos.map((t) => ({
|
|
1139
|
+
id: t.targetId,
|
|
1140
|
+
type: t.type,
|
|
1141
|
+
title: t.title,
|
|
1142
|
+
url: t.url,
|
|
1143
|
+
webSocketDebuggerUrl: "",
|
|
1144
|
+
...t.openerId ? { parentId: t.openerId } : {}
|
|
1145
|
+
}));
|
|
1146
|
+
}
|
|
1147
|
+
async function listTargets() {
|
|
1148
|
+
const base = currentEndpoint().base;
|
|
1149
|
+
if (knownTransports.get(base) === "browser-ws")
|
|
1150
|
+
return getTargetsOverBrowserWs();
|
|
1151
|
+
try {
|
|
1152
|
+
const listing = await httpJson("/json/list");
|
|
1153
|
+
knownTransports.set(base, "http");
|
|
1154
|
+
return listing;
|
|
1155
|
+
} catch (httpError) {
|
|
1156
|
+
const detected = await detectEndpoint().catch(() => {
|
|
1157
|
+
return;
|
|
1158
|
+
});
|
|
1159
|
+
if (detected?.transport !== "browser-ws")
|
|
1160
|
+
throw httpError;
|
|
1161
|
+
const targets = await getTargetsOverBrowserWs().catch(() => {
|
|
1162
|
+
throw httpError;
|
|
1163
|
+
});
|
|
1164
|
+
knownTransports.set(base, "browser-ws");
|
|
1165
|
+
return targets;
|
|
1166
|
+
}
|
|
641
1167
|
}
|
|
642
1168
|
async function browserWsUrl() {
|
|
643
|
-
|
|
644
|
-
|
|
1169
|
+
if (knownTransports.get(currentEndpoint().base) !== "browser-ws") {
|
|
1170
|
+
const version = await httpJson("/json/version").catch(() => {
|
|
1171
|
+
return;
|
|
1172
|
+
});
|
|
1173
|
+
if (version?.webSocketDebuggerUrl)
|
|
1174
|
+
return version.webSocketDebuggerUrl;
|
|
1175
|
+
}
|
|
1176
|
+
return (await detectEndpoint()).browserWsUrl;
|
|
645
1177
|
}
|
|
646
1178
|
async function resolveTarget(selector, opts = {}) {
|
|
647
1179
|
const targets = await listTargets();
|
|
648
1180
|
const hit = await pickTarget(targets, selector);
|
|
649
1181
|
if (isWorkerTargetType(hit.type))
|
|
650
1182
|
return hit;
|
|
651
|
-
await assertLeaseOk(
|
|
1183
|
+
await assertLeaseOk(chromeLeaseBackend(), hit.id, { lease: opts.lease, url: hit.url, title: hit.title });
|
|
652
1184
|
return hit;
|
|
653
1185
|
}
|
|
654
1186
|
async function pickTarget(targets, selector) {
|
|
@@ -680,7 +1212,7 @@ async function pickTarget(targets, selector) {
|
|
|
680
1212
|
}
|
|
681
1213
|
if (selector.startsWith("label:")) {
|
|
682
1214
|
const label = selector.slice(6);
|
|
683
|
-
const { matchIds, knownLabels } = await resolveLiveLabel(
|
|
1215
|
+
const { matchIds, knownLabels } = await resolveLiveLabel(chromeLeaseBackend(), label, pages.map((t) => t.id));
|
|
684
1216
|
if (matchIds.length > 1) {
|
|
685
1217
|
throw new CdpError(`label 'label:${label}' matches more than one live target: ${matchIds.join(", ")}. Resolve by target id instead.`);
|
|
686
1218
|
}
|
|
@@ -723,7 +1255,7 @@ async function openBrowser(opts = {}) {
|
|
|
723
1255
|
}
|
|
724
1256
|
async function openPage(selector, opts = {}) {
|
|
725
1257
|
const target = await resolveTarget(selector, { lease: opts.lease });
|
|
726
|
-
const conn = await new CdpConnection(target.webSocketDebuggerUrl, opts).connect();
|
|
1258
|
+
const conn = target.webSocketDebuggerUrl ? await new CdpConnection(target.webSocketDebuggerUrl, opts).connect() : await openSession(target.id, opts);
|
|
727
1259
|
return { conn, target };
|
|
728
1260
|
}
|
|
729
1261
|
async function withPage(selector, fn, opts = {}) {
|
|
@@ -734,13 +1266,23 @@ async function withPage(selector, fn, opts = {}) {
|
|
|
734
1266
|
conn.close();
|
|
735
1267
|
}
|
|
736
1268
|
}
|
|
737
|
-
var BASE, DEFAULT_TIMEOUT_MS, CdpError;
|
|
1269
|
+
var BASE, DEFAULT_TIMEOUT_MS, CdpError, knownTransports;
|
|
738
1270
|
var init_client = __esm(() => {
|
|
739
1271
|
init_leases();
|
|
740
1272
|
init_origins();
|
|
1273
|
+
init_endpoints();
|
|
741
1274
|
init_workers();
|
|
742
1275
|
init_frames();
|
|
743
|
-
|
|
1276
|
+
init_endpoint();
|
|
1277
|
+
init_session();
|
|
1278
|
+
init_session();
|
|
1279
|
+
BASE = (() => {
|
|
1280
|
+
try {
|
|
1281
|
+
return defaultEndpoint().base;
|
|
1282
|
+
} catch {
|
|
1283
|
+
return process.env.CDP_BASE ?? DEFAULT_CDP_BASE;
|
|
1284
|
+
}
|
|
1285
|
+
})();
|
|
744
1286
|
DEFAULT_TIMEOUT_MS = Number(process.env.CDP_TIMEOUT_MS ?? 15000);
|
|
745
1287
|
CdpError = class CdpError extends Error {
|
|
746
1288
|
code;
|
|
@@ -752,6 +1294,7 @@ var init_client = __esm(() => {
|
|
|
752
1294
|
this.name = "CdpError";
|
|
753
1295
|
}
|
|
754
1296
|
};
|
|
1297
|
+
knownTransports = new Map;
|
|
755
1298
|
});
|
|
756
1299
|
|
|
757
1300
|
// src/activity.ts
|
|
@@ -1068,8 +1611,8 @@ var init_network_mock = __esm(() => {
|
|
|
1068
1611
|
});
|
|
1069
1612
|
|
|
1070
1613
|
// src/driver.ts
|
|
1071
|
-
import { mkdir as mkdir3, readFile as
|
|
1072
|
-
import { join as
|
|
1614
|
+
import { mkdir as mkdir3, readFile as readFile4, unlink as unlink3, writeFile as writeFile3 } from "node:fs/promises";
|
|
1615
|
+
import { join as join4 } from "node:path";
|
|
1073
1616
|
function isDriverError(e) {
|
|
1074
1617
|
return e instanceof Error && typeof e.code === "string";
|
|
1075
1618
|
}
|
|
@@ -1085,11 +1628,11 @@ function isTiledCapture(delivery) {
|
|
|
1085
1628
|
return delivery.tiled === true;
|
|
1086
1629
|
}
|
|
1087
1630
|
function viewportRecordFile(scheme, targetId) {
|
|
1088
|
-
return
|
|
1631
|
+
return join4(leaseDir(), `viewport-${scheme}-${targetId.replace(/[^A-Za-z0-9._-]/g, "_")}.json`);
|
|
1089
1632
|
}
|
|
1090
1633
|
async function readViewportRecord(scheme, targetId) {
|
|
1091
1634
|
try {
|
|
1092
|
-
const raw = JSON.parse(await
|
|
1635
|
+
const raw = JSON.parse(await readFile4(viewportRecordFile(scheme, targetId), "utf8"));
|
|
1093
1636
|
if (typeof raw?.width !== "number" || typeof raw?.height !== "number")
|
|
1094
1637
|
return;
|
|
1095
1638
|
return {
|
|
@@ -1140,81 +1683,396 @@ var init_driver = __esm(() => {
|
|
|
1140
1683
|
};
|
|
1141
1684
|
});
|
|
1142
1685
|
|
|
1143
|
-
// src/bidi/
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
closed = false;
|
|
1152
|
-
refCount = 0;
|
|
1153
|
-
pending = new Map;
|
|
1154
|
-
listeners = new Map;
|
|
1155
|
-
constructor(wsUrl, opts = {}) {
|
|
1156
|
-
this.wsUrl = wsUrl;
|
|
1157
|
-
this.opts = opts;
|
|
1158
|
-
}
|
|
1159
|
-
get sessionId() {
|
|
1160
|
-
return this.sessId;
|
|
1161
|
-
}
|
|
1162
|
-
get capabilities() {
|
|
1163
|
-
return this.caps;
|
|
1164
|
-
}
|
|
1165
|
-
get holders() {
|
|
1166
|
-
return this.refCount;
|
|
1167
|
-
}
|
|
1168
|
-
get isOpen() {
|
|
1169
|
-
return !this.closed && this.ws !== undefined;
|
|
1170
|
-
}
|
|
1171
|
-
connect() {
|
|
1172
|
-
return new Promise((resolve, reject) => {
|
|
1173
|
-
const ws = new WebSocket(this.wsUrl);
|
|
1174
|
-
this.ws = ws;
|
|
1175
|
-
const openTimer = setTimeout(() => reject(new BidiError(`connect timeout: ${this.wsUrl}`)), this.opts.timeoutMs ?? DEFAULT_TIMEOUT_MS3);
|
|
1176
|
-
ws.onopen = () => {
|
|
1177
|
-
clearTimeout(openTimer);
|
|
1178
|
-
resolve(this);
|
|
1179
|
-
};
|
|
1180
|
-
ws.onerror = (e) => {
|
|
1181
|
-
clearTimeout(openTimer);
|
|
1182
|
-
const msg = e?.message ?? "websocket error";
|
|
1183
|
-
if (this.pending.size === 0)
|
|
1184
|
-
reject(new BidiError(msg));
|
|
1185
|
-
this.rejectAll(new BidiError(msg));
|
|
1186
|
-
};
|
|
1187
|
-
ws.onclose = () => {
|
|
1188
|
-
this.closed = true;
|
|
1189
|
-
this.rejectAll(new BidiError("connection closed"));
|
|
1190
|
-
};
|
|
1191
|
-
ws.onmessage = (ev) => this.onMessage(String(ev.data));
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
async newSession(capabilities = {}) {
|
|
1195
|
-
const result = await this.send("session.new", { capabilities });
|
|
1196
|
-
this.sessId = result.sessionId;
|
|
1197
|
-
this.caps = result.capabilities;
|
|
1198
|
-
return result.sessionId;
|
|
1686
|
+
// src/bidi/snapshot.ts
|
|
1687
|
+
async function takeStampedSnapshot(evaluate) {
|
|
1688
|
+
const raw = await evaluate(buildSnapshotFunctionSource());
|
|
1689
|
+
return coerceSnapshotResult(raw);
|
|
1690
|
+
}
|
|
1691
|
+
function coerceSnapshotResult(raw) {
|
|
1692
|
+
if (typeof raw !== "object" || raw === null || typeof raw.snapshot !== "string" || typeof raw.nodeCount !== "number") {
|
|
1693
|
+
throw new Error("takeStampedSnapshot: evaluate() returned an unexpected shape");
|
|
1199
1694
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1695
|
+
return { snapshot: raw.snapshot, nodeCount: raw.nodeCount };
|
|
1696
|
+
}
|
|
1697
|
+
function buildSnapshotFunctionSource() {
|
|
1698
|
+
return `function() {
|
|
1699
|
+
var STAMP_ATTR = ${JSON.stringify(STAMP_ATTR)};
|
|
1700
|
+
var MAX_NAME_LENGTH = ${MAX_NAME_LENGTH};
|
|
1701
|
+
var lines = [];
|
|
1702
|
+
var nodeCount = 0;
|
|
1703
|
+
|
|
1704
|
+
// THE UID CODEC (driver.ts) documents a bidi payload as exactly 12 lowercase hex chars,
|
|
1705
|
+
// /^[0-9a-f]{12}$/. Build it from two padded random blocks so the length is exact regardless
|
|
1706
|
+
// of the random value drawn, never from string concatenation that could come up short.
|
|
1707
|
+
function nextStamp() {
|
|
1708
|
+
var hi = Math.floor(Math.random() * 0x100000000).toString(16).padStart(8, "0");
|
|
1709
|
+
var lo = Math.floor(Math.random() * 0x10000).toString(16).padStart(4, "0");
|
|
1710
|
+
return hi + lo;
|
|
1206
1711
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
p.resolve(msg);
|
|
1215
|
-
return;
|
|
1712
|
+
|
|
1713
|
+
function stampOf(el) {
|
|
1714
|
+
var existing = el.getAttribute(STAMP_ATTR);
|
|
1715
|
+
if (existing) return existing;
|
|
1716
|
+
var stamp = nextStamp();
|
|
1717
|
+
el.setAttribute(STAMP_ATTR, stamp);
|
|
1718
|
+
return stamp;
|
|
1216
1719
|
}
|
|
1217
|
-
|
|
1720
|
+
|
|
1721
|
+
// skipSizeCheck exempts <option>/<optgroup> from the zero-size prune: a
|
|
1722
|
+
// closed select's popup is unpainted (0x0) though its options are still
|
|
1723
|
+
// present and pickable. Other visibility rules still apply to them.
|
|
1724
|
+
function isVisible(el, skipSizeCheck) {
|
|
1725
|
+
if (el.hidden) return false;
|
|
1726
|
+
if (el.getAttribute("aria-hidden") === "true") return false;
|
|
1727
|
+
var style;
|
|
1728
|
+
try {
|
|
1729
|
+
style = el.ownerDocument.defaultView.getComputedStyle(el);
|
|
1730
|
+
} catch (e) {
|
|
1731
|
+
style = null;
|
|
1732
|
+
}
|
|
1733
|
+
if (style) {
|
|
1734
|
+
if (style.display === "none" || style.visibility === "hidden") return false;
|
|
1735
|
+
}
|
|
1736
|
+
if (!skipSizeCheck) {
|
|
1737
|
+
var rect = el.getBoundingClientRect();
|
|
1738
|
+
if (rect.width === 0 && rect.height === 0) return false;
|
|
1739
|
+
}
|
|
1740
|
+
return true;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
${ACCNAME_HELPERS_SOURCE}
|
|
1744
|
+
|
|
1745
|
+
function headingLevel(el) {
|
|
1746
|
+
var m = /^H([1-6])$/.exec(el.tagName);
|
|
1747
|
+
return m ? m[1] : null;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
function currentValue(el) {
|
|
1751
|
+
var tag = el.tagName;
|
|
1752
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") {
|
|
1753
|
+
return el.value;
|
|
1754
|
+
}
|
|
1755
|
+
if (el.isContentEditable) return textOf(el);
|
|
1756
|
+
return undefined;
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
function isChecked(el) {
|
|
1760
|
+
var tag = el.tagName;
|
|
1761
|
+
if (tag === "INPUT") {
|
|
1762
|
+
var type = (el.getAttribute("type") || "").toLowerCase();
|
|
1763
|
+
if (type === "checkbox" || type === "radio") return !!el.checked;
|
|
1764
|
+
}
|
|
1765
|
+
var aria = el.getAttribute("aria-checked");
|
|
1766
|
+
if (aria === "true") return true;
|
|
1767
|
+
return false;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
function describeNode(el, role) {
|
|
1771
|
+
var contentNamed = !!CONTENT_NAMED_ROLES[role];
|
|
1772
|
+
var name = accessibleName(el, contentNamed);
|
|
1773
|
+
var extras = [];
|
|
1774
|
+
var value = currentValue(el);
|
|
1775
|
+
if (value !== undefined && value !== "") extras.push("value=" + JSON.stringify(String(value)));
|
|
1776
|
+
if (isChecked(el)) extras.push("checked=true");
|
|
1777
|
+
if (el.tagName === "OPTION" && el.selected) extras.push("selected");
|
|
1778
|
+
var href = el.getAttribute("href");
|
|
1779
|
+
if (href) extras.push("url=" + href);
|
|
1780
|
+
if (el.disabled || el.getAttribute("aria-disabled") === "true") extras.push("disabled");
|
|
1781
|
+
var level = headingLevel(el);
|
|
1782
|
+
if (level) extras.push("level=" + level);
|
|
1783
|
+
var label = name ? " " + JSON.stringify(name) : "";
|
|
1784
|
+
var extra = extras.length ? " [" + extras.join(" ") + "]" : "";
|
|
1785
|
+
return { role: role, label: label, extra: extra, name: name };
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
// Traverses light DOM, open shadow roots, and same-origin iframe documents.
|
|
1789
|
+
// A cross-origin iframe throws on contentDocument access; caught and
|
|
1790
|
+
// skipped rather than aborting the whole walk, and noted in a comment
|
|
1791
|
+
// here rather than silently vanishing from the tree without a trace.
|
|
1792
|
+
function walk(root, depth) {
|
|
1793
|
+
var children = root.children ? Array.prototype.slice.call(root.children) : [];
|
|
1794
|
+
for (var i = 0; i < children.length; i++) {
|
|
1795
|
+
var el = children[i];
|
|
1796
|
+
var isSelectChild = el.tagName === "OPTION" || el.tagName === "OPTGROUP";
|
|
1797
|
+
if (!isVisible(el, isSelectChild)) continue;
|
|
1798
|
+
|
|
1799
|
+
var role = implicitRole(el);
|
|
1800
|
+
var isLandmarkOrControl = !!role;
|
|
1801
|
+
var described = null;
|
|
1802
|
+
if (isLandmarkOrControl) {
|
|
1803
|
+
described = describeNode(el, role);
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
var hasContent = described && (described.name || described.extra);
|
|
1807
|
+
var isStructural = isLandmarkOrControl && (hasContent || isInteractiveRole(role) || isLandmarkRole(role));
|
|
1808
|
+
|
|
1809
|
+
// Role-less visible leaf text (measured vs Chrome's take_snapshot,
|
|
1810
|
+
// which keeps a StaticText under a generic wrapper for this case,
|
|
1811
|
+
// e.g. a plain status <div>). Only a leaf (no element children, so
|
|
1812
|
+
// its text is not already captured by a nested control/label).
|
|
1813
|
+
var hasElementChildren = !!(el.children && el.children.length > 0);
|
|
1814
|
+
var leafName = !isStructural && !hasElementChildren ? truncate(textOf(el)) : "";
|
|
1815
|
+
var isLeafText = !!leafName;
|
|
1816
|
+
|
|
1817
|
+
var nextDepth = depth;
|
|
1818
|
+
if (isStructural || isLeafText) {
|
|
1819
|
+
var stamp = stampOf(el);
|
|
1820
|
+
var indent = new Array(depth + 1).join(" ");
|
|
1821
|
+
var lineTail = isStructural
|
|
1822
|
+
? described.role + described.label + described.extra
|
|
1823
|
+
: "text " + JSON.stringify(leafName);
|
|
1824
|
+
lines.push(indent + "[" + stamp + "] " + lineTail);
|
|
1825
|
+
nodeCount += 1;
|
|
1826
|
+
nextDepth = depth + 1;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
if (el.shadowRoot) {
|
|
1830
|
+
walk(el.shadowRoot, nextDepth);
|
|
1831
|
+
} else if (el.tagName === "IFRAME") {
|
|
1832
|
+
try {
|
|
1833
|
+
var doc = el.contentDocument;
|
|
1834
|
+
if (doc && doc.body) walk(doc.body, nextDepth);
|
|
1835
|
+
} catch (e) {
|
|
1836
|
+
// cross-origin iframe: intentionally skipped, not silently merged
|
|
1837
|
+
// into the parent tree as though it were empty.
|
|
1838
|
+
}
|
|
1839
|
+
} else {
|
|
1840
|
+
walk(el, nextDepth);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
function isInteractiveRole(role) {
|
|
1846
|
+
return (
|
|
1847
|
+
role === "button" ||
|
|
1848
|
+
role === "link" ||
|
|
1849
|
+
role === "textbox" ||
|
|
1850
|
+
role === "searchbox" ||
|
|
1851
|
+
role === "checkbox" ||
|
|
1852
|
+
role === "radio" ||
|
|
1853
|
+
role === "combobox" ||
|
|
1854
|
+
role === "listbox" ||
|
|
1855
|
+
role === "option" ||
|
|
1856
|
+
role === "slider" ||
|
|
1857
|
+
role === "spinbutton" ||
|
|
1858
|
+
role === "progressbar" ||
|
|
1859
|
+
role === "meter"
|
|
1860
|
+
);
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
function isLandmarkRole(role) {
|
|
1864
|
+
return (
|
|
1865
|
+
role === "navigation" ||
|
|
1866
|
+
role === "main" ||
|
|
1867
|
+
role === "form" ||
|
|
1868
|
+
role === "dialog" ||
|
|
1869
|
+
role === "region" ||
|
|
1870
|
+
role === "heading" ||
|
|
1871
|
+
role === "list" ||
|
|
1872
|
+
role === "listitem" ||
|
|
1873
|
+
role === "table" ||
|
|
1874
|
+
role === "row" ||
|
|
1875
|
+
role === "cell" ||
|
|
1876
|
+
role === "columnheader" ||
|
|
1877
|
+
role === "img"
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
walk(document.body, 0);
|
|
1882
|
+
return { snapshot: lines.join("\\n"), nodeCount: nodeCount };
|
|
1883
|
+
}`;
|
|
1884
|
+
}
|
|
1885
|
+
var STAMP_ATTR = "data-cdp-uid", ACCNAME_HELPERS_SOURCE = `
|
|
1886
|
+
function truncate(s) {
|
|
1887
|
+
s = s.trim().replace(/\\s+/g, " ");
|
|
1888
|
+
if (s.length > MAX_NAME_LENGTH) return s.slice(0, MAX_NAME_LENGTH - 1) + "\\u2026";
|
|
1889
|
+
return s;
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
function textOf(el) {
|
|
1893
|
+
return el.textContent || "";
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
function idRefsText(doc, ids) {
|
|
1897
|
+
var parts = [];
|
|
1898
|
+
var list = ids.trim().split(/\\s+/);
|
|
1899
|
+
for (var i = 0; i < list.length; i++) {
|
|
1900
|
+
var ref = doc.getElementById(list[i]);
|
|
1901
|
+
if (ref) parts.push(textOf(ref));
|
|
1902
|
+
}
|
|
1903
|
+
return parts.join(" ").trim();
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
// Text of a <label>, minus any nested form control's own content: a
|
|
1907
|
+
// label that WRAPS its control ("<label>Color <select>...</select></label>")
|
|
1908
|
+
// would otherwise include every option's text in the control's own name.
|
|
1909
|
+
function labelOwnText(label) {
|
|
1910
|
+
var clone = label.cloneNode(true);
|
|
1911
|
+
var controls = clone.querySelectorAll("input, select, textarea, button");
|
|
1912
|
+
for (var i = 0; i < controls.length; i++) {
|
|
1913
|
+
controls[i].parentNode.removeChild(controls[i]);
|
|
1914
|
+
}
|
|
1915
|
+
return textOf(clone);
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// Guard: without this, an <option> inside a labelled <select> would
|
|
1919
|
+
// inherit the select's own label via closest("label"), not its text.
|
|
1920
|
+
var LABELABLE_TAGS = { INPUT: 1, TEXTAREA: 1, SELECT: 1, BUTTON: 1, METER: 1, OUTPUT: 1, PROGRESS: 1 };
|
|
1921
|
+
|
|
1922
|
+
function nativeLabelText(el) {
|
|
1923
|
+
if (!LABELABLE_TAGS[el.tagName]) return "";
|
|
1924
|
+
var doc = el.ownerDocument;
|
|
1925
|
+
if (el.id) {
|
|
1926
|
+
var forLabel = doc.querySelector('label[for="' + el.id + '"]');
|
|
1927
|
+
if (forLabel) return labelOwnText(forLabel);
|
|
1928
|
+
}
|
|
1929
|
+
var ancestor = el.closest ? el.closest("label") : null;
|
|
1930
|
+
if (ancestor) return labelOwnText(ancestor);
|
|
1931
|
+
return "";
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
// Reduced accname: aria-labelledby, then aria-label, then native label,
|
|
1935
|
+
// then alt/title/placeholder, then trimmed own text for content-named
|
|
1936
|
+
// elements. Not the full W3C accname algorithm (no recursive traversal
|
|
1937
|
+
// rules for nested presentational content) but covers the common cases.
|
|
1938
|
+
function accessibleName(el, contentNamed) {
|
|
1939
|
+
var doc = el.ownerDocument;
|
|
1940
|
+
var labelledby = el.getAttribute("aria-labelledby");
|
|
1941
|
+
if (labelledby) {
|
|
1942
|
+
var viaIds = idRefsText(doc, labelledby);
|
|
1943
|
+
if (viaIds) return truncate(viaIds);
|
|
1944
|
+
}
|
|
1945
|
+
var ariaLabel = el.getAttribute("aria-label");
|
|
1946
|
+
if (ariaLabel && ariaLabel.trim()) return truncate(ariaLabel);
|
|
1947
|
+
var native = nativeLabelText(el);
|
|
1948
|
+
if (native && native.trim()) return truncate(native);
|
|
1949
|
+
var alt = el.getAttribute("alt");
|
|
1950
|
+
if (alt && alt.trim()) return truncate(alt);
|
|
1951
|
+
var title = el.getAttribute("title");
|
|
1952
|
+
if (title && title.trim()) return truncate(title);
|
|
1953
|
+
var placeholder = el.getAttribute("placeholder");
|
|
1954
|
+
if (placeholder && placeholder.trim()) return truncate(placeholder);
|
|
1955
|
+
if (contentNamed) {
|
|
1956
|
+
var text = textOf(el);
|
|
1957
|
+
if (text && text.trim()) return truncate(text);
|
|
1958
|
+
}
|
|
1959
|
+
return "";
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
var IMPLICIT_ROLE_BY_TAG = {
|
|
1963
|
+
A: "link", BUTTON: "button", NAV: "navigation", MAIN: "main", FORM: "form", DIALOG: "dialog",
|
|
1964
|
+
UL: "list", OL: "list", LI: "listitem", TABLE: "table", TR: "row", TD: "cell", TH: "columnheader",
|
|
1965
|
+
SELECT: "combobox", OPTION: "option", TEXTAREA: "textbox", IMG: "img",
|
|
1966
|
+
H1: "heading", H2: "heading", H3: "heading", H4: "heading", H5: "heading", H6: "heading",
|
|
1967
|
+
PROGRESS: "progressbar", METER: "meter"
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
var INPUT_TYPE_ROLE = {
|
|
1971
|
+
button: "button", submit: "button", reset: "button", checkbox: "checkbox", radio: "radio",
|
|
1972
|
+
range: "slider", number: "spinbutton", search: "searchbox", email: "textbox", tel: "textbox",
|
|
1973
|
+
url: "textbox", password: "textbox", text: "textbox", image: "button"
|
|
1974
|
+
};
|
|
1975
|
+
|
|
1976
|
+
var CONTENT_NAMED_ROLES = {
|
|
1977
|
+
button: true, link: true, heading: true, option: true, cell: true,
|
|
1978
|
+
columnheader: true, listitem: true, menuitem: true, tab: true
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
function implicitRole(el) {
|
|
1982
|
+
var explicit = el.getAttribute("role");
|
|
1983
|
+
if (explicit) return explicit;
|
|
1984
|
+
var tag = el.tagName;
|
|
1985
|
+
if (tag === "INPUT") {
|
|
1986
|
+
var type = (el.getAttribute("type") || "text").toLowerCase();
|
|
1987
|
+
return INPUT_TYPE_ROLE[type] || "textbox";
|
|
1988
|
+
}
|
|
1989
|
+
if (tag === "A" && !el.getAttribute("href")) return "";
|
|
1990
|
+
if (Object.prototype.hasOwnProperty.call(IMPLICIT_ROLE_BY_TAG, tag)) {
|
|
1991
|
+
return IMPLICIT_ROLE_BY_TAG[tag];
|
|
1992
|
+
}
|
|
1993
|
+
// Deliberate divergence: Chrome's real AX tree says "generic" here,
|
|
1994
|
+
// but "textbox" is the useful signal an agent needs. Chrome is out of
|
|
1995
|
+
// step, do not "fix" this toward parity.
|
|
1996
|
+
if (el.isContentEditable) return "textbox";
|
|
1997
|
+
return "";
|
|
1998
|
+
}
|
|
1999
|
+
`, MAX_NAME_LENGTH = 120;
|
|
2000
|
+
|
|
2001
|
+
// src/bidi/client.ts
|
|
2002
|
+
class BidiConnection {
|
|
2003
|
+
wsUrl;
|
|
2004
|
+
opts;
|
|
2005
|
+
ws;
|
|
2006
|
+
nextId = 0;
|
|
2007
|
+
sessId;
|
|
2008
|
+
caps;
|
|
2009
|
+
closed = false;
|
|
2010
|
+
refCount = 0;
|
|
2011
|
+
pending = new Map;
|
|
2012
|
+
listeners = new Map;
|
|
2013
|
+
constructor(wsUrl, opts = {}) {
|
|
2014
|
+
this.wsUrl = wsUrl;
|
|
2015
|
+
this.opts = opts;
|
|
2016
|
+
}
|
|
2017
|
+
get sessionId() {
|
|
2018
|
+
return this.sessId;
|
|
2019
|
+
}
|
|
2020
|
+
get capabilities() {
|
|
2021
|
+
return this.caps;
|
|
2022
|
+
}
|
|
2023
|
+
get holders() {
|
|
2024
|
+
return this.refCount;
|
|
2025
|
+
}
|
|
2026
|
+
get isOpen() {
|
|
2027
|
+
return !this.closed && this.ws !== undefined;
|
|
2028
|
+
}
|
|
2029
|
+
connect() {
|
|
2030
|
+
return new Promise((resolve, reject) => {
|
|
2031
|
+
const ws = new WebSocket(this.wsUrl);
|
|
2032
|
+
this.ws = ws;
|
|
2033
|
+
const openTimer = setTimeout(() => reject(new BidiError(`connect timeout: ${this.wsUrl}`)), this.opts.timeoutMs ?? DEFAULT_TIMEOUT_MS3);
|
|
2034
|
+
ws.onopen = () => {
|
|
2035
|
+
clearTimeout(openTimer);
|
|
2036
|
+
resolve(this);
|
|
2037
|
+
};
|
|
2038
|
+
ws.onerror = (e) => {
|
|
2039
|
+
clearTimeout(openTimer);
|
|
2040
|
+
const msg = e?.message ?? "websocket error";
|
|
2041
|
+
if (this.pending.size === 0)
|
|
2042
|
+
reject(new BidiError(msg));
|
|
2043
|
+
this.rejectAll(new BidiError(msg));
|
|
2044
|
+
};
|
|
2045
|
+
ws.onclose = () => {
|
|
2046
|
+
this.closed = true;
|
|
2047
|
+
this.rejectAll(new BidiError("connection closed"));
|
|
2048
|
+
};
|
|
2049
|
+
ws.onmessage = (ev) => this.onMessage(String(ev.data));
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
async newSession(capabilities = {}) {
|
|
2053
|
+
const result = await this.send("session.new", { capabilities });
|
|
2054
|
+
this.sessId = result.sessionId;
|
|
2055
|
+
this.caps = result.capabilities;
|
|
2056
|
+
return result.sessionId;
|
|
2057
|
+
}
|
|
2058
|
+
onMessage(raw) {
|
|
2059
|
+
let msg;
|
|
2060
|
+
try {
|
|
2061
|
+
msg = JSON.parse(raw);
|
|
2062
|
+
} catch {
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
if (msg.type === "success" || msg.type === "error") {
|
|
2066
|
+
const id = msg.id;
|
|
2067
|
+
if (typeof id !== "number" || !this.pending.has(id))
|
|
2068
|
+
return;
|
|
2069
|
+
const p = this.pending.get(id);
|
|
2070
|
+
clearTimeout(p.timer);
|
|
2071
|
+
this.pending.delete(id);
|
|
2072
|
+
p.resolve(msg);
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
if (msg.type === "event") {
|
|
1218
2076
|
const set = this.listeners.get(msg.method);
|
|
1219
2077
|
if (set)
|
|
1220
2078
|
for (const h of set)
|
|
@@ -1339,16 +2197,16 @@ var init_client2 = __esm(() => {
|
|
|
1339
2197
|
});
|
|
1340
2198
|
|
|
1341
2199
|
// src/bidi/session-lease.ts
|
|
1342
|
-
import { mkdir as mkdir13, readFile as
|
|
1343
|
-
import { join as
|
|
2200
|
+
import { mkdir as mkdir13, readFile as readFile9, rename as rename3, unlink as unlink5, writeFile as writeFile10 } from "node:fs/promises";
|
|
2201
|
+
import { join as join12 } from "node:path";
|
|
1344
2202
|
function safeEndpoint(endpoint) {
|
|
1345
2203
|
return endpoint.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1346
2204
|
}
|
|
1347
2205
|
function sessionSlotFile(endpoint) {
|
|
1348
|
-
return
|
|
2206
|
+
return join12(leaseDir(), `ff-session-${safeEndpoint(endpoint)}.json`);
|
|
1349
2207
|
}
|
|
1350
2208
|
function muxDaemonLogFile(endpoint) {
|
|
1351
|
-
return
|
|
2209
|
+
return join12(leaseDir(), `ff-mux-${safeEndpoint(endpoint)}.log`);
|
|
1352
2210
|
}
|
|
1353
2211
|
function sessionWaitMs() {
|
|
1354
2212
|
const raw = Number(process.env.CDP_FIREFOX_SESSION_WAIT_MS);
|
|
@@ -1357,7 +2215,7 @@ function sessionWaitMs() {
|
|
|
1357
2215
|
async function readSessionSlot(endpoint) {
|
|
1358
2216
|
let raw;
|
|
1359
2217
|
try {
|
|
1360
|
-
raw = await
|
|
2218
|
+
raw = await readFile9(sessionSlotFile(endpoint), "utf8");
|
|
1361
2219
|
} catch (err) {
|
|
1362
2220
|
if (err.code === "ENOENT")
|
|
1363
2221
|
return;
|
|
@@ -2018,379 +2876,66 @@ function forceClearOrphanSession(marionettePort, opts = {}) {
|
|
|
2018
2876
|
resolve(false);
|
|
2019
2877
|
return;
|
|
2020
2878
|
}
|
|
2021
|
-
const sock = new Socket;
|
|
2022
|
-
const decoder = new FrameDecoder;
|
|
2023
|
-
let settled = false;
|
|
2024
|
-
let handshakeSeen = false;
|
|
2025
|
-
let commandSent = false;
|
|
2026
|
-
const settle = (value) => {
|
|
2027
|
-
if (settled)
|
|
2028
|
-
return;
|
|
2029
|
-
settled = true;
|
|
2030
|
-
clearTimeout(timer);
|
|
2031
|
-
sock.removeAllListeners();
|
|
2032
|
-
sock.destroy();
|
|
2033
|
-
resolve(value);
|
|
2034
|
-
};
|
|
2035
|
-
const timer = setTimeout(() => settle(false), timeoutMs);
|
|
2036
|
-
if (typeof timer.unref === "function")
|
|
2037
|
-
timer.unref();
|
|
2038
|
-
sock.on("error", () => settle(false));
|
|
2039
|
-
sock.on("close", () => settle(false));
|
|
2040
|
-
sock.on("data", (chunk) => {
|
|
2041
|
-
if (settled)
|
|
2042
|
-
return;
|
|
2043
|
-
try {
|
|
2044
|
-
decoder.push(chunk);
|
|
2045
|
-
for (;; ) {
|
|
2046
|
-
const frame = decoder.next();
|
|
2047
|
-
if (frame === undefined)
|
|
2048
|
-
break;
|
|
2049
|
-
if (!handshakeSeen) {
|
|
2050
|
-
handshakeSeen = true;
|
|
2051
|
-
continue;
|
|
2052
|
-
}
|
|
2053
|
-
settle(isSlotFreedReply(frame));
|
|
2054
|
-
return;
|
|
2055
|
-
}
|
|
2056
|
-
if (handshakeSeen && !commandSent) {
|
|
2057
|
-
commandSent = true;
|
|
2058
|
-
sock.write(DELETE_SESSION_FRAME);
|
|
2059
|
-
}
|
|
2060
|
-
} catch {
|
|
2061
|
-
settle(false);
|
|
2062
|
-
}
|
|
2063
|
-
});
|
|
2064
|
-
try {
|
|
2065
|
-
sock.connect(marionettePort, HOST);
|
|
2066
|
-
} catch {
|
|
2067
|
-
settle(false);
|
|
2068
|
-
}
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
var DEFAULT_MARIONETTE_PORT = 2828, DEFAULT_TIMEOUT_MS4 = 4000, HOST = "127.0.0.1", COLON = 58, DELETE_SESSION_FRAME, MarionetteProtocolError;
|
|
2072
|
-
var init_marionette = __esm(() => {
|
|
2073
|
-
DELETE_SESSION_FRAME = encodeFrame2([0, 1, "WebDriver:DeleteSession", {}]);
|
|
2074
|
-
MarionetteProtocolError = class MarionetteProtocolError extends Error {
|
|
2075
|
-
constructor(message) {
|
|
2076
|
-
super(message);
|
|
2077
|
-
this.name = "MarionetteProtocolError";
|
|
2078
|
-
}
|
|
2079
|
-
};
|
|
2080
|
-
});
|
|
2081
|
-
|
|
2082
|
-
// src/bidi/snapshot.ts
|
|
2083
|
-
async function takeStampedSnapshot(evaluate) {
|
|
2084
|
-
const raw = await evaluate(buildSnapshotFunctionSource());
|
|
2085
|
-
return coerceSnapshotResult(raw);
|
|
2086
|
-
}
|
|
2087
|
-
function coerceSnapshotResult(raw) {
|
|
2088
|
-
if (typeof raw !== "object" || raw === null || typeof raw.snapshot !== "string" || typeof raw.nodeCount !== "number") {
|
|
2089
|
-
throw new Error("takeStampedSnapshot: evaluate() returned an unexpected shape");
|
|
2090
|
-
}
|
|
2091
|
-
return { snapshot: raw.snapshot, nodeCount: raw.nodeCount };
|
|
2092
|
-
}
|
|
2093
|
-
function buildSnapshotFunctionSource() {
|
|
2094
|
-
return `function() {
|
|
2095
|
-
var STAMP_ATTR = ${JSON.stringify(STAMP_ATTR)};
|
|
2096
|
-
var MAX_NAME_LENGTH = ${MAX_NAME_LENGTH};
|
|
2097
|
-
var lines = [];
|
|
2098
|
-
var nodeCount = 0;
|
|
2099
|
-
|
|
2100
|
-
// THE UID CODEC (driver.ts) documents a bidi payload as exactly 12 lowercase hex chars,
|
|
2101
|
-
// /^[0-9a-f]{12}$/. Build it from two padded random blocks so the length is exact regardless
|
|
2102
|
-
// of the random value drawn, never from string concatenation that could come up short.
|
|
2103
|
-
function nextStamp() {
|
|
2104
|
-
var hi = Math.floor(Math.random() * 0x100000000).toString(16).padStart(8, "0");
|
|
2105
|
-
var lo = Math.floor(Math.random() * 0x10000).toString(16).padStart(4, "0");
|
|
2106
|
-
return hi + lo;
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
function stampOf(el) {
|
|
2110
|
-
var existing = el.getAttribute(STAMP_ATTR);
|
|
2111
|
-
if (existing) return existing;
|
|
2112
|
-
var stamp = nextStamp();
|
|
2113
|
-
el.setAttribute(STAMP_ATTR, stamp);
|
|
2114
|
-
return stamp;
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
// skipSizeCheck exempts <option>/<optgroup> from the zero-size prune: a
|
|
2118
|
-
// closed select's popup is unpainted (0x0) though its options are still
|
|
2119
|
-
// present and pickable. Other visibility rules still apply to them.
|
|
2120
|
-
function isVisible(el, skipSizeCheck) {
|
|
2121
|
-
if (el.hidden) return false;
|
|
2122
|
-
if (el.getAttribute("aria-hidden") === "true") return false;
|
|
2123
|
-
var style;
|
|
2124
|
-
try {
|
|
2125
|
-
style = el.ownerDocument.defaultView.getComputedStyle(el);
|
|
2126
|
-
} catch (e) {
|
|
2127
|
-
style = null;
|
|
2128
|
-
}
|
|
2129
|
-
if (style) {
|
|
2130
|
-
if (style.display === "none" || style.visibility === "hidden") return false;
|
|
2131
|
-
}
|
|
2132
|
-
if (!skipSizeCheck) {
|
|
2133
|
-
var rect = el.getBoundingClientRect();
|
|
2134
|
-
if (rect.width === 0 && rect.height === 0) return false;
|
|
2135
|
-
}
|
|
2136
|
-
return true;
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
function truncate(s) {
|
|
2140
|
-
s = s.trim().replace(/\\s+/g, " ");
|
|
2141
|
-
if (s.length > MAX_NAME_LENGTH) return s.slice(0, MAX_NAME_LENGTH - 1) + "\\u2026";
|
|
2142
|
-
return s;
|
|
2143
|
-
}
|
|
2144
|
-
|
|
2145
|
-
function textOf(el) {
|
|
2146
|
-
return el.textContent || "";
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
function idRefsText(doc, ids) {
|
|
2150
|
-
var parts = [];
|
|
2151
|
-
var list = ids.trim().split(/\\s+/);
|
|
2152
|
-
for (var i = 0; i < list.length; i++) {
|
|
2153
|
-
var ref = doc.getElementById(list[i]);
|
|
2154
|
-
if (ref) parts.push(textOf(ref));
|
|
2155
|
-
}
|
|
2156
|
-
return parts.join(" ").trim();
|
|
2157
|
-
}
|
|
2158
|
-
|
|
2159
|
-
// Text of a <label>, minus any nested form control's own content: a
|
|
2160
|
-
// label that WRAPS its control ("<label>Color <select>...</select></label>")
|
|
2161
|
-
// would otherwise include every option's text in the control's own name.
|
|
2162
|
-
function labelOwnText(label) {
|
|
2163
|
-
var clone = label.cloneNode(true);
|
|
2164
|
-
var controls = clone.querySelectorAll("input, select, textarea, button");
|
|
2165
|
-
for (var i = 0; i < controls.length; i++) {
|
|
2166
|
-
controls[i].parentNode.removeChild(controls[i]);
|
|
2167
|
-
}
|
|
2168
|
-
return textOf(clone);
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
// Guard: without this, an <option> inside a labelled <select> would
|
|
2172
|
-
// inherit the select's own label via closest("label"), not its text.
|
|
2173
|
-
var LABELABLE_TAGS = { INPUT: 1, TEXTAREA: 1, SELECT: 1, BUTTON: 1, METER: 1, OUTPUT: 1, PROGRESS: 1 };
|
|
2174
|
-
|
|
2175
|
-
function nativeLabelText(el) {
|
|
2176
|
-
if (!LABELABLE_TAGS[el.tagName]) return "";
|
|
2177
|
-
var doc = el.ownerDocument;
|
|
2178
|
-
if (el.id) {
|
|
2179
|
-
var forLabel = doc.querySelector('label[for="' + el.id + '"]');
|
|
2180
|
-
if (forLabel) return labelOwnText(forLabel);
|
|
2181
|
-
}
|
|
2182
|
-
var ancestor = el.closest ? el.closest("label") : null;
|
|
2183
|
-
if (ancestor) return labelOwnText(ancestor);
|
|
2184
|
-
return "";
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
// Reduced accname: aria-labelledby, then aria-label, then native label,
|
|
2188
|
-
// then alt/title/placeholder, then trimmed own text for content-named
|
|
2189
|
-
// elements. Not the full W3C accname algorithm (no recursive traversal
|
|
2190
|
-
// rules for nested presentational content) but covers the common cases.
|
|
2191
|
-
function accessibleName(el, contentNamed) {
|
|
2192
|
-
var doc = el.ownerDocument;
|
|
2193
|
-
var labelledby = el.getAttribute("aria-labelledby");
|
|
2194
|
-
if (labelledby) {
|
|
2195
|
-
var viaIds = idRefsText(doc, labelledby);
|
|
2196
|
-
if (viaIds) return truncate(viaIds);
|
|
2197
|
-
}
|
|
2198
|
-
var ariaLabel = el.getAttribute("aria-label");
|
|
2199
|
-
if (ariaLabel && ariaLabel.trim()) return truncate(ariaLabel);
|
|
2200
|
-
var native = nativeLabelText(el);
|
|
2201
|
-
if (native && native.trim()) return truncate(native);
|
|
2202
|
-
var alt = el.getAttribute("alt");
|
|
2203
|
-
if (alt && alt.trim()) return truncate(alt);
|
|
2204
|
-
var title = el.getAttribute("title");
|
|
2205
|
-
if (title && title.trim()) return truncate(title);
|
|
2206
|
-
var placeholder = el.getAttribute("placeholder");
|
|
2207
|
-
if (placeholder && placeholder.trim()) return truncate(placeholder);
|
|
2208
|
-
if (contentNamed) {
|
|
2209
|
-
var text = textOf(el);
|
|
2210
|
-
if (text && text.trim()) return truncate(text);
|
|
2211
|
-
}
|
|
2212
|
-
return "";
|
|
2213
|
-
}
|
|
2214
|
-
|
|
2215
|
-
var IMPLICIT_ROLE_BY_TAG = {
|
|
2216
|
-
A: "link", BUTTON: "button", NAV: "navigation", MAIN: "main", FORM: "form", DIALOG: "dialog",
|
|
2217
|
-
UL: "list", OL: "list", LI: "listitem", TABLE: "table", TR: "row", TD: "cell", TH: "columnheader",
|
|
2218
|
-
SELECT: "combobox", OPTION: "option", TEXTAREA: "textbox", IMG: "img",
|
|
2219
|
-
H1: "heading", H2: "heading", H3: "heading", H4: "heading", H5: "heading", H6: "heading",
|
|
2220
|
-
PROGRESS: "progressbar", METER: "meter"
|
|
2221
|
-
};
|
|
2222
|
-
|
|
2223
|
-
var INPUT_TYPE_ROLE = {
|
|
2224
|
-
button: "button", submit: "button", reset: "button", checkbox: "checkbox", radio: "radio",
|
|
2225
|
-
range: "slider", number: "spinbutton", search: "searchbox", email: "textbox", tel: "textbox",
|
|
2226
|
-
url: "textbox", password: "textbox", text: "textbox", image: "button"
|
|
2227
|
-
};
|
|
2228
|
-
|
|
2229
|
-
var CONTENT_NAMED_ROLES = {
|
|
2230
|
-
button: true, link: true, heading: true, option: true, cell: true,
|
|
2231
|
-
columnheader: true, listitem: true, menuitem: true, tab: true
|
|
2232
|
-
};
|
|
2233
|
-
|
|
2234
|
-
function implicitRole(el) {
|
|
2235
|
-
var explicit = el.getAttribute("role");
|
|
2236
|
-
if (explicit) return explicit;
|
|
2237
|
-
var tag = el.tagName;
|
|
2238
|
-
if (tag === "INPUT") {
|
|
2239
|
-
var type = (el.getAttribute("type") || "text").toLowerCase();
|
|
2240
|
-
return INPUT_TYPE_ROLE[type] || "textbox";
|
|
2241
|
-
}
|
|
2242
|
-
if (tag === "A" && !el.getAttribute("href")) return "";
|
|
2243
|
-
if (Object.prototype.hasOwnProperty.call(IMPLICIT_ROLE_BY_TAG, tag)) {
|
|
2244
|
-
return IMPLICIT_ROLE_BY_TAG[tag];
|
|
2245
|
-
}
|
|
2246
|
-
// Deliberate divergence: Chrome's real AX tree says "generic" here,
|
|
2247
|
-
// but "textbox" is the useful signal an agent needs. Chrome is out of
|
|
2248
|
-
// step, do not "fix" this toward parity.
|
|
2249
|
-
if (el.isContentEditable) return "textbox";
|
|
2250
|
-
return "";
|
|
2251
|
-
}
|
|
2252
|
-
|
|
2253
|
-
function headingLevel(el) {
|
|
2254
|
-
var m = /^H([1-6])$/.exec(el.tagName);
|
|
2255
|
-
return m ? m[1] : null;
|
|
2256
|
-
}
|
|
2257
|
-
|
|
2258
|
-
function currentValue(el) {
|
|
2259
|
-
var tag = el.tagName;
|
|
2260
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") {
|
|
2261
|
-
return el.value;
|
|
2262
|
-
}
|
|
2263
|
-
if (el.isContentEditable) return textOf(el);
|
|
2264
|
-
return undefined;
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
function isChecked(el) {
|
|
2268
|
-
var tag = el.tagName;
|
|
2269
|
-
if (tag === "INPUT") {
|
|
2270
|
-
var type = (el.getAttribute("type") || "").toLowerCase();
|
|
2271
|
-
if (type === "checkbox" || type === "radio") return !!el.checked;
|
|
2272
|
-
}
|
|
2273
|
-
var aria = el.getAttribute("aria-checked");
|
|
2274
|
-
if (aria === "true") return true;
|
|
2275
|
-
return false;
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
function describeNode(el, role) {
|
|
2279
|
-
var contentNamed = !!CONTENT_NAMED_ROLES[role];
|
|
2280
|
-
var name = accessibleName(el, contentNamed);
|
|
2281
|
-
var extras = [];
|
|
2282
|
-
var value = currentValue(el);
|
|
2283
|
-
if (value !== undefined && value !== "") extras.push("value=" + JSON.stringify(String(value)));
|
|
2284
|
-
if (isChecked(el)) extras.push("checked=true");
|
|
2285
|
-
if (el.tagName === "OPTION" && el.selected) extras.push("selected");
|
|
2286
|
-
var href = el.getAttribute("href");
|
|
2287
|
-
if (href) extras.push("url=" + href);
|
|
2288
|
-
if (el.disabled || el.getAttribute("aria-disabled") === "true") extras.push("disabled");
|
|
2289
|
-
var level = headingLevel(el);
|
|
2290
|
-
if (level) extras.push("level=" + level);
|
|
2291
|
-
var label = name ? " " + JSON.stringify(name) : "";
|
|
2292
|
-
var extra = extras.length ? " [" + extras.join(" ") + "]" : "";
|
|
2293
|
-
return { role: role, label: label, extra: extra, name: name };
|
|
2294
|
-
}
|
|
2295
|
-
|
|
2296
|
-
// Traverses light DOM, open shadow roots, and same-origin iframe documents.
|
|
2297
|
-
// A cross-origin iframe throws on contentDocument access; caught and
|
|
2298
|
-
// skipped rather than aborting the whole walk, and noted in a comment
|
|
2299
|
-
// here rather than silently vanishing from the tree without a trace.
|
|
2300
|
-
function walk(root, depth) {
|
|
2301
|
-
var children = root.children ? Array.prototype.slice.call(root.children) : [];
|
|
2302
|
-
for (var i = 0; i < children.length; i++) {
|
|
2303
|
-
var el = children[i];
|
|
2304
|
-
var isSelectChild = el.tagName === "OPTION" || el.tagName === "OPTGROUP";
|
|
2305
|
-
if (!isVisible(el, isSelectChild)) continue;
|
|
2306
|
-
|
|
2307
|
-
var role = implicitRole(el);
|
|
2308
|
-
var isLandmarkOrControl = !!role;
|
|
2309
|
-
var described = null;
|
|
2310
|
-
if (isLandmarkOrControl) {
|
|
2311
|
-
described = describeNode(el, role);
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
var hasContent = described && (described.name || described.extra);
|
|
2315
|
-
var isStructural = isLandmarkOrControl && (hasContent || isInteractiveRole(role) || isLandmarkRole(role));
|
|
2316
|
-
|
|
2317
|
-
// Role-less visible leaf text (measured vs Chrome's take_snapshot,
|
|
2318
|
-
// which keeps a StaticText under a generic wrapper for this case,
|
|
2319
|
-
// e.g. a plain status <div>). Only a leaf (no element children, so
|
|
2320
|
-
// its text is not already captured by a nested control/label).
|
|
2321
|
-
var hasElementChildren = !!(el.children && el.children.length > 0);
|
|
2322
|
-
var leafName = !isStructural && !hasElementChildren ? truncate(textOf(el)) : "";
|
|
2323
|
-
var isLeafText = !!leafName;
|
|
2324
|
-
|
|
2325
|
-
var nextDepth = depth;
|
|
2326
|
-
if (isStructural || isLeafText) {
|
|
2327
|
-
var stamp = stampOf(el);
|
|
2328
|
-
var indent = new Array(depth + 1).join(" ");
|
|
2329
|
-
var lineTail = isStructural
|
|
2330
|
-
? described.role + described.label + described.extra
|
|
2331
|
-
: "text " + JSON.stringify(leafName);
|
|
2332
|
-
lines.push(indent + "[" + stamp + "] " + lineTail);
|
|
2333
|
-
nodeCount += 1;
|
|
2334
|
-
nextDepth = depth + 1;
|
|
2335
|
-
}
|
|
2336
|
-
|
|
2337
|
-
if (el.shadowRoot) {
|
|
2338
|
-
walk(el.shadowRoot, nextDepth);
|
|
2339
|
-
} else if (el.tagName === "IFRAME") {
|
|
2340
|
-
try {
|
|
2341
|
-
var doc = el.contentDocument;
|
|
2342
|
-
if (doc && doc.body) walk(doc.body, nextDepth);
|
|
2343
|
-
} catch (e) {
|
|
2344
|
-
// cross-origin iframe: intentionally skipped, not silently merged
|
|
2345
|
-
// into the parent tree as though it were empty.
|
|
2879
|
+
const sock = new Socket;
|
|
2880
|
+
const decoder = new FrameDecoder;
|
|
2881
|
+
let settled = false;
|
|
2882
|
+
let handshakeSeen = false;
|
|
2883
|
+
let commandSent = false;
|
|
2884
|
+
const settle = (value) => {
|
|
2885
|
+
if (settled)
|
|
2886
|
+
return;
|
|
2887
|
+
settled = true;
|
|
2888
|
+
clearTimeout(timer);
|
|
2889
|
+
sock.removeAllListeners();
|
|
2890
|
+
sock.destroy();
|
|
2891
|
+
resolve(value);
|
|
2892
|
+
};
|
|
2893
|
+
const timer = setTimeout(() => settle(false), timeoutMs);
|
|
2894
|
+
if (typeof timer.unref === "function")
|
|
2895
|
+
timer.unref();
|
|
2896
|
+
sock.on("error", () => settle(false));
|
|
2897
|
+
sock.on("close", () => settle(false));
|
|
2898
|
+
sock.on("data", (chunk) => {
|
|
2899
|
+
if (settled)
|
|
2900
|
+
return;
|
|
2901
|
+
try {
|
|
2902
|
+
decoder.push(chunk);
|
|
2903
|
+
for (;; ) {
|
|
2904
|
+
const frame = decoder.next();
|
|
2905
|
+
if (frame === undefined)
|
|
2906
|
+
break;
|
|
2907
|
+
if (!handshakeSeen) {
|
|
2908
|
+
handshakeSeen = true;
|
|
2909
|
+
continue;
|
|
2346
2910
|
}
|
|
2347
|
-
|
|
2348
|
-
|
|
2911
|
+
settle(isSlotFreedReply(frame));
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
if (handshakeSeen && !commandSent) {
|
|
2915
|
+
commandSent = true;
|
|
2916
|
+
sock.write(DELETE_SESSION_FRAME);
|
|
2349
2917
|
}
|
|
2918
|
+
} catch {
|
|
2919
|
+
settle(false);
|
|
2350
2920
|
}
|
|
2921
|
+
});
|
|
2922
|
+
try {
|
|
2923
|
+
sock.connect(marionettePort, HOST);
|
|
2924
|
+
} catch {
|
|
2925
|
+
settle(false);
|
|
2351
2926
|
}
|
|
2352
|
-
|
|
2353
|
-
function isInteractiveRole(role) {
|
|
2354
|
-
return (
|
|
2355
|
-
role === "button" ||
|
|
2356
|
-
role === "link" ||
|
|
2357
|
-
role === "textbox" ||
|
|
2358
|
-
role === "searchbox" ||
|
|
2359
|
-
role === "checkbox" ||
|
|
2360
|
-
role === "radio" ||
|
|
2361
|
-
role === "combobox" ||
|
|
2362
|
-
role === "listbox" ||
|
|
2363
|
-
role === "option" ||
|
|
2364
|
-
role === "slider" ||
|
|
2365
|
-
role === "spinbutton" ||
|
|
2366
|
-
role === "progressbar" ||
|
|
2367
|
-
role === "meter"
|
|
2368
|
-
);
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
function isLandmarkRole(role) {
|
|
2372
|
-
return (
|
|
2373
|
-
role === "navigation" ||
|
|
2374
|
-
role === "main" ||
|
|
2375
|
-
role === "form" ||
|
|
2376
|
-
role === "dialog" ||
|
|
2377
|
-
role === "region" ||
|
|
2378
|
-
role === "heading" ||
|
|
2379
|
-
role === "list" ||
|
|
2380
|
-
role === "listitem" ||
|
|
2381
|
-
role === "table" ||
|
|
2382
|
-
role === "row" ||
|
|
2383
|
-
role === "cell" ||
|
|
2384
|
-
role === "columnheader" ||
|
|
2385
|
-
role === "img"
|
|
2386
|
-
);
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
walk(document.body, 0);
|
|
2390
|
-
return { snapshot: lines.join("\\n"), nodeCount: nodeCount };
|
|
2391
|
-
}`;
|
|
2927
|
+
});
|
|
2392
2928
|
}
|
|
2393
|
-
var
|
|
2929
|
+
var DEFAULT_MARIONETTE_PORT = 2828, DEFAULT_TIMEOUT_MS4 = 4000, HOST = "127.0.0.1", COLON = 58, DELETE_SESSION_FRAME, MarionetteProtocolError;
|
|
2930
|
+
var init_marionette = __esm(() => {
|
|
2931
|
+
DELETE_SESSION_FRAME = encodeFrame2([0, 1, "WebDriver:DeleteSession", {}]);
|
|
2932
|
+
MarionetteProtocolError = class MarionetteProtocolError extends Error {
|
|
2933
|
+
constructor(message) {
|
|
2934
|
+
super(message);
|
|
2935
|
+
this.name = "MarionetteProtocolError";
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
});
|
|
2394
2939
|
|
|
2395
2940
|
// src/bidi/driver.ts
|
|
2396
2941
|
import { spawn as spawn3 } from "node:child_process";
|
|
@@ -3756,7 +4301,9 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
3756
4301
|
|
|
3757
4302
|
// src/cdp/driver.ts
|
|
3758
4303
|
init_client();
|
|
4304
|
+
init_session();
|
|
3759
4305
|
init_leases();
|
|
4306
|
+
init_endpoints();
|
|
3760
4307
|
init_activity();
|
|
3761
4308
|
|
|
3762
4309
|
// src/tools/snapshot.ts
|
|
@@ -4244,7 +4791,7 @@ class CdpPageDriver {
|
|
|
4244
4791
|
await this.conn.send(`${name}.enable`);
|
|
4245
4792
|
}
|
|
4246
4793
|
async dispatchInput(method, params = {}) {
|
|
4247
|
-
return sendInput(this.conn,
|
|
4794
|
+
return sendInput(this.conn, chromeLeaseBackend(), this.info.id, method, params);
|
|
4248
4795
|
}
|
|
4249
4796
|
async ensureDomainSoft(name) {
|
|
4250
4797
|
if (this.enabledDomains.has(name))
|
|
@@ -4838,9 +5385,21 @@ class CdpPageDriver {
|
|
|
4838
5385
|
}
|
|
4839
5386
|
}
|
|
4840
5387
|
var beaconSessions = new BeaconSessions((conn) => conn.close());
|
|
4841
|
-
|
|
5388
|
+
function beaconKey(targetId) {
|
|
5389
|
+
const backend = chromeLeaseBackend(currentEndpoint());
|
|
5390
|
+
return backend === "chrome" ? targetId : `${backend}\x00${targetId}`;
|
|
5391
|
+
}
|
|
5392
|
+
async function openTargetConn(targetId, opts = {}) {
|
|
4842
5393
|
const hit = (await listTargets()).find((t) => t.id === targetId);
|
|
4843
|
-
|
|
5394
|
+
if (!hit)
|
|
5395
|
+
return;
|
|
5396
|
+
if (!hit.webSocketDebuggerUrl)
|
|
5397
|
+
return openSession(targetId, opts).catch(() => {
|
|
5398
|
+
return;
|
|
5399
|
+
});
|
|
5400
|
+
return new CdpConnection(hit.webSocketDebuggerUrl, opts).connect().catch(() => {
|
|
5401
|
+
return;
|
|
5402
|
+
});
|
|
4844
5403
|
}
|
|
4845
5404
|
async function readBeaconOver(conn) {
|
|
4846
5405
|
try {
|
|
@@ -4939,7 +5498,7 @@ class CdpBrowserDriver {
|
|
|
4939
5498
|
return withBrowserConn(async (conn) => {
|
|
4940
5499
|
const res = await conn.send("Target.closeTarget", { targetId: id });
|
|
4941
5500
|
if (res.success !== false)
|
|
4942
|
-
beaconSessions.drop(id);
|
|
5501
|
+
beaconSessions.drop(beaconKey(id));
|
|
4943
5502
|
return { success: res.success ?? true };
|
|
4944
5503
|
});
|
|
4945
5504
|
}
|
|
@@ -4957,19 +5516,15 @@ class CdpBrowserDriver {
|
|
|
4957
5516
|
return new CdpPageDriver(conn, target, this);
|
|
4958
5517
|
}
|
|
4959
5518
|
async installActivityBeacon(targetId) {
|
|
4960
|
-
const
|
|
5519
|
+
const key = beaconKey(targetId);
|
|
5520
|
+
const held = beaconSessions.get(key);
|
|
4961
5521
|
if (held) {
|
|
4962
5522
|
const rearmed = await held.send("Runtime.evaluate", { expression: BEACON_SOURCE, returnByValue: true }).then(() => true).catch(() => false);
|
|
4963
5523
|
if (rearmed)
|
|
4964
5524
|
return true;
|
|
4965
|
-
beaconSessions.drop(
|
|
5525
|
+
beaconSessions.drop(key);
|
|
4966
5526
|
}
|
|
4967
|
-
const
|
|
4968
|
-
return;
|
|
4969
|
-
});
|
|
4970
|
-
if (!wsUrl)
|
|
4971
|
-
return false;
|
|
4972
|
-
const conn = await new CdpConnection(wsUrl).connect().catch(() => {
|
|
5527
|
+
const conn = await openTargetConn(targetId).catch(() => {
|
|
4973
5528
|
return;
|
|
4974
5529
|
});
|
|
4975
5530
|
if (!conn)
|
|
@@ -4982,23 +5537,19 @@ class CdpBrowserDriver {
|
|
|
4982
5537
|
conn.close();
|
|
4983
5538
|
return false;
|
|
4984
5539
|
}
|
|
4985
|
-
beaconSessions.set(
|
|
5540
|
+
beaconSessions.set(key, conn);
|
|
4986
5541
|
return true;
|
|
4987
5542
|
}
|
|
4988
5543
|
async readActivityBeacon(targetId) {
|
|
4989
|
-
const
|
|
5544
|
+
const key = beaconKey(targetId);
|
|
5545
|
+
const held = beaconSessions.get(key);
|
|
4990
5546
|
if (held) {
|
|
4991
5547
|
const value = await readBeaconOver(held);
|
|
4992
5548
|
if (value !== undefined)
|
|
4993
5549
|
return value;
|
|
4994
|
-
beaconSessions.drop(
|
|
5550
|
+
beaconSessions.drop(key);
|
|
4995
5551
|
}
|
|
4996
|
-
const
|
|
4997
|
-
return;
|
|
4998
|
-
});
|
|
4999
|
-
if (!wsUrl)
|
|
5000
|
-
return null;
|
|
5001
|
-
const conn = await new CdpConnection(wsUrl).connect().catch(() => {
|
|
5552
|
+
const conn = await openTargetConn(targetId).catch(() => {
|
|
5002
5553
|
return;
|
|
5003
5554
|
});
|
|
5004
5555
|
if (!conn)
|
|
@@ -5010,20 +5561,14 @@ class CdpBrowserDriver {
|
|
|
5010
5561
|
}
|
|
5011
5562
|
}
|
|
5012
5563
|
async probeRenderer(targetId, timeoutMs = RENDERER_PROBE_TIMEOUT_MS) {
|
|
5013
|
-
const held = beaconSessions.get(targetId);
|
|
5564
|
+
const held = beaconSessions.get(beaconKey(targetId));
|
|
5014
5565
|
if (held)
|
|
5015
5566
|
return probeOver(held, timeoutMs);
|
|
5016
|
-
const
|
|
5567
|
+
const conn = await openTargetConn(targetId, { timeoutMs }).catch(() => {
|
|
5017
5568
|
return;
|
|
5018
5569
|
});
|
|
5019
|
-
if (!
|
|
5020
|
-
return { responsive: false, beaconTs: null };
|
|
5021
|
-
const conn = new CdpConnection(wsUrl, { timeoutMs });
|
|
5022
|
-
try {
|
|
5023
|
-
await conn.connect();
|
|
5024
|
-
} catch {
|
|
5570
|
+
if (!conn)
|
|
5025
5571
|
return { responsive: false, beaconTs: null };
|
|
5026
|
-
}
|
|
5027
5572
|
try {
|
|
5028
5573
|
return await probeOver(conn, timeoutMs);
|
|
5029
5574
|
} finally {
|
|
@@ -5043,6 +5588,7 @@ init_activity();
|
|
|
5043
5588
|
init_origins();
|
|
5044
5589
|
|
|
5045
5590
|
// src/reap.ts
|
|
5591
|
+
init_endpoints();
|
|
5046
5592
|
init_leases();
|
|
5047
5593
|
init_origins();
|
|
5048
5594
|
function staleAgentTabs(input) {
|
|
@@ -5071,6 +5617,11 @@ function reapGraceMs() {
|
|
|
5071
5617
|
const raw = Number(process.env.CDP_REAP_GRACE_MS);
|
|
5072
5618
|
return Number.isFinite(raw) && raw >= 0 ? raw : DEFAULT_REAP_GRACE_MS;
|
|
5073
5619
|
}
|
|
5620
|
+
function reapAllowed(driver) {
|
|
5621
|
+
if (driver.scheme === "bidi")
|
|
5622
|
+
return true;
|
|
5623
|
+
return !currentEndpoint().readOnly;
|
|
5624
|
+
}
|
|
5074
5625
|
async function reapStaleAgentTabs(driver, backend) {
|
|
5075
5626
|
const now = Date.now();
|
|
5076
5627
|
const livePageIds = (await driver.listPages()).map((p) => p.id);
|
|
@@ -5093,7 +5644,7 @@ async function reapStaleAgentTabs(driver, backend) {
|
|
|
5093
5644
|
// src/shared-tools.ts
|
|
5094
5645
|
init_driver();
|
|
5095
5646
|
import { mkdir as mkdir5, writeFile as writeFile4 } from "node:fs/promises";
|
|
5096
|
-
import { dirname as dirname2, join as
|
|
5647
|
+
import { dirname as dirname2, join as join5 } from "node:path";
|
|
5097
5648
|
|
|
5098
5649
|
// src/png.ts
|
|
5099
5650
|
import { once } from "node:events";
|
|
@@ -5613,6 +6164,7 @@ init_activity();
|
|
|
5613
6164
|
init_origins();
|
|
5614
6165
|
init_workers();
|
|
5615
6166
|
init_frames();
|
|
6167
|
+
init_endpoints();
|
|
5616
6168
|
var ARTIFACT_DIR = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
5617
6169
|
var STATE_DIR = process.env.CDP_STATE_DIR ?? "/tmp/cdp-toolkit";
|
|
5618
6170
|
|
|
@@ -5622,7 +6174,7 @@ function target3(p) {
|
|
|
5622
6174
|
return { id: p.id, url: p.url, title: p.title };
|
|
5623
6175
|
}
|
|
5624
6176
|
function backendOf(driver) {
|
|
5625
|
-
return driver.scheme === "bidi" ? "firefox" :
|
|
6177
|
+
return driver.scheme === "bidi" ? "firefox" : chromeLeaseBackend();
|
|
5626
6178
|
}
|
|
5627
6179
|
async function withPage2(driver, target, fn) {
|
|
5628
6180
|
const page = await driver.page(target);
|
|
@@ -5710,8 +6262,44 @@ async function reapSet(driver, pages, all) {
|
|
|
5710
6262
|
}
|
|
5711
6263
|
}
|
|
5712
6264
|
async function listPages(driver, args = {}) {
|
|
6265
|
+
const one = { all: args.all, probe: args.probe };
|
|
6266
|
+
if (args.allEndpoints === true) {
|
|
6267
|
+
if (driver.scheme === "bidi")
|
|
6268
|
+
throw new SharedToolError("list_pages: allEndpoints needs the Chrome backend; named endpoints are CDP-only");
|
|
6269
|
+
const results = await Promise.all(allEndpoints().map((ep) => withEndpointScope(ep, () => listPagesOne(driver, one)).then((r) => ({ ep, r }), (e) => ({ ep, error: e instanceof Error ? e.message : String(e) }))));
|
|
6270
|
+
const pages = [];
|
|
6271
|
+
const reaped = [];
|
|
6272
|
+
const endpoints = [];
|
|
6273
|
+
for (const res of results) {
|
|
6274
|
+
const { ep } = res;
|
|
6275
|
+
if ("error" in res) {
|
|
6276
|
+
endpoints.push({ endpoint: ep.name, base: ep.base, readOnly: ep.readOnly, down: true, error: res.error });
|
|
6277
|
+
continue;
|
|
6278
|
+
}
|
|
6279
|
+
for (const p of res.r.pages)
|
|
6280
|
+
pages.push({ ...p, endpoint: ep.name });
|
|
6281
|
+
for (const t of res.r.reaped ?? [])
|
|
6282
|
+
reaped.push({ ...t, endpoint: ep.name });
|
|
6283
|
+
endpoints.push({ endpoint: ep.name, base: ep.base, readOnly: ep.readOnly, count: res.r.count });
|
|
6284
|
+
}
|
|
6285
|
+
return { pages, count: pages.length, ...reaped.length ? { reaped } : {}, endpoints };
|
|
6286
|
+
}
|
|
6287
|
+
const res = await listPagesOne(driver, one);
|
|
6288
|
+
if (driver.scheme !== "bidi") {
|
|
6289
|
+
const ep = currentEndpoint();
|
|
6290
|
+
if (!isDefaultEndpoint(ep)) {
|
|
6291
|
+
return {
|
|
6292
|
+
...res,
|
|
6293
|
+
pages: res.pages.map((p) => ({ ...p, endpoint: ep.name })),
|
|
6294
|
+
...res.reaped ? { reaped: res.reaped.map((t) => ({ ...t, endpoint: ep.name })) } : {}
|
|
6295
|
+
};
|
|
6296
|
+
}
|
|
6297
|
+
}
|
|
6298
|
+
return res;
|
|
6299
|
+
}
|
|
6300
|
+
async function listPagesOne(driver, args = {}) {
|
|
5713
6301
|
const backend = backendOf(driver);
|
|
5714
|
-
const reaped = requireLease() ? await reapStaleAgentTabs(driver, backend) : [];
|
|
6302
|
+
const reaped = requireLease() && reapAllowed(driver) ? await reapStaleAgentTabs(driver, backend) : [];
|
|
5715
6303
|
const reapedIds = new Set(reaped.map((r) => r.targetId));
|
|
5716
6304
|
const pages = (await driver.listPages({ all: args.all })).filter((p) => !reapedIds.has(p.id));
|
|
5717
6305
|
const ledger = await originIndex(backend, await reapSet(driver, pages, args.all));
|
|
@@ -5761,7 +6349,7 @@ async function closePage(driver, args) {
|
|
|
5761
6349
|
}
|
|
5762
6350
|
async function writeSelectedFile(id) {
|
|
5763
6351
|
await mkdir5(STATE_DIR, { recursive: true });
|
|
5764
|
-
await writeFile4(
|
|
6352
|
+
await writeFile4(join5(STATE_DIR, "selected"), id, "utf8");
|
|
5765
6353
|
}
|
|
5766
6354
|
async function selectPage(driver, args) {
|
|
5767
6355
|
if (args.target === undefined || args.target === "")
|
|
@@ -5825,7 +6413,7 @@ function serializeForSink(value) {
|
|
|
5825
6413
|
return json ?? "null";
|
|
5826
6414
|
}
|
|
5827
6415
|
async function writeJsonSink(savePath, value) {
|
|
5828
|
-
const path = savePath.startsWith("/") ? savePath :
|
|
6416
|
+
const path = savePath.startsWith("/") ? savePath : join5(ARTIFACT_DIR, savePath);
|
|
5829
6417
|
await mkdir5(dirname2(path), { recursive: true });
|
|
5830
6418
|
const json = serializeForSink(value);
|
|
5831
6419
|
await writeFile4(path, json, "utf8");
|
|
@@ -5969,10 +6557,45 @@ async function takeSnapshot(driver, args = {}) {
|
|
|
5969
6557
|
`), target: target3(page.info), nodeCount: nodes.length };
|
|
5970
6558
|
});
|
|
5971
6559
|
}
|
|
6560
|
+
function describeElementSource() {
|
|
6561
|
+
return `function() {
|
|
6562
|
+
var MAX_NAME_LENGTH = ${MAX_NAME_LENGTH};
|
|
6563
|
+
${ACCNAME_HELPERS_SOURCE}
|
|
6564
|
+
var el = this;
|
|
6565
|
+
if (!el || el.nodeType !== 1) return null;
|
|
6566
|
+
var role = implicitRole(el);
|
|
6567
|
+
var name = accessibleName(el, !!CONTENT_NAMED_ROLES[role]);
|
|
6568
|
+
if (!name) name = truncate(el.innerText || el.textContent || "");
|
|
6569
|
+
return (role || el.tagName.toLowerCase()) + (name ? " " + JSON.stringify(name) : "");
|
|
6570
|
+
}`;
|
|
6571
|
+
}
|
|
6572
|
+
var DESCRIBE_TIMEOUT_MS = 2000;
|
|
6573
|
+
async function describeElement(page, loc) {
|
|
6574
|
+
let timer;
|
|
6575
|
+
try {
|
|
6576
|
+
const timeout = new Promise((r) => {
|
|
6577
|
+
timer = setTimeout(() => r(undefined), DESCRIBE_TIMEOUT_MS);
|
|
6578
|
+
});
|
|
6579
|
+
const desc = await Promise.race([page.callOnElement(loc, describeElementSource()), timeout]);
|
|
6580
|
+
return typeof desc === "string" && desc.length > 0 ? desc : undefined;
|
|
6581
|
+
} catch {
|
|
6582
|
+
return;
|
|
6583
|
+
} finally {
|
|
6584
|
+
clearTimeout(timer);
|
|
6585
|
+
}
|
|
6586
|
+
}
|
|
6587
|
+
function isElementLocator(d) {
|
|
6588
|
+
return !("x" in d) && !("dx" in d);
|
|
6589
|
+
}
|
|
6590
|
+
function elementField(element) {
|
|
6591
|
+
return element === undefined ? {} : { element };
|
|
6592
|
+
}
|
|
5972
6593
|
async function click(driver, args) {
|
|
6594
|
+
const loc = locatorOf(args);
|
|
5973
6595
|
return withPage2(driver, args.target, async (page) => {
|
|
5974
|
-
const
|
|
5975
|
-
|
|
6596
|
+
const element = await describeElement(page, loc);
|
|
6597
|
+
const { x, y } = await page.click(loc, { button: args.button ?? "left", clickCount: args.clickCount ?? 1, modifiers: args.modifiers });
|
|
6598
|
+
return { clicked: true, ...elementField(element), x, y };
|
|
5976
6599
|
});
|
|
5977
6600
|
}
|
|
5978
6601
|
function resolveScrollAnchor(args) {
|
|
@@ -6008,9 +6631,11 @@ async function scroll(driver, args) {
|
|
|
6008
6631
|
});
|
|
6009
6632
|
}
|
|
6010
6633
|
async function hover(driver, args) {
|
|
6634
|
+
const loc = locatorOf(args);
|
|
6011
6635
|
return withPage2(driver, args.target, async (page) => {
|
|
6012
|
-
const
|
|
6013
|
-
|
|
6636
|
+
const element = await describeElement(page, loc);
|
|
6637
|
+
const { x, y } = await page.hover(loc);
|
|
6638
|
+
return { hovered: true, ...elementField(element), x, y };
|
|
6014
6639
|
});
|
|
6015
6640
|
}
|
|
6016
6641
|
function resolveDragTo(to) {
|
|
@@ -6076,16 +6701,29 @@ async function drag(driver, args) {
|
|
|
6076
6701
|
const steps = resolveDragSteps(args.steps);
|
|
6077
6702
|
const mode = resolveDragMode(args.mode, driver.capabilities);
|
|
6078
6703
|
return withPage2(driver, args.target, async (page) => {
|
|
6079
|
-
const
|
|
6080
|
-
|
|
6704
|
+
const fromLoc = locatorOf(args.from);
|
|
6705
|
+
const element = await describeElement(page, fromLoc);
|
|
6706
|
+
const targetElement = isElementLocator(destination) ? await describeElement(page, destination) : undefined;
|
|
6707
|
+
const { from, to } = await page.drag(fromLoc, destination, { mode, steps });
|
|
6708
|
+
return {
|
|
6709
|
+
dragged: true,
|
|
6710
|
+
...elementField(element),
|
|
6711
|
+
...targetElement === undefined ? {} : { target_element: targetElement },
|
|
6712
|
+
mode,
|
|
6713
|
+
steps,
|
|
6714
|
+
from,
|
|
6715
|
+
to
|
|
6716
|
+
};
|
|
6081
6717
|
});
|
|
6082
6718
|
}
|
|
6083
6719
|
async function fill(driver, args) {
|
|
6084
6720
|
if (typeof args.value !== "string")
|
|
6085
6721
|
throw new SharedToolError("fill requires a string { value }");
|
|
6722
|
+
const loc = locatorOf(args);
|
|
6086
6723
|
return withPage2(driver, args.target, async (page) => {
|
|
6087
|
-
await page
|
|
6088
|
-
|
|
6724
|
+
const element = await describeElement(page, loc);
|
|
6725
|
+
await page.setValue(loc, args.value);
|
|
6726
|
+
return { filled: true, ...elementField(element), value: args.value };
|
|
6089
6727
|
});
|
|
6090
6728
|
}
|
|
6091
6729
|
async function fillForm(driver, args) {
|
|
@@ -6093,21 +6731,26 @@ async function fillForm(driver, args) {
|
|
|
6093
6731
|
throw new SharedToolError("fill_form requires a non-empty { fields } array");
|
|
6094
6732
|
return withPage2(driver, args.target, async (page) => {
|
|
6095
6733
|
let filled = 0;
|
|
6734
|
+
const elements = [];
|
|
6096
6735
|
for (const f of args.fields) {
|
|
6097
6736
|
if (typeof f.value !== "string")
|
|
6098
6737
|
throw new SharedToolError("each fill_form field requires a string value");
|
|
6099
|
-
|
|
6738
|
+
const loc = locatorOf(f);
|
|
6739
|
+
elements.push(await describeElement(page, loc) ?? null);
|
|
6740
|
+
await page.setValue(loc, f.value);
|
|
6100
6741
|
filled++;
|
|
6101
6742
|
}
|
|
6102
|
-
return { filled, fields: args.fields.length };
|
|
6743
|
+
return { filled, fields: args.fields.length, elements };
|
|
6103
6744
|
});
|
|
6104
6745
|
}
|
|
6105
6746
|
async function typeText(driver, args) {
|
|
6106
6747
|
if (typeof args.text !== "string")
|
|
6107
6748
|
throw new SharedToolError("type_text requires a string { text }");
|
|
6749
|
+
const loc = locatorOf(args);
|
|
6108
6750
|
return withPage2(driver, args.target, async (page) => {
|
|
6109
|
-
await page
|
|
6110
|
-
|
|
6751
|
+
const element = await describeElement(page, loc);
|
|
6752
|
+
await page.typeText(loc, args.text);
|
|
6753
|
+
return { typed: true, ...elementField(element), text: args.text };
|
|
6111
6754
|
});
|
|
6112
6755
|
}
|
|
6113
6756
|
async function pressKey(driver, args) {
|
|
@@ -6125,8 +6768,10 @@ async function uploadFile(driver, args) {
|
|
|
6125
6768
|
throw new SharedToolError("upload_file requires { files } as a non-empty path or array of paths");
|
|
6126
6769
|
}
|
|
6127
6770
|
return withPage2(driver, args.target, async (page) => {
|
|
6128
|
-
|
|
6129
|
-
|
|
6771
|
+
const loc = locatorOf(args);
|
|
6772
|
+
const element = await describeElement(page, loc);
|
|
6773
|
+
await page.setFiles(loc, files);
|
|
6774
|
+
return { uploaded: files, ...elementField(element) };
|
|
6130
6775
|
});
|
|
6131
6776
|
}
|
|
6132
6777
|
function stamp() {
|
|
@@ -6240,7 +6885,7 @@ async function takeScreenshot(driver, args = {}) {
|
|
|
6240
6885
|
return withPage2(driver, args.target, async (page) => {
|
|
6241
6886
|
const clip = args.uid !== undefined || args.selector ? locatorOf(args) : undefined;
|
|
6242
6887
|
const ext = format === "jpeg" ? "jpg" : "png";
|
|
6243
|
-
const path = args.savePath ??
|
|
6888
|
+
const path = args.savePath ?? join5(ARTIFACT_DIR, `screenshot-${page.info.id.slice(0, 8)}-${stamp()}.${ext}`);
|
|
6244
6889
|
const stitch = async (banded) => {
|
|
6245
6890
|
if (format !== "png")
|
|
6246
6891
|
throw tiledCaptureRefusal("format", banded);
|
|
@@ -6352,7 +6997,7 @@ init_leases();
|
|
|
6352
6997
|
class LeaseToolError extends Error {
|
|
6353
6998
|
}
|
|
6354
6999
|
function backendOf2(driver) {
|
|
6355
|
-
return driver.scheme === "bidi" ? "firefox" :
|
|
7000
|
+
return driver.scheme === "bidi" ? "firefox" : chromeLeaseBackend();
|
|
6356
7001
|
}
|
|
6357
7002
|
async function claimPage(driver, args = {}) {
|
|
6358
7003
|
const hasTarget = typeof args.target === "string" && args.target.length > 0;
|
|
@@ -6437,7 +7082,7 @@ async function releasePage(driver, args = {}) {
|
|
|
6437
7082
|
}
|
|
6438
7083
|
async function listLeasesTool(driver, _args = {}) {
|
|
6439
7084
|
const backend = backendOf2(driver);
|
|
6440
|
-
const reaped = requireLease() ? await reapStaleAgentTabs(driver, backend) : [];
|
|
7085
|
+
const reaped = requireLease() && reapAllowed(driver) ? await reapStaleAgentTabs(driver, backend) : [];
|
|
6441
7086
|
const reapedIds = new Set(reaped.map((r) => r.targetId));
|
|
6442
7087
|
const livePages = await driver.listPages();
|
|
6443
7088
|
const liveIds = livePages.map((p) => p.id);
|
|
@@ -6465,7 +7110,7 @@ var LEASE_TOOLS = {
|
|
|
6465
7110
|
|
|
6466
7111
|
// src/tools/console.ts
|
|
6467
7112
|
init_client();
|
|
6468
|
-
import { readFile as
|
|
7113
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
6469
7114
|
|
|
6470
7115
|
// src/tools/recorder.ts
|
|
6471
7116
|
init_client();
|
|
@@ -6668,7 +7313,7 @@ function lineToEntry(line, index) {
|
|
|
6668
7313
|
async function readConsoleEntries(file) {
|
|
6669
7314
|
let raw;
|
|
6670
7315
|
try {
|
|
6671
|
-
raw = await
|
|
7316
|
+
raw = await readFile5(file, "utf8");
|
|
6672
7317
|
} catch {
|
|
6673
7318
|
return [];
|
|
6674
7319
|
}
|
|
@@ -6726,7 +7371,7 @@ async function getConsoleMessage(args = {}) {
|
|
|
6726
7371
|
|
|
6727
7372
|
// src/tools/network.ts
|
|
6728
7373
|
init_client();
|
|
6729
|
-
import { readFile as
|
|
7374
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
6730
7375
|
var DEFAULT_CAPTURE_MS2 = 2500;
|
|
6731
7376
|
function asHeaders(v) {
|
|
6732
7377
|
if (!v || typeof v !== "object")
|
|
@@ -6793,7 +7438,7 @@ function correlate(lines) {
|
|
|
6793
7438
|
async function readNetworkRequests(file) {
|
|
6794
7439
|
let raw;
|
|
6795
7440
|
try {
|
|
6796
|
-
raw = await
|
|
7441
|
+
raw = await readFile6(file, "utf8");
|
|
6797
7442
|
} catch {
|
|
6798
7443
|
return [];
|
|
6799
7444
|
}
|
|
@@ -6878,8 +7523,8 @@ async function getNetworkRequest(args = {}) {
|
|
|
6878
7523
|
|
|
6879
7524
|
// src/tools/performance.ts
|
|
6880
7525
|
init_client();
|
|
6881
|
-
import { mkdir as mkdir7, readFile as
|
|
6882
|
-
import { join as
|
|
7526
|
+
import { mkdir as mkdir7, readFile as readFile7, writeFile as writeFile6, stat, unlink as unlink4 } from "node:fs/promises";
|
|
7527
|
+
import { join as join6 } from "node:path";
|
|
6883
7528
|
var ARTIFACT_DIR2 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
6884
7529
|
var STATE_DIR2 = process.env.CDP_STATE_DIR ?? "/tmp/cdp-toolkit";
|
|
6885
7530
|
var DEFAULT_CATEGORIES = [
|
|
@@ -6897,7 +7542,7 @@ function shortId(id) {
|
|
|
6897
7542
|
return id.slice(0, 8);
|
|
6898
7543
|
}
|
|
6899
7544
|
function stateFilePath() {
|
|
6900
|
-
return
|
|
7545
|
+
return join6(STATE_DIR2, "trace-state.json");
|
|
6901
7546
|
}
|
|
6902
7547
|
function bufferTraceData(conn, sink) {
|
|
6903
7548
|
return conn.on("Tracing.dataCollected", (params) => {
|
|
@@ -6920,7 +7565,7 @@ async function endTrace(conn, sink, timeoutMs = 30000) {
|
|
|
6920
7565
|
}
|
|
6921
7566
|
async function writeTrace(events, targetId) {
|
|
6922
7567
|
await mkdir7(ARTIFACT_DIR2, { recursive: true });
|
|
6923
|
-
const path =
|
|
7568
|
+
const path = join6(ARTIFACT_DIR2, `trace-${shortId(targetId)}-${stamp2()}.json`);
|
|
6924
7569
|
const body = JSON.stringify({ traceEvents: events, metadata: { source: "cdp-toolkit" } });
|
|
6925
7570
|
await writeFile6(path, body, "utf8");
|
|
6926
7571
|
const { size } = await stat(path);
|
|
@@ -6963,7 +7608,7 @@ async function performanceStopTrace(args = {}) {
|
|
|
6963
7608
|
if (!entry) {
|
|
6964
7609
|
let hint = "";
|
|
6965
7610
|
try {
|
|
6966
|
-
const raw = await
|
|
7611
|
+
const raw = await readFile7(stateFilePath(), "utf8");
|
|
6967
7612
|
const state = JSON.parse(raw);
|
|
6968
7613
|
hint = state.pid === process.pid ? ` (state file lists target ${shortId(state.targetId)} but its live connection is gone)` : ` (trace was started by a DIFFERENT process pid=${state.pid}; live recordings cannot cross process boundaries)`;
|
|
6969
7614
|
} catch {}
|
|
@@ -7093,7 +7738,7 @@ async function performanceAnalyzeInsight(args = {}) {
|
|
|
7093
7738
|
}
|
|
7094
7739
|
let raw;
|
|
7095
7740
|
try {
|
|
7096
|
-
raw = await
|
|
7741
|
+
raw = await readFile7(args.tracePath, "utf8");
|
|
7097
7742
|
} catch (err) {
|
|
7098
7743
|
throw new CdpError(`cannot read trace file '${args.tracePath}': ${err.message}`);
|
|
7099
7744
|
}
|
|
@@ -7113,7 +7758,7 @@ async function performanceAnalyzeInsight(args = {}) {
|
|
|
7113
7758
|
init_client();
|
|
7114
7759
|
import { spawn } from "node:child_process";
|
|
7115
7760
|
import { mkdir as mkdir8, rm as rm2, stat as stat2, writeFile as writeFile7 } from "node:fs/promises";
|
|
7116
|
-
import { join as
|
|
7761
|
+
import { join as join7 } from "node:path";
|
|
7117
7762
|
var ARTIFACT_DIR3 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
7118
7763
|
var FFMPEG_BIN = process.env.CDP_FFMPEG ?? "ffmpeg";
|
|
7119
7764
|
function frameDurationsMs(ledger, stopWallclockMs) {
|
|
@@ -7229,6 +7874,22 @@ function selectEncoder(encodersOutput) {
|
|
|
7229
7874
|
}
|
|
7230
7875
|
throw new CdpError(`ffmpeg reports none of the supported video encoders (${ENCODER_LADDER.map((c) => c.encoder).join(", ")}). ` + "Install a full ffmpeg build: 'brew install ffmpeg' (macOS) or 'apt install ffmpeg' (Debian/Ubuntu).");
|
|
7231
7876
|
}
|
|
7877
|
+
function supportsFpsMode(versionOutput) {
|
|
7878
|
+
const m = /ffmpeg version n?(\d+)\.(\d+)/.exec(versionOutput);
|
|
7879
|
+
if (!m)
|
|
7880
|
+
return /ffmpeg version N-/.test(versionOutput) ? true : undefined;
|
|
7881
|
+
const major = Number(m[1]);
|
|
7882
|
+
const minor = Number(m[2]);
|
|
7883
|
+
return major > 5 || major === 5 && minor >= 1;
|
|
7884
|
+
}
|
|
7885
|
+
function chooseFpsMode(versionOutput, helpOutput) {
|
|
7886
|
+
const byVersion = versionOutput === undefined ? undefined : supportsFpsMode(versionOutput);
|
|
7887
|
+
if (byVersion !== undefined)
|
|
7888
|
+
return byVersion;
|
|
7889
|
+
if (helpOutput !== undefined && /-vsync\b|-fps_mode\b/.test(helpOutput))
|
|
7890
|
+
return /-fps_mode\b/.test(helpOutput);
|
|
7891
|
+
return true;
|
|
7892
|
+
}
|
|
7232
7893
|
function buildFfmpegArgs(manifestPath, outPath, choice) {
|
|
7233
7894
|
return [
|
|
7234
7895
|
"-hide_banner",
|
|
@@ -7241,8 +7902,7 @@ function buildFfmpegArgs(manifestPath, outPath, choice) {
|
|
|
7241
7902
|
"0",
|
|
7242
7903
|
"-i",
|
|
7243
7904
|
manifestPath,
|
|
7244
|
-
"-vsync",
|
|
7245
|
-
"vfr",
|
|
7905
|
+
...choice.fpsMode ? ["-fps_mode", "vfr"] : ["-vsync", "vfr"],
|
|
7246
7906
|
"-vf",
|
|
7247
7907
|
"scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
|
7248
7908
|
"-c:v",
|
|
@@ -7284,8 +7944,19 @@ async function probeEncoder() {
|
|
|
7284
7944
|
}
|
|
7285
7945
|
if (res.code !== 0)
|
|
7286
7946
|
throw new CdpError(`${FFMPEG_MISSING} ('-encoders' exited ${res.code}: ${res.stderr.trim().slice(0, 300)})`);
|
|
7287
|
-
|
|
7947
|
+
const choice = selectEncoder(`${res.stdout}
|
|
7288
7948
|
${res.stderr}`);
|
|
7949
|
+
const output = async (args) => {
|
|
7950
|
+
const r = await run(FFMPEG_BIN, args).catch(() => {
|
|
7951
|
+
return;
|
|
7952
|
+
});
|
|
7953
|
+
return r && r.code === 0 ? `${r.stdout}
|
|
7954
|
+
${r.stderr}` : undefined;
|
|
7955
|
+
};
|
|
7956
|
+
const version = await output(["-version"]);
|
|
7957
|
+
const byVersion = version === undefined ? undefined : supportsFpsMode(version);
|
|
7958
|
+
const help = byVersion === undefined ? await output(["-hide_banner", "-h", "full"]) : undefined;
|
|
7959
|
+
return { ...choice, fpsMode: chooseFpsMode(version, help) };
|
|
7289
7960
|
})();
|
|
7290
7961
|
encoderProbe.catch(() => {
|
|
7291
7962
|
encoderProbe = undefined;
|
|
@@ -7334,7 +8005,7 @@ async function startScreenRecording(args = {}) {
|
|
|
7334
8005
|
conn.close();
|
|
7335
8006
|
throw err;
|
|
7336
8007
|
}
|
|
7337
|
-
const spoolDir =
|
|
8008
|
+
const spoolDir = join7(ARTIFACT_DIR3, `screencast-${shortId2(target.id)}-${stamp3()}`);
|
|
7338
8009
|
try {
|
|
7339
8010
|
await mkdir8(spoolDir, { recursive: true });
|
|
7340
8011
|
} catch (err) {
|
|
@@ -7377,7 +8048,7 @@ async function startScreenRecording(args = {}) {
|
|
|
7377
8048
|
seq += 1;
|
|
7378
8049
|
const file = `frame-${String(seq).padStart(6, "0")}.${ext}`;
|
|
7379
8050
|
rec.ledger.push({ file, timestamp, width: size.width, height: size.height });
|
|
7380
|
-
rec.writes = rec.writes.then(() => writeFile7(
|
|
8051
|
+
rec.writes = rec.writes.then(() => writeFile7(join7(spoolDir, file), buf)).catch(() => {
|
|
7381
8052
|
rec.dropped += 1;
|
|
7382
8053
|
rec.unwritten.add(file);
|
|
7383
8054
|
});
|
|
@@ -7441,9 +8112,9 @@ async function stopScreenRecording(args = {}) {
|
|
|
7441
8112
|
throw new CdpError(`screen recording captured 0 frames for target ${shortId2(rec.target.id)}. Chrome emits a screencast frame only on repaint: a fully backgrounded or occluded tab may never paint. Retry with bringToFront:true, or drive the page while recording.`);
|
|
7442
8113
|
}
|
|
7443
8114
|
await mkdir8(ARTIFACT_DIR3, { recursive: true });
|
|
7444
|
-
const outPath = args.savePath ??
|
|
8115
|
+
const outPath = args.savePath ?? join7(ARTIFACT_DIR3, `screen-recording-${shortId2(rec.target.id)}-${stamp3()}.mp4`);
|
|
7445
8116
|
const frames = coalesceToConcatGrid(ledger, stoppedAt);
|
|
7446
|
-
const manifestPath =
|
|
8117
|
+
const manifestPath = join7(rec.spoolDir, "frames.ffconcat");
|
|
7447
8118
|
await writeFile7(manifestPath, buildConcatManifest(frames), "utf8");
|
|
7448
8119
|
const durationMs = frames.reduce((total, f) => total + f.durationMs, 0);
|
|
7449
8120
|
const { width, height } = evenDimensions(ledger[0].width, ledger[0].height);
|
|
@@ -7477,7 +8148,7 @@ ffmpeg said: ${res.stderr.trim().slice(0, 800)}`);
|
|
|
7477
8148
|
// src/tools/heap.ts
|
|
7478
8149
|
init_client();
|
|
7479
8150
|
import { mkdir as mkdir9, writeFile as writeFile8 } from "node:fs/promises";
|
|
7480
|
-
import { join as
|
|
8151
|
+
import { join as join8 } from "node:path";
|
|
7481
8152
|
var ARTIFACT_DIR4 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
7482
8153
|
function stamp4(targetId) {
|
|
7483
8154
|
const short = targetId.slice(0, 8);
|
|
@@ -7503,7 +8174,7 @@ async function takeHeapsnapshot(args = {}) {
|
|
|
7503
8174
|
throw new Error("HeapProfiler.takeHeapSnapshot produced no chunks");
|
|
7504
8175
|
}
|
|
7505
8176
|
await mkdir9(ARTIFACT_DIR4, { recursive: true });
|
|
7506
|
-
const path = args.savePath ? args.savePath.startsWith("/") ? args.savePath :
|
|
8177
|
+
const path = args.savePath ? args.savePath.startsWith("/") ? args.savePath : join8(ARTIFACT_DIR4, args.savePath) : join8(ARTIFACT_DIR4, `take_heapsnapshot-${stamp4(target.id)}.heapsnapshot`);
|
|
7507
8178
|
await writeFile8(path, snapshot, "utf8");
|
|
7508
8179
|
const bytes = Buffer.byteLength(snapshot, "utf8");
|
|
7509
8180
|
return {
|
|
@@ -7517,11 +8188,12 @@ async function takeHeapsnapshot(args = {}) {
|
|
|
7517
8188
|
|
|
7518
8189
|
// src/tools/lighthouse.ts
|
|
7519
8190
|
init_client();
|
|
8191
|
+
init_endpoints();
|
|
7520
8192
|
import { spawn as spawn2 } from "node:child_process";
|
|
7521
|
-
import { mkdir as mkdir10, readFile as
|
|
8193
|
+
import { mkdir as mkdir10, readFile as readFile8, stat as stat3 } from "node:fs/promises";
|
|
7522
8194
|
var ARTIFACT_DIR5 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
7523
8195
|
function cdpPort() {
|
|
7524
|
-
const base =
|
|
8196
|
+
const base = currentEndpoint().base;
|
|
7525
8197
|
const m = base.match(/:(\d+)/);
|
|
7526
8198
|
return m?.[1] ? Number(m[1]) : 9222;
|
|
7527
8199
|
}
|
|
@@ -7608,7 +8280,7 @@ async function lighthouseAudit(args) {
|
|
|
7608
8280
|
}
|
|
7609
8281
|
let raw;
|
|
7610
8282
|
try {
|
|
7611
|
-
raw = await
|
|
8283
|
+
raw = await readFile8(outPath, "utf8");
|
|
7612
8284
|
} catch {
|
|
7613
8285
|
raw = undefined;
|
|
7614
8286
|
}
|
|
@@ -7658,6 +8330,7 @@ init_network_mock();
|
|
|
7658
8330
|
// src/tools/dispatch-mouse.ts
|
|
7659
8331
|
init_activity();
|
|
7660
8332
|
init_client();
|
|
8333
|
+
init_leases();
|
|
7661
8334
|
var CLICK_MODIFIER_BITS2 = { Alt: 1, Control: 2, Meta: 4, Shift: 8 };
|
|
7662
8335
|
var BUTTONS = new Set(["left", "right", "middle"]);
|
|
7663
8336
|
var CDP_EVENT_TYPE = {
|
|
@@ -7694,7 +8367,7 @@ async function dispatchMouse(args) {
|
|
|
7694
8367
|
const params = { type: CDP_EVENT_TYPE[args.action], x: args.x, y: args.y, button, modifiers };
|
|
7695
8368
|
if (args.action !== "move")
|
|
7696
8369
|
params.clickCount = args.clickCount ?? 1;
|
|
7697
|
-
await sendInput(conn,
|
|
8370
|
+
await sendInput(conn, chromeLeaseBackend(), target.id, "Input.dispatchMouseEvent", params);
|
|
7698
8371
|
return { dispatched: args.action, x: args.x, y: args.y };
|
|
7699
8372
|
});
|
|
7700
8373
|
}
|
|
@@ -7702,6 +8375,7 @@ async function dispatchMouse(args) {
|
|
|
7702
8375
|
// src/tools/focus-emulation.ts
|
|
7703
8376
|
init_activity();
|
|
7704
8377
|
init_client();
|
|
8378
|
+
init_leases();
|
|
7705
8379
|
function validateFocusEmulationArgs(args) {
|
|
7706
8380
|
if (typeof args.enabled !== "boolean") {
|
|
7707
8381
|
throw new Error("focus_emulation requires { enabled } of true or false");
|
|
@@ -7768,9 +8442,10 @@ async function clickFocusGated(args) {
|
|
|
7768
8442
|
const btn = result?.value;
|
|
7769
8443
|
if (btn && !btn.disabled) {
|
|
7770
8444
|
const base = { x: btn.x, y: btn.y, button: "left", buttons: 1, clickCount: 1 };
|
|
7771
|
-
|
|
7772
|
-
await sendInput(conn,
|
|
7773
|
-
await sendInput(conn,
|
|
8445
|
+
const backend = chromeLeaseBackend();
|
|
8446
|
+
await sendInput(conn, backend, target.id, "Input.dispatchMouseEvent", { type: "mouseMoved", x: btn.x, y: btn.y });
|
|
8447
|
+
await sendInput(conn, backend, target.id, "Input.dispatchMouseEvent", { ...base, type: "mousePressed" });
|
|
8448
|
+
await sendInput(conn, backend, target.id, "Input.dispatchMouseEvent", { ...base, type: "mouseReleased" });
|
|
7774
8449
|
return {
|
|
7775
8450
|
clicked: true,
|
|
7776
8451
|
x: btn.x,
|
|
@@ -7795,16 +8470,20 @@ async function clickFocusGated(args) {
|
|
|
7795
8470
|
// src/tools/downloads.ts
|
|
7796
8471
|
init_client();
|
|
7797
8472
|
import { readdir as readdir3, rename as rename2, stat as stat4 } from "node:fs/promises";
|
|
7798
|
-
import { basename, extname, join as
|
|
8473
|
+
import { basename, extname, join as join10 } from "node:path";
|
|
7799
8474
|
|
|
7800
8475
|
// src/tools/browser-session.ts
|
|
7801
8476
|
init_client();
|
|
8477
|
+
init_endpoints();
|
|
7802
8478
|
import { mkdir as mkdir11 } from "node:fs/promises";
|
|
7803
|
-
import { join as
|
|
8479
|
+
import { join as join9 } from "node:path";
|
|
7804
8480
|
var ARTIFACT_DIR6 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
7805
|
-
var DOWNLOADS_DIR =
|
|
8481
|
+
var DOWNLOADS_DIR = join9(ARTIFACT_DIR6, "downloads");
|
|
7806
8482
|
var DOWNLOAD_BUFFER_LIMIT = 50;
|
|
7807
|
-
var
|
|
8483
|
+
var sessions2 = new Map;
|
|
8484
|
+
function sessionKey() {
|
|
8485
|
+
return currentEndpoint().name;
|
|
8486
|
+
}
|
|
7808
8487
|
function isDisconnect(e) {
|
|
7809
8488
|
const m = e instanceof Error ? e.message : String(e);
|
|
7810
8489
|
return /connection (not open|closed)|closed by caller|websocket|ECONNREFUSED|socket/i.test(m);
|
|
@@ -7849,13 +8528,15 @@ function subscribe(s) {
|
|
|
7849
8528
|
});
|
|
7850
8529
|
}
|
|
7851
8530
|
async function getBrowserSession() {
|
|
8531
|
+
const key = sessionKey();
|
|
8532
|
+
const session = sessions2.get(key);
|
|
7852
8533
|
if (session && !session.dead)
|
|
7853
8534
|
return session;
|
|
7854
8535
|
const previousPath = session?.armedPath;
|
|
7855
8536
|
const conn = await openBrowser();
|
|
7856
8537
|
const s = { conn, downloads: [], waiters: [], dead: false };
|
|
7857
8538
|
subscribe(s);
|
|
7858
|
-
|
|
8539
|
+
sessions2.set(key, s);
|
|
7859
8540
|
if (previousPath)
|
|
7860
8541
|
await armDownloadsAt(previousPath);
|
|
7861
8542
|
return s;
|
|
@@ -7886,7 +8567,7 @@ async function armDownloads() {
|
|
|
7886
8567
|
return { downloadPath: DOWNLOADS_DIR };
|
|
7887
8568
|
}
|
|
7888
8569
|
function pendingDownloads() {
|
|
7889
|
-
return (
|
|
8570
|
+
return (sessions2.get(sessionKey())?.downloads ?? []).filter((d) => d.state === "completed" && !d.consumed);
|
|
7890
8571
|
}
|
|
7891
8572
|
async function nextCompletedDownload(timeoutMs) {
|
|
7892
8573
|
const s = await getBrowserSession();
|
|
@@ -7910,14 +8591,14 @@ async function nextCompletedDownload(timeoutMs) {
|
|
|
7910
8591
|
});
|
|
7911
8592
|
}
|
|
7912
8593
|
async function disposeBrowserSession() {
|
|
7913
|
-
const
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
}
|
|
8594
|
+
const all = [...sessions2.values()];
|
|
8595
|
+
sessions2.clear();
|
|
8596
|
+
for (const s of all) {
|
|
8597
|
+
s.dead = true;
|
|
8598
|
+
try {
|
|
8599
|
+
s.conn.close();
|
|
8600
|
+
} catch {}
|
|
8601
|
+
}
|
|
7921
8602
|
}
|
|
7922
8603
|
|
|
7923
8604
|
// src/tools/downloads.ts
|
|
@@ -7964,7 +8645,7 @@ async function waitForDownload(args = {}) {
|
|
|
7964
8645
|
const taken = new Set(await readdir3(DOWNLOADS_DIR).catch(() => []));
|
|
7965
8646
|
taken.delete(basename(rec.filePath));
|
|
7966
8647
|
const finalName = nextFreeName(suggestedFilename, taken);
|
|
7967
|
-
const path =
|
|
8648
|
+
const path = join10(DOWNLOADS_DIR, finalName);
|
|
7968
8649
|
await rename2(rec.filePath, path);
|
|
7969
8650
|
const bytes = (await stat4(path)).size;
|
|
7970
8651
|
return { path, suggestedFilename, bytes, ...rec.url ? { url: rec.url } : {}, target };
|
|
@@ -8023,7 +8704,7 @@ async function grantPermissions(args = {}) {
|
|
|
8023
8704
|
// src/tools/extract.ts
|
|
8024
8705
|
init_client();
|
|
8025
8706
|
import { mkdir as mkdir12, writeFile as writeFile9 } from "node:fs/promises";
|
|
8026
|
-
import { dirname as dirname3, join as
|
|
8707
|
+
import { dirname as dirname3, join as join11 } from "node:path";
|
|
8027
8708
|
var ARTIFACT_DIR7 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
8028
8709
|
var DEFAULT_BASE_URL = "http://127.0.0.1:8090/v1";
|
|
8029
8710
|
var DEFAULT_MODEL = "schematron";
|
|
@@ -8424,7 +9105,7 @@ async function extractPage(driver, args) {
|
|
|
8424
9105
|
};
|
|
8425
9106
|
if (args.savePath === undefined || args.savePath === "")
|
|
8426
9107
|
return result;
|
|
8427
|
-
const path = args.savePath.startsWith("/") ? args.savePath :
|
|
9108
|
+
const path = args.savePath.startsWith("/") ? args.savePath : join11(ARTIFACT_DIR7, args.savePath);
|
|
8428
9109
|
await mkdir12(dirname3(path), { recursive: true });
|
|
8429
9110
|
const json = JSON.stringify(result, null, 2);
|
|
8430
9111
|
await writeFile9(path, json, "utf8");
|
|
@@ -8516,6 +9197,14 @@ var MANIFEST = [
|
|
|
8516
9197
|
probe: {
|
|
8517
9198
|
type: "boolean",
|
|
8518
9199
|
description: "Probe renderer responsiveness."
|
|
9200
|
+
},
|
|
9201
|
+
endpoint: {
|
|
9202
|
+
type: "string",
|
|
9203
|
+
description: "Named CDP endpoint to list (CDP_ENDPOINTS); default endpoint when omitted."
|
|
9204
|
+
},
|
|
9205
|
+
allEndpoints: {
|
|
9206
|
+
type: "boolean",
|
|
9207
|
+
description: "List every configured endpoint; rows carry endpoint, a down one is reported, not thrown."
|
|
8519
9208
|
}
|
|
8520
9209
|
},
|
|
8521
9210
|
required: [],
|
|
@@ -8540,6 +9229,10 @@ var MANIFEST = [
|
|
|
8540
9229
|
type: "boolean",
|
|
8541
9230
|
description: "Claim the new tab."
|
|
8542
9231
|
},
|
|
9232
|
+
endpoint: {
|
|
9233
|
+
type: "string",
|
|
9234
|
+
description: "Named CDP endpoint to open the tab on (CDP_ENDPOINTS); default endpoint when omitted."
|
|
9235
|
+
},
|
|
8543
9236
|
label: {
|
|
8544
9237
|
type: "string",
|
|
8545
9238
|
description: "Agent lease label."
|
|
@@ -8565,7 +9258,7 @@ var MANIFEST = [
|
|
|
8565
9258
|
},
|
|
8566
9259
|
target: {
|
|
8567
9260
|
type: "string",
|
|
8568
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9261
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8569
9262
|
}
|
|
8570
9263
|
},
|
|
8571
9264
|
required: [
|
|
@@ -8586,7 +9279,7 @@ var MANIFEST = [
|
|
|
8586
9279
|
},
|
|
8587
9280
|
target: {
|
|
8588
9281
|
type: "string",
|
|
8589
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9282
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8590
9283
|
}
|
|
8591
9284
|
},
|
|
8592
9285
|
required: [
|
|
@@ -8607,7 +9300,7 @@ var MANIFEST = [
|
|
|
8607
9300
|
},
|
|
8608
9301
|
target: {
|
|
8609
9302
|
type: "string",
|
|
8610
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9303
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8611
9304
|
},
|
|
8612
9305
|
url: {
|
|
8613
9306
|
type: "string",
|
|
@@ -8657,7 +9350,7 @@ var MANIFEST = [
|
|
|
8657
9350
|
},
|
|
8658
9351
|
target: {
|
|
8659
9352
|
type: "string",
|
|
8660
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9353
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8661
9354
|
},
|
|
8662
9355
|
text: {
|
|
8663
9356
|
type: "string",
|
|
@@ -8690,7 +9383,7 @@ var MANIFEST = [
|
|
|
8690
9383
|
},
|
|
8691
9384
|
target: {
|
|
8692
9385
|
type: "string",
|
|
8693
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9386
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8694
9387
|
},
|
|
8695
9388
|
wake: {
|
|
8696
9389
|
type: "boolean",
|
|
@@ -8732,7 +9425,7 @@ var MANIFEST = [
|
|
|
8732
9425
|
},
|
|
8733
9426
|
target: {
|
|
8734
9427
|
type: "string",
|
|
8735
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9428
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8736
9429
|
},
|
|
8737
9430
|
domain: {
|
|
8738
9431
|
type: "string",
|
|
@@ -8763,7 +9456,7 @@ var MANIFEST = [
|
|
|
8763
9456
|
},
|
|
8764
9457
|
target: {
|
|
8765
9458
|
type: "string",
|
|
8766
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9459
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8767
9460
|
},
|
|
8768
9461
|
name: {
|
|
8769
9462
|
type: "string",
|
|
@@ -8827,7 +9520,7 @@ var MANIFEST = [
|
|
|
8827
9520
|
},
|
|
8828
9521
|
target: {
|
|
8829
9522
|
type: "string",
|
|
8830
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9523
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8831
9524
|
},
|
|
8832
9525
|
name: {
|
|
8833
9526
|
type: "string",
|
|
@@ -8864,7 +9557,7 @@ var MANIFEST = [
|
|
|
8864
9557
|
},
|
|
8865
9558
|
target: {
|
|
8866
9559
|
type: "string",
|
|
8867
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9560
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8868
9561
|
},
|
|
8869
9562
|
interactiveOnly: {
|
|
8870
9563
|
type: "boolean",
|
|
@@ -8887,7 +9580,7 @@ var MANIFEST = [
|
|
|
8887
9580
|
},
|
|
8888
9581
|
target: {
|
|
8889
9582
|
type: "string",
|
|
8890
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9583
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8891
9584
|
},
|
|
8892
9585
|
uid: {
|
|
8893
9586
|
type: "number",
|
|
@@ -8940,7 +9633,7 @@ var MANIFEST = [
|
|
|
8940
9633
|
},
|
|
8941
9634
|
target: {
|
|
8942
9635
|
type: "string",
|
|
8943
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9636
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8944
9637
|
},
|
|
8945
9638
|
uid: {
|
|
8946
9639
|
type: "number",
|
|
@@ -8967,7 +9660,7 @@ var MANIFEST = [
|
|
|
8967
9660
|
},
|
|
8968
9661
|
target: {
|
|
8969
9662
|
type: "string",
|
|
8970
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9663
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
8971
9664
|
},
|
|
8972
9665
|
from: {
|
|
8973
9666
|
type: "object",
|
|
@@ -9053,7 +9746,7 @@ var MANIFEST = [
|
|
|
9053
9746
|
},
|
|
9054
9747
|
target: {
|
|
9055
9748
|
type: "string",
|
|
9056
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9749
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9057
9750
|
},
|
|
9058
9751
|
uid: {
|
|
9059
9752
|
type: "number",
|
|
@@ -9096,7 +9789,7 @@ var MANIFEST = [
|
|
|
9096
9789
|
},
|
|
9097
9790
|
target: {
|
|
9098
9791
|
type: "string",
|
|
9099
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9792
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9100
9793
|
},
|
|
9101
9794
|
action: {
|
|
9102
9795
|
type: "string",
|
|
@@ -9162,7 +9855,7 @@ var MANIFEST = [
|
|
|
9162
9855
|
},
|
|
9163
9856
|
target: {
|
|
9164
9857
|
type: "string",
|
|
9165
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9858
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9166
9859
|
},
|
|
9167
9860
|
enabled: {
|
|
9168
9861
|
type: "boolean",
|
|
@@ -9187,7 +9880,7 @@ var MANIFEST = [
|
|
|
9187
9880
|
},
|
|
9188
9881
|
target: {
|
|
9189
9882
|
type: "string",
|
|
9190
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9883
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9191
9884
|
},
|
|
9192
9885
|
selector: {
|
|
9193
9886
|
type: "string",
|
|
@@ -9226,7 +9919,7 @@ var MANIFEST = [
|
|
|
9226
9919
|
},
|
|
9227
9920
|
target: {
|
|
9228
9921
|
type: "string",
|
|
9229
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9922
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9230
9923
|
},
|
|
9231
9924
|
arm: {
|
|
9232
9925
|
type: "boolean",
|
|
@@ -9253,7 +9946,7 @@ var MANIFEST = [
|
|
|
9253
9946
|
},
|
|
9254
9947
|
target: {
|
|
9255
9948
|
type: "string",
|
|
9256
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9949
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9257
9950
|
},
|
|
9258
9951
|
permissions: {
|
|
9259
9952
|
type: "array",
|
|
@@ -9287,7 +9980,7 @@ var MANIFEST = [
|
|
|
9287
9980
|
},
|
|
9288
9981
|
target: {
|
|
9289
9982
|
type: "string",
|
|
9290
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
9983
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9291
9984
|
},
|
|
9292
9985
|
uid: {
|
|
9293
9986
|
type: "number",
|
|
@@ -9320,7 +10013,7 @@ var MANIFEST = [
|
|
|
9320
10013
|
},
|
|
9321
10014
|
target: {
|
|
9322
10015
|
type: "string",
|
|
9323
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10016
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9324
10017
|
},
|
|
9325
10018
|
fields: {
|
|
9326
10019
|
type: "array",
|
|
@@ -9366,7 +10059,7 @@ var MANIFEST = [
|
|
|
9366
10059
|
},
|
|
9367
10060
|
target: {
|
|
9368
10061
|
type: "string",
|
|
9369
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10062
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9370
10063
|
},
|
|
9371
10064
|
uid: {
|
|
9372
10065
|
type: "number",
|
|
@@ -9399,7 +10092,7 @@ var MANIFEST = [
|
|
|
9399
10092
|
},
|
|
9400
10093
|
target: {
|
|
9401
10094
|
type: "string",
|
|
9402
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10095
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9403
10096
|
},
|
|
9404
10097
|
key: {
|
|
9405
10098
|
type: "string",
|
|
@@ -9431,7 +10124,7 @@ var MANIFEST = [
|
|
|
9431
10124
|
},
|
|
9432
10125
|
target: {
|
|
9433
10126
|
type: "string",
|
|
9434
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10127
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9435
10128
|
},
|
|
9436
10129
|
uid: {
|
|
9437
10130
|
type: "number",
|
|
@@ -9467,7 +10160,7 @@ var MANIFEST = [
|
|
|
9467
10160
|
},
|
|
9468
10161
|
target: {
|
|
9469
10162
|
type: "string",
|
|
9470
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10163
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9471
10164
|
},
|
|
9472
10165
|
format: {
|
|
9473
10166
|
type: "string",
|
|
@@ -9534,7 +10227,7 @@ var MANIFEST = [
|
|
|
9534
10227
|
},
|
|
9535
10228
|
target: {
|
|
9536
10229
|
type: "string",
|
|
9537
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10230
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9538
10231
|
},
|
|
9539
10232
|
width: {
|
|
9540
10233
|
type: "number",
|
|
@@ -9634,7 +10327,7 @@ var MANIFEST = [
|
|
|
9634
10327
|
},
|
|
9635
10328
|
target: {
|
|
9636
10329
|
type: "string",
|
|
9637
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10330
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9638
10331
|
},
|
|
9639
10332
|
width: {
|
|
9640
10333
|
type: "number",
|
|
@@ -9672,7 +10365,7 @@ var MANIFEST = [
|
|
|
9672
10365
|
},
|
|
9673
10366
|
target: {
|
|
9674
10367
|
type: "string",
|
|
9675
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10368
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9676
10369
|
},
|
|
9677
10370
|
accept: {
|
|
9678
10371
|
type: "boolean",
|
|
@@ -9709,7 +10402,7 @@ var MANIFEST = [
|
|
|
9709
10402
|
},
|
|
9710
10403
|
target: {
|
|
9711
10404
|
type: "string",
|
|
9712
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10405
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9713
10406
|
},
|
|
9714
10407
|
reload: {
|
|
9715
10408
|
type: "boolean",
|
|
@@ -9740,7 +10433,7 @@ var MANIFEST = [
|
|
|
9740
10433
|
},
|
|
9741
10434
|
target: {
|
|
9742
10435
|
type: "string",
|
|
9743
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10436
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9744
10437
|
},
|
|
9745
10438
|
index: {
|
|
9746
10439
|
type: "number",
|
|
@@ -9763,7 +10456,7 @@ var MANIFEST = [
|
|
|
9763
10456
|
},
|
|
9764
10457
|
target: {
|
|
9765
10458
|
type: "string",
|
|
9766
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10459
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9767
10460
|
},
|
|
9768
10461
|
reload: {
|
|
9769
10462
|
type: "boolean",
|
|
@@ -9798,7 +10491,7 @@ var MANIFEST = [
|
|
|
9798
10491
|
},
|
|
9799
10492
|
target: {
|
|
9800
10493
|
type: "string",
|
|
9801
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10494
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9802
10495
|
},
|
|
9803
10496
|
requestId: {
|
|
9804
10497
|
type: "string",
|
|
@@ -9837,7 +10530,7 @@ var MANIFEST = [
|
|
|
9837
10530
|
},
|
|
9838
10531
|
target: {
|
|
9839
10532
|
type: "string",
|
|
9840
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10533
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9841
10534
|
},
|
|
9842
10535
|
categories: {
|
|
9843
10536
|
type: "array",
|
|
@@ -9863,7 +10556,7 @@ var MANIFEST = [
|
|
|
9863
10556
|
},
|
|
9864
10557
|
target: {
|
|
9865
10558
|
type: "string",
|
|
9866
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10559
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9867
10560
|
}
|
|
9868
10561
|
},
|
|
9869
10562
|
required: [],
|
|
@@ -9901,7 +10594,7 @@ var MANIFEST = [
|
|
|
9901
10594
|
},
|
|
9902
10595
|
target: {
|
|
9903
10596
|
type: "string",
|
|
9904
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10597
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9905
10598
|
},
|
|
9906
10599
|
durationMs: {
|
|
9907
10600
|
type: "number",
|
|
@@ -9939,7 +10632,7 @@ var MANIFEST = [
|
|
|
9939
10632
|
},
|
|
9940
10633
|
target: {
|
|
9941
10634
|
type: "string",
|
|
9942
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10635
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9943
10636
|
},
|
|
9944
10637
|
format: {
|
|
9945
10638
|
type: "string",
|
|
@@ -9986,7 +10679,7 @@ var MANIFEST = [
|
|
|
9986
10679
|
},
|
|
9987
10680
|
target: {
|
|
9988
10681
|
type: "string",
|
|
9989
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10682
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
9990
10683
|
},
|
|
9991
10684
|
savePath: {
|
|
9992
10685
|
type: "string",
|
|
@@ -10009,7 +10702,7 @@ var MANIFEST = [
|
|
|
10009
10702
|
},
|
|
10010
10703
|
target: {
|
|
10011
10704
|
type: "string",
|
|
10012
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10705
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
10013
10706
|
},
|
|
10014
10707
|
savePath: {
|
|
10015
10708
|
type: "string",
|
|
@@ -10076,7 +10769,7 @@ var MANIFEST = [
|
|
|
10076
10769
|
},
|
|
10077
10770
|
target: {
|
|
10078
10771
|
type: "string",
|
|
10079
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10772
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
10080
10773
|
},
|
|
10081
10774
|
urlPattern: {
|
|
10082
10775
|
type: "string",
|
|
@@ -10165,7 +10858,7 @@ var MANIFEST = [
|
|
|
10165
10858
|
},
|
|
10166
10859
|
target: {
|
|
10167
10860
|
type: "string",
|
|
10168
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10861
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
10169
10862
|
},
|
|
10170
10863
|
all: {
|
|
10171
10864
|
type: "boolean",
|
|
@@ -10184,7 +10877,7 @@ var MANIFEST = [
|
|
|
10184
10877
|
properties: {
|
|
10185
10878
|
target: {
|
|
10186
10879
|
type: "string",
|
|
10187
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10880
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
10188
10881
|
},
|
|
10189
10882
|
targetId: {
|
|
10190
10883
|
type: "string",
|
|
@@ -10219,7 +10912,7 @@ var MANIFEST = [
|
|
|
10219
10912
|
},
|
|
10220
10913
|
target: {
|
|
10221
10914
|
type: "string",
|
|
10222
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10915
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
10223
10916
|
},
|
|
10224
10917
|
close: {
|
|
10225
10918
|
type: "boolean",
|
|
@@ -10252,7 +10945,7 @@ var MANIFEST = [
|
|
|
10252
10945
|
},
|
|
10253
10946
|
target: {
|
|
10254
10947
|
type: "string",
|
|
10255
|
-
description: "Page selector (index:/url:/title:/label:/targetId, default active); grammar in server instructions."
|
|
10948
|
+
description: "Page selector (index:/url:/title:/label:/targetId, endpoint:<name>/ prefix, default active); grammar in server instructions."
|
|
10256
10949
|
},
|
|
10257
10950
|
schema: {
|
|
10258
10951
|
type: "object",
|
|
@@ -10321,10 +11014,10 @@ init_driver2();
|
|
|
10321
11014
|
|
|
10322
11015
|
// src/bidi/launch.ts
|
|
10323
11016
|
import { spawn as spawn4 } from "node:child_process";
|
|
10324
|
-
import { existsSync as existsSync2, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
11017
|
+
import { existsSync as existsSync2, mkdtempSync, readFileSync as readFileSync2, rmSync, writeFileSync } from "node:fs";
|
|
10325
11018
|
import { createConnection, createServer as createServer2 } from "node:net";
|
|
10326
11019
|
import { tmpdir } from "node:os";
|
|
10327
|
-
import { join as
|
|
11020
|
+
import { join as join13 } from "node:path";
|
|
10328
11021
|
function resolveBinary() {
|
|
10329
11022
|
const candidates = [
|
|
10330
11023
|
process.env.FIREFOX_BIN,
|
|
@@ -10404,8 +11097,8 @@ var LAUNCH_USER_JS_PREFS = {
|
|
|
10404
11097
|
"dom.file.createInChild": true
|
|
10405
11098
|
};
|
|
10406
11099
|
function writeLaunchUserJs(profilePath) {
|
|
10407
|
-
const target =
|
|
10408
|
-
const existing = existsSync2(target) ?
|
|
11100
|
+
const target = join13(profilePath, "user.js");
|
|
11101
|
+
const existing = existsSync2(target) ? readFileSync2(target, "utf8") : "";
|
|
10409
11102
|
const present = new Set;
|
|
10410
11103
|
for (const line of existing.split(`
|
|
10411
11104
|
`)) {
|
|
@@ -10426,7 +11119,7 @@ async function launchFirefox(opts = {}) {
|
|
|
10426
11119
|
const binary = resolveBinary();
|
|
10427
11120
|
const port = await pickPort(opts.port);
|
|
10428
11121
|
const isThrowaway = opts.profilePath === undefined;
|
|
10429
|
-
const profilePath = opts.profilePath ?? mkdtempSync(
|
|
11122
|
+
const profilePath = opts.profilePath ?? mkdtempSync(join13(tmpdir(), "cdp-toolkit-ff-profile-"));
|
|
10430
11123
|
if (isThrowaway)
|
|
10431
11124
|
writeLaunchUserJs(profilePath);
|
|
10432
11125
|
const args = ["--profile", profilePath, "--remote-debugging-port", String(port), "--no-remote"];
|
|
@@ -10786,6 +11479,7 @@ var FIREFOX_TOOLS = {
|
|
|
10786
11479
|
|
|
10787
11480
|
// src/mcp.ts
|
|
10788
11481
|
init_leases();
|
|
11482
|
+
init_endpoints();
|
|
10789
11483
|
|
|
10790
11484
|
// src/toolGroups.ts
|
|
10791
11485
|
var TOOL_GROUPS = [
|
|
@@ -10904,7 +11598,9 @@ var TOOL_DOCS = {
|
|
|
10904
11598
|
params: {
|
|
10905
11599
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10906
11600
|
all: "Include non-page targets (service/shared workers, background pages, out-of-process (OOPIF) iframes); default false lists page-type tabs only. A returned non-page targetId is accepted as a bare id by any tool's `target` param.",
|
|
10907
|
-
probe: "Ping each page-type renderer before returning, one bounded 500ms check per target and never more, so a wedged tab can't stall the listing. Adds 'responsive' (false on timeout/exception/unreachable, never an error for the whole call) and, where the same round trip finds human input, humanActiveMs. Default false. On a backend that cannot answer the ping, responsive is absent too (not false)."
|
|
11601
|
+
probe: "Ping each page-type renderer before returning, one bounded 500ms check per target and never more, so a wedged tab can't stall the listing. Adds 'responsive' (false on timeout/exception/unreachable, never an error for the whole call) and, where the same round trip finds human input, humanActiveMs. Default false. On a backend that cannot answer the ping, responsive is absent too (not false).",
|
|
11602
|
+
endpoint: "Name of a CDP endpoint configured with CDP_ENDPOINTS / CDP_ENDPOINTS_FILE (Chrome only); lists that endpoint instead of the default. Every row from a non-default endpoint carries 'endpoint', so build selectors as 'endpoint:<name>/<targetId>'. An app endpoint (e.g. the Teams desktop app, a WebView2/Electron shell) often lists an empty host page first: pick the real window with 'title:'.",
|
|
11603
|
+
allEndpoints: "List every configured endpoint at once (Chrome only). Each page row carries its 'endpoint'; an 'endpoints' array reports every endpoint as {endpoint, base, readOnly, count}, or {endpoint, base, readOnly, down:true, error} for one that cannot be reached, which never fails the whole call. Default false."
|
|
10908
11604
|
}
|
|
10909
11605
|
},
|
|
10910
11606
|
new_page: {
|
|
@@ -10912,6 +11608,7 @@ var TOOL_DOCS = {
|
|
|
10912
11608
|
params: {
|
|
10913
11609
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10914
11610
|
url: "URL to open in the new tab; defaults to about:blank.",
|
|
11611
|
+
endpoint: "Name of a CDP endpoint configured with CDP_ENDPOINTS / CDP_ENDPOINTS_FILE to open the tab on (Chrome only); default endpoint when omitted. Address the new tab later as 'endpoint:<name>/<targetId>'.",
|
|
10915
11612
|
claim: "Claim the new tab atomically and return a lease token alongside {targetId,url}. Under CDP_REQUIRE_LEASE the tab is claimed and a lease returned even without claim:true; claim:true makes it an EXPLICIT lease that demands its token on every later call, even from this process. Default false.",
|
|
10916
11613
|
label: "Agent label recorded on the lease when the tab is claimed; surfaced in conflict errors and list_leases. Defaults to pid-<pid>.",
|
|
10917
11614
|
ttlMs: "How long a claimed lease survives without use before it is reclaimable. Defaults to CDP_LEASE_TTL_MS, else 900000 (15min); every checked call refreshes it. Ignored when not claiming."
|
|
@@ -10921,21 +11618,21 @@ var TOOL_DOCS = {
|
|
|
10921
11618
|
description: "Close a page target via Target.closeTarget. Requires an explicit, resolvable target; errors rather than guessing when the selector matches nothing.",
|
|
10922
11619
|
params: {
|
|
10923
11620
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10924
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions."
|
|
11621
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions."
|
|
10925
11622
|
}
|
|
10926
11623
|
},
|
|
10927
11624
|
select_page: {
|
|
10928
11625
|
description: "Activate/focus a page target via Target.activateTarget and persist its bare targetId to the selected-state file (CDP_STATE_DIR/selected). Requires an explicit, resolvable target.",
|
|
10929
11626
|
params: {
|
|
10930
11627
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10931
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions."
|
|
11628
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions."
|
|
10932
11629
|
}
|
|
10933
11630
|
},
|
|
10934
11631
|
navigate_page: {
|
|
10935
11632
|
description: "Navigate a target page to a URL (Page.navigate), reload it (reload:true), OR go back/forward in its session history (history:'back'|'forward'), then wait for the load milestone with a bounded timeout so a wedged renderer can't hang. Exactly one of url / reload / history per call. Returns {url,frameId,waitedFor} (plus reloaded:true on a reload, traversed:'back'|'forward' on a history move); waitUntil supports 'load'|'domcontentloaded' only (no 'networkidle'), and there is no auto-snapshot of the new page. Pass reload:true with ignoreCache:true for a hard reload that refetches every subresource (e.g. to pick up a freshly-deployed, non-content-hashed bundle the HTTP cache would serve stale).",
|
|
10936
11633
|
params: {
|
|
10937
11634
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10938
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11635
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
10939
11636
|
url: "Destination URL to navigate to. Required unless reload:true.",
|
|
10940
11637
|
reload: "Reload the current page (Page.reload) instead of navigating to url. Default false.",
|
|
10941
11638
|
history: "Traverse this tab's session history instead of loading a url: 'back' and 'forward' are the browser's Back and Forward buttons. Mutually exclusive with 'url' and 'reload' — passing two of the three is refused by name, not resolved by precedence. Works on BOTH backends and waits for the same load milestone as an ordinary navigation. Going back from the first entry, or forward from the last, is an ERROR naming the direction — never a silent no-op. The result carries traversed:'back'|'forward' alongside the resulting url.",
|
|
@@ -10948,7 +11645,7 @@ var TOOL_DOCS = {
|
|
|
10948
11645
|
description: "Poll the target until the substring appears in document.body.innerText (Runtime.evaluate on a fixed interval), or throw on timeout. Text-substring only -- no aria/role/selector or event variants; throws rather than returning {found:false}.",
|
|
10949
11646
|
params: {
|
|
10950
11647
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10951
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11648
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
10952
11649
|
text: "Substring to wait for in document.body.innerText. Required.",
|
|
10953
11650
|
timeoutMs: "Total time budget in ms. Default 15000.",
|
|
10954
11651
|
pollMs: "Poll interval in ms. Default 250."
|
|
@@ -10958,7 +11655,7 @@ var TOOL_DOCS = {
|
|
|
10958
11655
|
description: "Run arbitrary JavaScript in the target's main-world context over raw CDP and return the evaluated value (returnByValue). With no 'args', 'expression' is a raw expression; with 'args' it must be a function literal (arrow or classic) invoked on globalThis with args passed positionally. A thrown exception surfaces as an error; non-serializable returns (DOM nodes, functions) come back as their CDP description string. savePath writes the value to a JSON file instead -- the response then carries only {path,bytes,type,target} and the value never appears in it, the way to read a credential (a JWT/session token from localStorage) without putting the secret in the transcript. This is the one tool that EVALUATES inside an MV3 extension's background SERVICE WORKER rather than OBSERVING it (Chrome, Capability 'worker.targets'): a worker: target reads chrome.storage.local, chrome.runtime and the worker's own globals directly, with an idle-evicted worker started first (see 'wake').",
|
|
10959
11656
|
params: {
|
|
10960
11657
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10961
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Grammar: see server instructions.",
|
|
11658
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
10962
11659
|
wake: "Worker targets only, when starting a capture. Default true: an idle-evicted MV3 service worker exists in no target listing, so it is started first (ServiceWorker.startWorker) and re-confirmed; false fails fast. Rejected on a page target, a bare target id, or a read-only call. See server instructions.",
|
|
10963
11660
|
expression: "JavaScript to run. Evaluated as an expression when 'args' is omitted; must be a function literal (arrow or classic) whose parameters receive 'args' when provided. REQUIRED -- the code always goes in this key, never in 'function', 'code', 'js', 'script', 'fn' or 'body'; a call using one of those is rejected with an error naming the wrong key.",
|
|
10964
11661
|
awaitPromise: "Await the result if it is a Promise. Default true.",
|
|
@@ -10970,7 +11667,7 @@ var TOOL_DOCS = {
|
|
|
10970
11667
|
description: "Read the target page's cookie store INCLUDING httpOnly cookies, which document.cookie (and therefore evaluate_script) cannot see. Page-scoped, not browser-wide: returns cookies of the resolved tab, so point at a page on the site you want. Each cookie carries name, value, domain, path, expires (Unix seconds, -1 for a session cookie), size, httpOnly, secure, sameSite ('strict'|'lax'|'none'|'default'), session. Filter with 'domain' and/or 'name'. Pass 'savePath' to write the array to a JSON file instead: the response is then {path,bytes,count,target} with no cookie value in any form, the way to capture a session cookie without putting the credential in the transcript.",
|
|
10971
11668
|
params: {
|
|
10972
11669
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10973
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11670
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
10974
11671
|
domain: "Keep only cookies for this domain. A leading dot is ignored on both sides and subdomains match too, so 'example.test' matches '.example.test' and 'app.example.test'. No wildcards.",
|
|
10975
11672
|
name: "Keep only the cookie with exactly this name. Exact match, not a substring.",
|
|
10976
11673
|
savePath: "Write the cookie array here as JSON and KEEP THE VALUES OUT OF THE RESPONSE: the result is {path,bytes,count,target} only, with no preview or truncation of any value. An absolute path (starting with /) is used as-is; a relative path resolves under the artifact dir (/tmp/cdp-toolkit); missing parents are created. Omit to get the cookies back inline."
|
|
@@ -10980,7 +11677,7 @@ var TOOL_DOCS = {
|
|
|
10980
11677
|
description: "Write one cookie into the target page's cookie store, INCLUDING httpOnly or secure cookies that document.cookie (and therefore evaluate_script) cannot create. Either 'url' or 'domain' is REQUIRED: the call is refused when neither is given, rather than guessing the page origin. The response is {set:true,target} and never echoes the value back. A 'set:true' is earned, not assumed: Chrome raises an error when it declines the cookie (a domain the url does not belong to, a secure cookie on an insecure origin, an oversized value). On Firefox 'domain' is derived from 'url' when only the url was given (BiDi has no url parameter), and a url with no host such as about:blank or a data URL is an error, not a silent no-op. Read the result back with list_cookies when you need proof.",
|
|
10981
11678
|
params: {
|
|
10982
11679
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10983
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11680
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
10984
11681
|
name: "Cookie name. Required and non-empty.",
|
|
10985
11682
|
value: "Cookie value. Required. It is not echoed back in the response.",
|
|
10986
11683
|
url: "URL the cookie is set for, e.g. 'https://example.com/'. Chrome derives domain, path and secure from it; Firefox derives only the domain from its host. Give this or 'domain'.",
|
|
@@ -10996,7 +11693,7 @@ var TOOL_DOCS = {
|
|
|
10996
11693
|
description: "Delete the named cookie from the target page's cookie store, httpOnly cookies included. Both 'name' and one of 'url' or 'domain' are REQUIRED: without a site constraint it would delete by name across the whole partition, so it is refused with an error instead. Narrow further with 'path'. The response is {deleted:true,target} and carries NO count, because neither protocol reports how many cookies it removed and a number here would be invented; call list_cookies before and after for a real count. 'deleted:true' means the backend accepted and performed the deletion, not that a matching cookie existed, since deleting an absent cookie succeeds on both backends.",
|
|
10997
11694
|
params: {
|
|
10998
11695
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
10999
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11696
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11000
11697
|
name: "Exact cookie name to delete. Required and non-empty. No wildcards: this removes a named cookie, not a swathe of them.",
|
|
11001
11698
|
url: "Delete cookies matching this URL, e.g. 'https://example.com/'. Give this or 'domain'. On Firefox only the host is used, because BiDi's filter has no url field.",
|
|
11002
11699
|
domain: "Delete cookies with this exact domain. Give this or 'url'.",
|
|
@@ -11007,15 +11704,15 @@ var TOOL_DOCS = {
|
|
|
11007
11704
|
description: `Captures the page's accessibility tree as an indented text tree, each line prefixed [uid] (a CDP backendDOMNodeId). Every interaction tool (click/hover/fill/etc.) resolves that uid via DOM.resolveNode — run this first to discover uids to act on. Cross-origin iframe subtrees are not walked (they live in a separate renderer process); the iframe node itself is emitted with a frame="<targetId>" marker (also in interactiveOnly mode), so the frame is discoverable and driveable via that id or frame:<url-substring>.`,
|
|
11008
11705
|
params: {
|
|
11009
11706
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11010
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11707
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11011
11708
|
interactiveOnly: "When true, emit only interactive/meaningful nodes as a flat list; default false returns the full hierarchical tree."
|
|
11012
11709
|
}
|
|
11013
11710
|
},
|
|
11014
11711
|
click: {
|
|
11015
|
-
description:
|
|
11712
|
+
description: 'Click an element via a synthetic mouse press/release at its scrolled-into-view center. Give exactly one of uid or selector. modifiers (Alt/Control/Meta/Shift) throws on the Firefox backend — use --browser chrome for a modifier-click. clickCount:3 triple-clicks (selects a line/paragraph in most editors). Returns {clicked,element,x,y}; element names what was hit, snapshot-style (button "Save"), read before the click and omitted if it cannot be read.',
|
|
11016
11713
|
params: {
|
|
11017
11714
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11018
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11715
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11019
11716
|
uid: "CDP backendDOMNodeId of the element to click, from take_snapshot. Exactly one of uid or selector.",
|
|
11020
11717
|
selector: "CSS selector for the element to click (document.querySelector). Exactly one of uid or selector.",
|
|
11021
11718
|
button: "Mouse button: 'left' (default), 'right', or 'middle'.",
|
|
@@ -11027,7 +11724,7 @@ var TOOL_DOCS = {
|
|
|
11027
11724
|
description: "Hovers the mouse over an element by dispatching a mouseMoved event at its scrolled-into-view center, firing framework hover handlers. Give exactly one of uid or selector.",
|
|
11028
11725
|
params: {
|
|
11029
11726
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11030
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11727
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11031
11728
|
uid: "CDP backendDOMNodeId of the element to hover, from take_snapshot. Exactly one of uid or selector.",
|
|
11032
11729
|
selector: "CSS selector for the element to hover (document.querySelector). Exactly one of uid or selector."
|
|
11033
11730
|
}
|
|
@@ -11036,7 +11733,7 @@ var TOOL_DOCS = {
|
|
|
11036
11733
|
description: "Drags from a source element to a destination or by an offset. mode:'mouse' (default) dispatches synthetic mouse press/move/release; at the default steps:2 an HTML5 drop zone (dragover preventDefault) gets ZERO dragover events and refuses the drop. mode:'html5' replays real dragstart/dragEnter/dragOver/drop with the page's own dataTransfer instead — deterministic regardless of pointer path, but CHROME-ONLY (rejected with a clear error on the Firefox backend). 'from' takes uid or selector; destination is exactly one of 'to' (uid/selector/x+y) or 'by' ({dx,dy} offset — sliders, map panning, resize handles).",
|
|
11037
11734
|
params: {
|
|
11038
11735
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11039
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11736
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11040
11737
|
from: "Source element to drag from. Exactly one of uid or selector.",
|
|
11041
11738
|
to: "Where the drag ends: exactly one of uid, selector, or x+y. Mutually exclusive with 'by'; exactly one of to/by required.",
|
|
11042
11739
|
by: "Offset from the source element's center: at least one of dx/dy (other defaults to 0). Mutually exclusive with 'to'; exactly one of to/by required. For sliders (by:{dx:40}), map panning, resize handles.",
|
|
@@ -11048,7 +11745,7 @@ var TOOL_DOCS = {
|
|
|
11048
11745
|
description: "Dispatches a wheel/scroll event at an anchor point — element (uid/selector) or x+y, scrolled into view first if an element; omit all three for viewport center. At least one of deltaX/deltaY required: positive deltaY scrolls DOWN, positive deltaX scrolls RIGHT (wheel-event convention — easy to invert). Returns the resolved anchor {x,y} plus the delta actually dispatched.",
|
|
11049
11746
|
params: {
|
|
11050
11747
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11051
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11748
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11052
11749
|
uid: "CDP backendDOMNodeId of the element to scroll into view and anchor at, from take_snapshot. At most one of uid, selector, or x+y.",
|
|
11053
11750
|
selector: "CSS selector for the element to anchor at (document.querySelector). At most one of uid, selector, or x+y.",
|
|
11054
11751
|
x: "Absolute viewport x-coordinate to anchor at; must be given with y. At most one of uid, selector, or x+y.",
|
|
@@ -11061,7 +11758,7 @@ var TOOL_DOCS = {
|
|
|
11061
11758
|
description: "Dispatches one raw mouse event (move/down/up) at absolute viewport coordinates — the toolkit's lowest-level input primitive. Compose move/down/move/up calls yourself for anything click/drag's fixed sequences can't reach: canvas drag-painting, marquee/rubber-band selection, custom hit-testing widgets. Chrome-only: absent from tools/list under the Firefox backend, never present-and-throwing.",
|
|
11062
11759
|
params: {
|
|
11063
11760
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11064
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11761
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11065
11762
|
action: "Which raw event to dispatch: 'move' (mouseMoved), 'down' (mousePressed), or 'up' (mouseReleased).",
|
|
11066
11763
|
x: "Viewport x-coordinate. Required every call — CDP has no 'current pointer position' to default from.",
|
|
11067
11764
|
y: "Viewport y-coordinate. Required every call.",
|
|
@@ -11074,7 +11771,7 @@ var TOOL_DOCS = {
|
|
|
11074
11771
|
description: "Toggles CDP Emulation.setFocusEmulationEnabled on a tab: the page then BELIEVES it is focused (document.hasFocus()→true, visibilitychange stays 'visible', focus events fire) while the real OS window and active tab stay put — no focus theft. This is the primitive that unlocks focus-GATED UI (a button the site disables unless its tab is focused, e.g. Anthropic's Claude Code OAuth Authorize button on claude.ai/oauth/*) on a background tab. Chrome-only: WebDriver BiDi's emulation module has no focus primitive, so this tool is absent from tools/list under --browser firefox. Ports the core mechanism of the danbuhler/claude-code-auto-authorize extension. Remember to call with enabled:false to restore, or use click_focus_gated which restores automatically.",
|
|
11075
11772
|
params: {
|
|
11076
11773
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11077
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'.",
|
|
11774
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only).",
|
|
11078
11775
|
enabled: "true = page reports focused/visible; false = restore the real focus state."
|
|
11079
11776
|
}
|
|
11080
11777
|
},
|
|
@@ -11082,7 +11779,7 @@ var TOOL_DOCS = {
|
|
|
11082
11779
|
description: "One-call compose of focus emulation + trusted click for a focus-gated button: enables Emulation.setFocusEmulationEnabled, polls until the button (located by CSS selector OR exact visible-text match, e.g. 'Authorize') exists AND is enabled, dispatches a trusted move/press/release click via Input.dispatchMouseEvent (isTrusted:true — a content script's synthesized events can never satisfy a focus gate), then restores focus emulation off unless keepFocus. Built for the Claude Code OAuth Authorize button but works on any focus-gated control on a background tab. Throws with a diagnostic ('never located' vs 'found but stayed disabled') on timeout. Chrome-only; absent under --browser firefox.",
|
|
11083
11780
|
params: {
|
|
11084
11781
|
lease: "Lease token from claim_page. Omit for a tab this process holds. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease).",
|
|
11085
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'.",
|
|
11782
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only).",
|
|
11086
11783
|
selector: "CSS selector of the button. Give exactly one of selector or text.",
|
|
11087
11784
|
text: "Exact visible-text match of the button (trims whitespace, matches button/[role=button]/submit inputs), e.g. 'Authorize'. Give exactly one of selector or text.",
|
|
11088
11785
|
timeoutMs: "Max ms to poll for the button to appear and become enabled. Default 30000.",
|
|
@@ -11110,10 +11807,10 @@ var TOOL_DOCS = {
|
|
|
11110
11807
|
}
|
|
11111
11808
|
},
|
|
11112
11809
|
fill: {
|
|
11113
|
-
description:
|
|
11810
|
+
description: `Fills an element by focusing it, clearing existing content, then inserting value via Input.insertText (atomic paste-like commit, not per-character keystrokes — won't fire per-keypress handlers). Give exactly one of uid or selector. Returns {filled,element,value}; element names the field (textbox "Email").`,
|
|
11114
11811
|
params: {
|
|
11115
11812
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11116
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11813
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11117
11814
|
uid: "CDP backendDOMNodeId of the field to fill, from take_snapshot. Exactly one of uid or selector.",
|
|
11118
11815
|
selector: "CSS selector for the field to fill (document.querySelector). Exactly one of uid or selector.",
|
|
11119
11816
|
value: "Text value to set; the field is cleared first, overwriting existing content."
|
|
@@ -11123,7 +11820,7 @@ var TOOL_DOCS = {
|
|
|
11123
11820
|
description: "Fills multiple form fields in one call; each is focused, cleared, then set via Input.insertText (overwrites existing content, same as fill). Each entry in the non-empty 'fields' array takes exactly one of uid or selector plus a string value.",
|
|
11124
11821
|
params: {
|
|
11125
11822
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11126
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11823
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11127
11824
|
fields: "Non-empty array of fields to fill, each with exactly one of uid or selector plus a string value."
|
|
11128
11825
|
}
|
|
11129
11826
|
},
|
|
@@ -11131,7 +11828,7 @@ var TOOL_DOCS = {
|
|
|
11131
11828
|
description: "Focuses an element and appends text via Input.insertText without clearing first — closest primitive to typing, but still atomic (not per-character keystrokes). Give exactly one of uid or selector.",
|
|
11132
11829
|
params: {
|
|
11133
11830
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11134
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11831
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11135
11832
|
uid: "CDP backendDOMNodeId of the element to type into, from take_snapshot. Exactly one of uid or selector.",
|
|
11136
11833
|
selector: "CSS selector for the element to type into (document.querySelector). Exactly one of uid or selector.",
|
|
11137
11834
|
text: "Text to insert; appended to existing content rather than overwriting it."
|
|
@@ -11141,7 +11838,7 @@ var TOOL_DOCS = {
|
|
|
11141
11838
|
description: "Dispatches a keyDown/keyUp pair for one key with optional modifiers. 'key' is a named key (Enter, Tab, Escape, ArrowDown, Backspace, etc.) or a single printable character — the named-key table is curated, with no F-keys, numpad, or IME support.",
|
|
11142
11839
|
params: {
|
|
11143
11840
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11144
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11841
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11145
11842
|
key: "Key to press: a named key (Enter, Tab, Escape, ArrowDown, Backspace, ...) or a single printable character.",
|
|
11146
11843
|
modifiers: "Modifier names held during the press: 'Control'/'Ctrl', 'Shift', 'Alt', 'Meta'/'Cmd'."
|
|
11147
11844
|
}
|
|
@@ -11150,7 +11847,7 @@ var TOOL_DOCS = {
|
|
|
11150
11847
|
description: "Attaches one or more files to an <input type=file> element via DOM.setFileInputFiles. Give exactly one of uid or selector for the input; 'files' is an array of absolute path(s) — wrap a single path in an array too.",
|
|
11151
11848
|
params: {
|
|
11152
11849
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11153
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11850
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11154
11851
|
uid: "CDP backendDOMNodeId of the file input element, from take_snapshot. Exactly one of uid or selector.",
|
|
11155
11852
|
selector: "CSS selector for the file input element (document.querySelector). Exactly one of uid or selector.",
|
|
11156
11853
|
files: 'Absolute path(s) to attach to the <input type=file>, as an array — wrap a single path too, e.g. ["/tmp/a.pdf"]. Array-only because some model APIs (Google Gemini function calling) reject union-typed parameters.'
|
|
@@ -11160,7 +11857,7 @@ var TOOL_DOCS = {
|
|
|
11160
11857
|
description: "Captures the viewport (default), the full scrollable page (fullPage), or one element (uid or selector, mutually exclusive) via CDP Page.captureScreenshot. Past 16384 device px per side Chrome can hang rather than refuse, so size is checked first via Page.getLayoutMetrics; an oversized capture is auto-tiled into vertical bands stitched losslessly into one PNG (see tile) instead of wedging the tab. Writes PNG/JPEG to /tmp/cdp-toolkit (override savePath, dir auto-created); returns {path,bytes,format,target,scale} plus width/height measured from the encoded bytes (omitted if undecodable). renderSize/renderRestored(+renderRestoreError) accompany a renderWidth/renderHeight capture, tiled/bands a banded one. returnBase64 adds raw bytes to the result but is refused on a banded capture. quality applies to jpeg only.",
|
|
11161
11858
|
params: {
|
|
11162
11859
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11163
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11860
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11164
11861
|
format: "Image format, default png. quality applies only to jpeg.",
|
|
11165
11862
|
quality: "JPEG quality 0-100, default 80; ignored for png.",
|
|
11166
11863
|
fullPage: "Capture the full scrollable height (via Page.getLayoutMetrics), not just the viewport.",
|
|
@@ -11178,7 +11875,7 @@ var TOOL_DOCS = {
|
|
|
11178
11875
|
description: "Applies any subset of Chrome emulation overrides in one call: device metrics (width+height together, +deviceScaleFactor/mobile), userAgent, cpuThrottlingRate(>=1), media type+features, networkConditions. Device-metrics overrides PERSIST on the target until cleared or the renderer navigates/reloads; every other override is session-scoped and resets when this call's connection closes. clearOverrides:true resets everything (ignoring other fields) and, as of 1.9.2, genuinely clears a device-metrics override set by a DIFFERENT process — Chrome's clearDeviceMetricsOverride is normally a no-op unless the clearing connection also set the override, so the driver re-asserts the tab's current size first, then clears, throwing rather than reporting cleared:true if it can't verify.",
|
|
11179
11876
|
params: {
|
|
11180
11877
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11181
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11878
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11182
11879
|
width: "Device-metrics viewport width in CSS px. Must be paired with height.",
|
|
11183
11880
|
height: "Device-metrics viewport height in CSS px. Must be paired with width.",
|
|
11184
11881
|
deviceScaleFactor: "Device pixel ratio for the device-metrics override; 0 = platform default.",
|
|
@@ -11195,7 +11892,7 @@ var TOOL_DOCS = {
|
|
|
11195
11892
|
description: "Sets the page's device-metrics width/height (the narrow case of emulate), optionally deviceScaleFactor/mobile, then verifies by reading back window.innerWidth/innerHeight after applying. Requires positive width and height. The override PERSISTS on the target until cleared (emulate{clearOverrides:true}) or the renderer navigates/reloads.",
|
|
11196
11893
|
params: {
|
|
11197
11894
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11198
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11895
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11199
11896
|
width: "Viewport width in CSS px (required, must be positive).",
|
|
11200
11897
|
height: "Viewport height in CSS px (required, must be positive).",
|
|
11201
11898
|
deviceScaleFactor: "Device pixel ratio; 0 = platform default.",
|
|
@@ -11206,7 +11903,7 @@ var TOOL_DOCS = {
|
|
|
11206
11903
|
description: "Wait for the next JavaScript dialog (alert/confirm/prompt/beforeunload) on a page and respond via Page.handleJavaScriptDialog, accepting or dismissing it. Default mode resolves with the first handled dialog or throws on timeout; set autoMs to handle every dialog opening during a fixed window and resolve with the list. Trigger the dialog out-of-band (e.g. click a button) — a blocking dialog freezes the renderer, so it cannot be triggered inline.",
|
|
11207
11904
|
params: {
|
|
11208
11905
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11209
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11906
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11210
11907
|
accept: "Whether to accept (OK) or dismiss (Cancel) the dialog.",
|
|
11211
11908
|
promptText: "Text to enter for a prompt() dialog when accepting.",
|
|
11212
11909
|
timeoutMs: "How long to wait for the next dialog, in milliseconds (default 15000).",
|
|
@@ -11217,7 +11914,7 @@ var TOOL_DOCS = {
|
|
|
11217
11914
|
description: "Read console output (logs, warnings, exceptions) captured for the target. Reads the existing shared buffer by default (empty if no capture ran); reload:true reloads and records a fresh capture (console+network together, so a network reload never wipes console history). WORKER capture (Chrome, Capability 'worker.targets'): a worker: target records an MV3 background service worker -- its console.log arrives as Runtime.consoleAPICalled, its outbound requests from CDP's Network domain on the worker's own session -- so the two tricks callers try first fail for plain JS reasons, not worker ones: a value bound at module top level is not visible from evaluate_script's global scope, and assigning self.fetch cannot rebind a fetch the module already captured. A worker has no reload: reload:true means 'listen for durationMs while it runs', so trigger its work (tool call, message, alarm) during the window; a worker woken by the call already ran its top-level code, so a startup message can be missed. SIDE EFFECT: the CDP session KEEPS THE WORKER ALIVE for the capture (an idle MV3 worker is evicted in seconds); Chrome resumes evicting after.",
|
|
11218
11915
|
params: {
|
|
11219
11916
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11220
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Grammar: see server instructions.",
|
|
11917
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11221
11918
|
reload: "Record fresh by reloading the page and capturing a window. Default false (read existing buffer). With a worker: target nothing reloads -- records for durationMs while the worker runs and keeps it alive until the capture stops.",
|
|
11222
11919
|
durationMs: "Capture window for reload mode, in ms. Default 2500.",
|
|
11223
11920
|
wake: "Worker targets only, when starting a capture. Default true: an idle-evicted MV3 service worker exists in no target listing, so it is started first (ServiceWorker.startWorker) and re-confirmed; false fails fast. Rejected on a page target, a bare target id, or a read-only call. See server instructions."
|
|
@@ -11227,7 +11924,7 @@ var TOOL_DOCS = {
|
|
|
11227
11924
|
description: "Return one console entry by zero-based index from the target's existing console buffer. Throws if the index is out of range; run list_console_messages (optionally reload:true) first to populate the buffer.",
|
|
11228
11925
|
params: {
|
|
11229
11926
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11230
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11927
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11231
11928
|
index: "Zero-based index into the parsed console entries. Default 0."
|
|
11232
11929
|
}
|
|
11233
11930
|
},
|
|
@@ -11235,7 +11932,7 @@ var TOOL_DOCS = {
|
|
|
11235
11932
|
description: "Return correlated network rows (one per requestId; status/headers/state) for the target. Reads the existing buffer by default; reload:true records a fresh both-domains capture window. filterUrl keeps only URLs containing a substring. WORKER capture (Chrome, Capability 'worker.targets'): a worker: target records an MV3 background service worker's outbound requests from CDP's Network domain on the worker's own session -- what the code ACTUALLY SENT -- so the two tricks callers try first fail for plain JS reasons, not worker ones: a value bound at module top level is not visible from evaluate_script's global scope, and assigning self.fetch cannot rebind a fetch the module already captured. A worker has no reload: reload:true means 'listen for durationMs while it runs', so trigger its work (tool call, message, alarm) during the window; a worker woken by the call already ran its top-level code, so a startup request can be missed. SIDE EFFECT: the CDP session KEEPS THE WORKER ALIVE for the capture (an idle MV3 worker is evicted in seconds); Chrome resumes evicting after.",
|
|
11236
11933
|
params: {
|
|
11237
11934
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11238
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Grammar: see server instructions.",
|
|
11935
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11239
11936
|
reload: "Record fresh by reloading the page and capturing a window. Default false (read existing buffer). With a worker: target nothing reloads -- records for durationMs while the worker runs and keeps it alive until the capture stops.",
|
|
11240
11937
|
durationMs: "Capture window for reload mode, in ms. Default 2500.",
|
|
11241
11938
|
filterUrl: "Return only requests whose URL contains this substring.",
|
|
@@ -11246,7 +11943,7 @@ var TOOL_DOCS = {
|
|
|
11246
11943
|
description: "Return one network request (matched by exact requestId, else url substring) with status/headers. Requires requestId or url (throws otherwise). includeBody:true drives a fresh capture (page reload, or worker listen window) matched by url ONLY -- a fresh capture re-mints requestIds, so a carried-over requestId returns metadata plus bodyUnavailableReason. WORKER capture (Chrome, Capability 'worker.targets'): a worker: target records an MV3 background service worker's outbound requests from CDP's Network domain on the worker's own session -- what the code ACTUALLY SENT -- so the two tricks callers try first fail for plain JS reasons, not worker ones: a value bound at module top level is not visible from evaluate_script's global scope, and assigning self.fetch cannot rebind a fetch the module already captured. A worker has no reload: reload means 'listen for durationMs while it runs', so trigger its work (tool call, message, alarm) during the window; a worker woken by the call already ran its top-level code, so a startup request can be missed. SIDE EFFECT: the CDP session KEEPS THE WORKER ALIVE for the capture (an idle MV3 worker is evicted in seconds); Chrome resumes evicting after.",
|
|
11247
11944
|
params: {
|
|
11248
11945
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11249
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Grammar: see server instructions.",
|
|
11946
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', '<targetId>'; plus 'worker:<substring>' to reach a service/shared worker (e.g. an MV3 extension background worker). The worker: arm is CHROME-ONLY (Capability 'worker.targets'). Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11250
11947
|
requestId: "Match by exact requestId (metadata only; cannot fetch a body, since a reload re-mints requestIds).",
|
|
11251
11948
|
url: "Match by URL substring (first match). Required for body fetch (includeBody), since url is stable across reload.",
|
|
11252
11949
|
includeBody: "Also fetch the response body; drives a fresh capture and requires the url selector.",
|
|
@@ -11258,7 +11955,7 @@ var TOOL_DOCS = {
|
|
|
11258
11955
|
description: "Starts a CDP trace recording on the target and holds the recording connection in-process; you MUST call performance_stop_trace from the SAME PROCESS to end it, or use performance_trace instead for a robust cross-call trace. Throws if a trace is already in progress for this target.",
|
|
11259
11956
|
params: {
|
|
11260
11957
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11261
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11958
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11262
11959
|
categories: "Trace categories to record. Defaults to timeline + user-timing + loading + disabled-by-default timeline tracks carrying LCP/LayoutShift/RunTask."
|
|
11263
11960
|
}
|
|
11264
11961
|
},
|
|
@@ -11266,7 +11963,7 @@ var TOOL_DOCS = {
|
|
|
11266
11963
|
description: "Stops the in-process trace started by performance_start_trace and writes it as JSON under /tmp/cdp-toolkit, returning {path,bytes,events,metrics}. Throws if no live trace exists in THIS process (e.g. start ran in a different process) — use performance_trace instead. The target arg is accepted only for API symmetry; at most one trace is ever live per process.",
|
|
11267
11964
|
params: {
|
|
11268
11965
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11269
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions."
|
|
11966
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions."
|
|
11270
11967
|
}
|
|
11271
11968
|
},
|
|
11272
11969
|
performance_analyze_insight: {
|
|
@@ -11280,7 +11977,7 @@ var TOOL_DOCS = {
|
|
|
11280
11977
|
description: "RECOMMENDED entry point: one-shot trace that starts tracing, optionally reloads or navigates the page, waits durationMs (default 3000ms), stops, and writes JSON under /tmp/cdp-toolkit — returns {path,bytes,events,metrics,target}. Holds one connection open for the whole window, so unlike start/stop it is NOT limited to a single process.",
|
|
11281
11978
|
params: {
|
|
11282
11979
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11283
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11980
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11284
11981
|
durationMs: "How long to record after the optional reload/navigate, in ms. Default 3000.",
|
|
11285
11982
|
reload: "Reload the page after starting the trace, to capture full navigation timing.",
|
|
11286
11983
|
navigateTo: "Navigate to this URL after starting the trace (alternative to reload).",
|
|
@@ -11291,7 +11988,7 @@ var TOOL_DOCS = {
|
|
|
11291
11988
|
description: "Starts recording the target tab to video via CDP Page.startScreencast, holding one persistent connection and spooling every frame to disk — MUST be paired with stop_screen_recording WITHIN THE SAME PROCESS (frames are connection-scoped and cannot be reattached from another process, so this only works under the MCP server, not the one-process-per-call CLI). Chrome only: WebDriver BiDi has no screencast primitive, so both tools are absent under --browser firefox. Frames arrive ON REPAINT not on a clock (variable rate); each is timestamped into a ledger that stop_screen_recording turns into per-frame display durations, so a still page holds one long frame instead of racing. ffmpeg is probed here (not at stop) so a missing encoder fails before frames are captured and thrown away. Throws if the target already has a recording in progress; different targets record concurrently.",
|
|
11292
11989
|
params: {
|
|
11293
11990
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11294
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
11991
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11295
11992
|
format: "Frame format, default jpeg (much smaller per repaint); png is lossless. quality applies to jpeg only.",
|
|
11296
11993
|
quality: "JPEG frame quality 0-100. Ignored for png; omitted leaves Chrome's own default.",
|
|
11297
11994
|
maxWidth: "Caps the streamed frame width in px; also pins frame size if the viewport may change mid-recording.",
|
|
@@ -11312,7 +12009,7 @@ var TOOL_DOCS = {
|
|
|
11312
12009
|
description: "Captures a V8 heap snapshot of the target page over CDP and writes it as a .heapsnapshot JSON file (loadable in the DevTools Memory panel) under /tmp/cdp-toolkit unless savePath is given. Returns {path,bytes,chunks,target} only — does NOT parse or summarize the snapshot.",
|
|
11313
12010
|
params: {
|
|
11314
12011
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11315
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
12012
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11316
12013
|
savePath: "Override the output path. Absolute paths (starting with /) are used as-is; relative paths resolve under the artifact dir (/tmp/cdp-toolkit). Defaults to an auto-named take_heapsnapshot-<targetId>-<timestamp>.heapsnapshot file."
|
|
11317
12014
|
}
|
|
11318
12015
|
},
|
|
@@ -11386,7 +12083,7 @@ var TOOL_DOCS = {
|
|
|
11386
12083
|
description: "Structured extraction: take the target page's HTML, clean it, and send it to an OpenAI-compatible /chat/completions endpoint along with your JSON Schema, getting back schema-conformant JSON instead of prose. THE DEFAULT ENDPOINT IS LOOPBACK - llm-ferry at http://127.0.0.1:8090/v1 with model 'schematron' - so page content stays ON THIS MACHINE unless the operator overrides baseUrl (or sets CDP_EXTRACT_BASE_URL). Configuration: CDP_EXTRACT_BASE_URL (endpoint override), CDP_EXTRACT_MODEL (model override), CDP_EXTRACT_API_KEY (bearer token; never logged and REDACTED from every error), CDP_EXTRACT_TIMEOUT_MS, CDP_EXTRACT_MAX_CHARS, CDP_EXTRACT_PROMPT. PROMPT SHAPE: by default only the cleaned HTML is sent and the schema rides in response_format, which is what the HOSTED Schematron API expects (it injects the schema server-side); set prompt:'schematron' when baseUrl points at a LOCALLY SERVED open-weight Schematron (e.g. an MLX schematron8B), because that model was fine-tuned on a prompt with the schema INSIDE the user message and an HTML-only prompt returns garbage from it even under constrained decoding. In 'schematron' mode NO response_format is sent at all - the schema already lives in the prompt, and the client validates only that the response parses as JSON. THE SCHEMA-DESCRIPTION RULE: this is prompt-driven extraction, and the extraction INSTRUCTIONS live in the schema's property descriptions - write them like prompts ('the job title, exactly as printed', 'ISO date, not 'yesterday'). A schema whose properties carry no descriptions is REJECTED up front with an error saying so, because it would produce garbage extraction with no hint why. Source: 'dom' (live DOM, the rendered, JS-executed page) is the default; 'served' (the raw server response before rendering) currently returns a not-implemented error rather than guessing. Size guard: cleaned HTML over maxChars (default 300000) fails with html_too_large naming the actual size - shrink the payload with 'selector' to scope to a subtree, clean:'aggressive' to strip harder (standard already drops scripts/styles/hidden), or a larger maxChars if you truly need it all. Endpoint failures surface as upstream_error (with status and body, API key redacted) or timeout; the response never contains the key. A completion the endpoint cut off at its 8192-token output cap fails naming finish_reason=length and the fix (narrow with 'selector', or ask the schema for less) - it is NOT reported as invalid JSON, because a truncated tail is a size problem, not a model one. COST IS ALWAYS VISIBLE: every successful call reports the endpoint's usage token counts inline, so a slow/bloated extraction is visible in the answer itself, not discovered on a bill later.",
|
|
11387
12084
|
params: {
|
|
11388
12085
|
lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
|
|
11389
|
-
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Grammar: see server instructions.",
|
|
12086
|
+
target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
|
|
11390
12087
|
schema: "REQUIRED JSON Schema object (type object) describing the JSON you want back. This is both the contract AND the prompt: each property's 'description' tells the extractor what to put there, so make them specific instructions. A schema with no property descriptions at all is rejected before any page work happens - empty descriptions extract garbage and the error says exactly what to fix. Nested objects and arrays of objects work; their inner descriptions count too.",
|
|
11391
12088
|
selector: "CSS selector scoping extraction to that subtree's HTML only (pierces open shadow roots). The cheapest fix for html_too_large: extract the article or table, not the whole page. Omit to send the full cleaned document.",
|
|
11392
12089
|
source: "'dom' (default) reads the live, rendered DOM - what the page shows after JS ran. 'served' would read the raw HTTP response before rendering; it currently returns a not-implemented error naming the arm, so callers can detect and fall back rather than guessing.",
|
|
@@ -11401,8 +12098,104 @@ var TOOL_DOCS = {
|
|
|
11401
12098
|
}
|
|
11402
12099
|
};
|
|
11403
12100
|
|
|
12101
|
+
// src/policy.ts
|
|
12102
|
+
var READ_TOOLS = new Set([
|
|
12103
|
+
"list_pages",
|
|
12104
|
+
"wait_for",
|
|
12105
|
+
"evaluate_script",
|
|
12106
|
+
"list_cookies",
|
|
12107
|
+
"take_snapshot",
|
|
12108
|
+
"take_screenshot",
|
|
12109
|
+
"list_console_messages",
|
|
12110
|
+
"get_console_message",
|
|
12111
|
+
"list_network_requests",
|
|
12112
|
+
"get_network_request",
|
|
12113
|
+
"performance_analyze_insight",
|
|
12114
|
+
"take_heapsnapshot",
|
|
12115
|
+
"list_mocks",
|
|
12116
|
+
"extract_page",
|
|
12117
|
+
"list_leases"
|
|
12118
|
+
]);
|
|
12119
|
+
var MUTATING_TOOLS = new Set([
|
|
12120
|
+
"new_page",
|
|
12121
|
+
"close_page",
|
|
12122
|
+
"select_page",
|
|
12123
|
+
"navigate_page",
|
|
12124
|
+
"set_cookie",
|
|
12125
|
+
"delete_cookies",
|
|
12126
|
+
"click",
|
|
12127
|
+
"hover",
|
|
12128
|
+
"drag",
|
|
12129
|
+
"scroll",
|
|
12130
|
+
"fill",
|
|
12131
|
+
"fill_form",
|
|
12132
|
+
"type_text",
|
|
12133
|
+
"press_key",
|
|
12134
|
+
"upload_file",
|
|
12135
|
+
"emulate",
|
|
12136
|
+
"resize_page",
|
|
12137
|
+
"handle_dialog",
|
|
12138
|
+
"performance_start_trace",
|
|
12139
|
+
"performance_stop_trace",
|
|
12140
|
+
"performance_trace",
|
|
12141
|
+
"start_screen_recording",
|
|
12142
|
+
"stop_screen_recording",
|
|
12143
|
+
"lighthouse_audit",
|
|
12144
|
+
"mock_request",
|
|
12145
|
+
"clear_mocks",
|
|
12146
|
+
"dispatch_mouse",
|
|
12147
|
+
"focus_emulation",
|
|
12148
|
+
"click_focus_gated",
|
|
12149
|
+
"wait_for_download",
|
|
12150
|
+
"grant_permissions",
|
|
12151
|
+
"claim_page",
|
|
12152
|
+
"release_page"
|
|
12153
|
+
]);
|
|
12154
|
+
var META_TOOLS = new Set(["search_tools", "call_tool", "describe_tool"]);
|
|
12155
|
+
|
|
12156
|
+
class PolicyError extends Error {
|
|
12157
|
+
code = "read_only_endpoint";
|
|
12158
|
+
tool;
|
|
12159
|
+
endpoint;
|
|
12160
|
+
constructor(tool, endpoint) {
|
|
12161
|
+
super(`'${tool}' is not allowed on endpoint '${endpoint}': the endpoint is read-only (tools that change state are refused before any CDP message is sent)`);
|
|
12162
|
+
this.name = "PolicyError";
|
|
12163
|
+
this.tool = tool;
|
|
12164
|
+
this.endpoint = endpoint;
|
|
12165
|
+
}
|
|
12166
|
+
}
|
|
12167
|
+
function escalatesToMutation(tool, args) {
|
|
12168
|
+
if (typeof args !== "object" || args === null)
|
|
12169
|
+
return false;
|
|
12170
|
+
const a = args;
|
|
12171
|
+
switch (tool) {
|
|
12172
|
+
case "list_console_messages":
|
|
12173
|
+
case "list_network_requests":
|
|
12174
|
+
return a.reload === true;
|
|
12175
|
+
case "get_network_request":
|
|
12176
|
+
return a.includeBody === true && typeof a.url === "string" && a.url !== "";
|
|
12177
|
+
case "take_screenshot":
|
|
12178
|
+
return a.renderWidth !== undefined || a.renderHeight !== undefined;
|
|
12179
|
+
default:
|
|
12180
|
+
return false;
|
|
12181
|
+
}
|
|
12182
|
+
}
|
|
12183
|
+
function assertAllowed(tool, endpoint, args) {
|
|
12184
|
+
if (!endpoint.readOnly)
|
|
12185
|
+
return;
|
|
12186
|
+
if (META_TOOLS.has(tool))
|
|
12187
|
+
return;
|
|
12188
|
+
if (!READ_TOOLS.has(tool))
|
|
12189
|
+
throw new PolicyError(tool, endpoint.name);
|
|
12190
|
+
if (escalatesToMutation(tool, args))
|
|
12191
|
+
throw new PolicyError(tool, endpoint.name);
|
|
12192
|
+
}
|
|
12193
|
+
function toolAnnotations(name) {
|
|
12194
|
+
return { readOnlyHint: READ_TOOLS.has(name) };
|
|
12195
|
+
}
|
|
12196
|
+
|
|
11404
12197
|
// src/version.ts
|
|
11405
|
-
var VERSION = "3.0
|
|
12198
|
+
var VERSION = "3.2.0";
|
|
11406
12199
|
|
|
11407
12200
|
// src/mcp.ts
|
|
11408
12201
|
function isDirectRun() {
|
|
@@ -11462,14 +12255,14 @@ function auditCoverage() {
|
|
|
11462
12255
|
var INSTRUCTIONS = [
|
|
11463
12256
|
"cdp-toolkit drives a real browser over CDP (or Firefox WebDriver-BiDi): pages, input, screenshots, snapshots, console, network, cookies, emulation, Lighthouse, traces, screencasts.",
|
|
11464
12257
|
"TOOLS: by default only 5 are listed (navigate_page, take_snapshot, click, fill, evaluate_script). ~45 more exist: find one with search_tools {query} (returns its schema; no query = catalog), run it with call_tool {name, arguments}. No tab yet? call_tool {name:'new_page'}. The listing is fixed for the process's life; CDP_TOOL_PROFILE=full lists everything.",
|
|
11465
|
-
"TARGET SELECTOR (the `target` param, unless a tool says otherwise): 'active' (default = first page) | 'index:N' (0-based) | 'url:<substr>' | 'title:<substr>' | 'label:<name>' (exact, ledger or live lease) | a 32-hex '<targetId>' of any target type — an iframe id from list_pages{all:true} drives like a tab. Chrome tools also accept 'frame:<substr>' for OOPIF iframe targets. Four Chrome-only tools (evaluate_script, list_network_requests, get_network_request, list_console_messages) also accept 'worker:<substr>' to reach a service/shared worker (e.g.
|
|
12258
|
+
"TARGET SELECTOR (the `target` param, unless a tool says otherwise): 'active' (default = first page) | 'index:N' (0-based) | 'url:<substr>' | 'title:<substr>' | 'label:<name>' (exact, ledger or live lease) | a 32-hex '<targetId>' of any target type — an iframe id from list_pages{all:true} drives like a tab. Chrome tools also accept 'frame:<substr>' for OOPIF iframe targets. Four Chrome-only tools (evaluate_script, list_network_requests, get_network_request, list_console_messages) also accept 'worker:<substr>' to reach a service/shared worker (e.g. MV3 background); an idle-evicted worker is started first (see `wake`). Prefix 'endpoint:<name>/' for a named CDP endpoint; an app endpoint (Teams) lists an empty host page first: use title:.",
|
|
11466
12259
|
"LEASES (the `lease` param): claim_page, and new_page{claim:true}, mint an opaque token. Omit it for a tab THIS process already holds. It is required for a tab held by ANOTHER process, or one claimed explicitly. Under CDP_REQUIRE_LEASE the gate auto-acquires a lease for any tab this process drives — no token is surfaced, so pass `target`, not `lease` — while an explicit claim:true still demands its token on every later call.",
|
|
11467
12260
|
"ORIGIN: list_pages and list_leases tag each tab's `origin` as 'agent' (this toolkit created it) or 'unknown' — never 'human', because the toolkit cannot prove a person opened a tab. An 'agent' tab stays findable after its creator releases the lease or dies."
|
|
11468
12261
|
].join(`
|
|
11469
12262
|
|
|
11470
12263
|
`);
|
|
11471
12264
|
var PROFILE = startupProfile();
|
|
11472
|
-
var
|
|
12265
|
+
var META_TOOLS2 = new Set(["search_tools", "call_tool", "describe_tool"]);
|
|
11473
12266
|
var SEARCH_DEFAULT_LIMIT = 8;
|
|
11474
12267
|
var SEARCH_MAX_LIMIT = 20;
|
|
11475
12268
|
function startupProfile() {
|
|
@@ -11497,7 +12290,8 @@ var LISTING = Object.freeze([
|
|
|
11497
12290
|
}
|
|
11498
12291
|
},
|
|
11499
12292
|
additionalProperties: false
|
|
11500
|
-
}
|
|
12293
|
+
},
|
|
12294
|
+
annotations: { readOnlyHint: true }
|
|
11501
12295
|
},
|
|
11502
12296
|
{
|
|
11503
12297
|
name: "call_tool",
|
|
@@ -11510,9 +12304,10 @@ var LISTING = Object.freeze([
|
|
|
11510
12304
|
},
|
|
11511
12305
|
required: ["name"],
|
|
11512
12306
|
additionalProperties: false
|
|
11513
|
-
}
|
|
12307
|
+
},
|
|
12308
|
+
annotations: { readOnlyHint: false }
|
|
11514
12309
|
},
|
|
11515
|
-
...MANIFEST.filter((s) => AVAILABLE_NAMES.has(s.name) && isListed(PROFILE, s.name)).map((s) => ({ name: s.name, description: s.description, inputSchema: s.inputSchema }))
|
|
12310
|
+
...MANIFEST.filter((s) => AVAILABLE_NAMES.has(s.name) && isListed(PROFILE, s.name)).map((s) => ({ name: s.name, description: s.description, inputSchema: s.inputSchema, annotations: toolAnnotations(s.name) }))
|
|
11516
12311
|
]);
|
|
11517
12312
|
function renderCatalog() {
|
|
11518
12313
|
const lines = [
|
|
@@ -11627,7 +12422,7 @@ function buildServer() {
|
|
|
11627
12422
|
if (typeof inner.name !== "string" || inner.name === "") {
|
|
11628
12423
|
return { content: [{ type: "text", text: "call_tool: `name` is required (find one with search_tools)" }], isError: true };
|
|
11629
12424
|
}
|
|
11630
|
-
if (
|
|
12425
|
+
if (META_TOOLS2.has(inner.name)) {
|
|
11631
12426
|
return { content: [{ type: "text", text: `call_tool: '${inner.name}' is a meta-tool; call it directly` }], isError: true };
|
|
11632
12427
|
}
|
|
11633
12428
|
const innerArgs = inner.arguments ?? {};
|
|
@@ -11640,6 +12435,14 @@ function buildServer() {
|
|
|
11640
12435
|
});
|
|
11641
12436
|
return server;
|
|
11642
12437
|
}
|
|
12438
|
+
function endpointsLogSuffix() {
|
|
12439
|
+
if (BROWSER !== "chrome")
|
|
12440
|
+
return "";
|
|
12441
|
+
const eps = allEndpoints();
|
|
12442
|
+
if (eps.length < 2)
|
|
12443
|
+
return "";
|
|
12444
|
+
return `, endpoints=${eps.map((e) => `${e.name}=${e.base}${e.readOnly ? "(read)" : ""}`).join(",")}`;
|
|
12445
|
+
}
|
|
11643
12446
|
async function runTool(name, args) {
|
|
11644
12447
|
if (!AVAILABLE_NAMES.has(name)) {
|
|
11645
12448
|
const gap = AVAILABILITY.unavailable.find((u) => u.name === name);
|
|
@@ -11654,20 +12457,25 @@ async function runTool(name, args) {
|
|
|
11654
12457
|
if (!fn)
|
|
11655
12458
|
return { content: [{ type: "text", text: `unknown tool: ${name}` }], isError: true };
|
|
11656
12459
|
try {
|
|
11657
|
-
const
|
|
11658
|
-
|
|
12460
|
+
const { endpoint, args: toolArgs } = stripEndpointArgs(args);
|
|
12461
|
+
assertAllowed(name, endpoint, toolArgs);
|
|
12462
|
+
const result = await withEndpointScope(endpoint, () => fn(toolArgs));
|
|
12463
|
+
return { content: [{ type: "text", text: JSON.stringify(result ?? null, null, 2) }] };
|
|
11659
12464
|
} catch (err) {
|
|
11660
12465
|
const message = err instanceof Error ? err.message : String(err);
|
|
11661
12466
|
return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
|
|
11662
12467
|
}
|
|
11663
12468
|
}
|
|
12469
|
+
if (usesEndpointArgs(args)) {
|
|
12470
|
+
return { content: [{ type: "text", text: `Error: ${ENDPOINTS_FIREFOX_MESSAGE}` }], isError: true };
|
|
12471
|
+
}
|
|
11664
12472
|
const neutralFn = neutralDispatch[name];
|
|
11665
12473
|
if (!neutralFn)
|
|
11666
12474
|
return { content: [{ type: "text", text: `unknown tool: ${name}` }], isError: true };
|
|
11667
12475
|
try {
|
|
11668
12476
|
const session = await getOrCreateFirefoxSession({ endpoint: FIREFOX_ENDPOINT });
|
|
11669
12477
|
const result = await neutralFn(session.driver, args);
|
|
11670
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
12478
|
+
return { content: [{ type: "text", text: JSON.stringify(result ?? null, null, 2) }] };
|
|
11671
12479
|
} catch (err) {
|
|
11672
12480
|
const message = err instanceof Error ? err.message : String(err);
|
|
11673
12481
|
return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
|
|
@@ -11678,6 +12486,14 @@ async function run2(argv) {
|
|
|
11678
12486
|
const serve = parseServeOptions(argv);
|
|
11679
12487
|
auditCoverage();
|
|
11680
12488
|
markLongLivedProcess();
|
|
12489
|
+
if (BROWSER === "chrome") {
|
|
12490
|
+
try {
|
|
12491
|
+
endpointConfig();
|
|
12492
|
+
} catch (err) {
|
|
12493
|
+
console.error(`[cdp-toolkit] ${err instanceof Error ? err.message : String(err)}`);
|
|
12494
|
+
process.exit(1);
|
|
12495
|
+
}
|
|
12496
|
+
}
|
|
11681
12497
|
let stdioHandle;
|
|
11682
12498
|
let httpHandler;
|
|
11683
12499
|
let listener;
|
|
@@ -11708,7 +12524,7 @@ async function run2(argv) {
|
|
|
11708
12524
|
return buildServer();
|
|
11709
12525
|
}, { onerror: (err) => console.error(`[cdp-toolkit] stdio: ${err.message}`) });
|
|
11710
12526
|
process.stdin.on("close", () => void shutdown());
|
|
11711
|
-
console.error(`[cdp-toolkit] MCP server v${VERSION} ready, browser=${BROWSER}${FIREFOX_ENDPOINT ? ` (attach ${FIREFOX_ENDPOINT})` : ""}, ${AVAILABILITY.available.length} tools available, ${LISTING.length} listed (CDP_TOOL_PROFILE=${PROFILE.label}), CDP_BASE=${BASE}`);
|
|
12527
|
+
console.error(`[cdp-toolkit] MCP server v${VERSION} ready, browser=${BROWSER}${FIREFOX_ENDPOINT ? ` (attach ${FIREFOX_ENDPOINT})` : ""}, ${AVAILABILITY.available.length} tools available, ${LISTING.length} listed (CDP_TOOL_PROFILE=${PROFILE.label}), CDP_BASE=${BASE}${endpointsLogSuffix()}`);
|
|
11712
12528
|
return;
|
|
11713
12529
|
}
|
|
11714
12530
|
if (typeof Bun === "undefined") {
|
|
@@ -11724,7 +12540,7 @@ async function run2(argv) {
|
|
|
11724
12540
|
hostname: serve.host,
|
|
11725
12541
|
fetch: (req) => hostHeaderValidationResponse(req, localhostAllowedHostnames()) ?? originValidationResponse(req, localhostAllowedOrigins()) ?? httpHandler.fetch(req)
|
|
11726
12542
|
});
|
|
11727
|
-
console.error(`[cdp-toolkit] MCP server v${VERSION} listening on streamable-http port ${listener.port} (http://${serve.host}:${listener.port}/), browser=${BROWSER}${FIREFOX_ENDPOINT ? ` (attach ${FIREFOX_ENDPOINT})` : ""}, ${AVAILABILITY.available.length} tools available, ${LISTING.length} listed (CDP_TOOL_PROFILE=${PROFILE.label}), CDP_BASE=${BASE}`);
|
|
12543
|
+
console.error(`[cdp-toolkit] MCP server v${VERSION} listening on streamable-http port ${listener.port} (http://${serve.host}:${listener.port}/), browser=${BROWSER}${FIREFOX_ENDPOINT ? ` (attach ${FIREFOX_ENDPOINT})` : ""}, ${AVAILABILITY.available.length} tools available, ${LISTING.length} listed (CDP_TOOL_PROFILE=${PROFILE.label}), CDP_BASE=${BASE}${endpointsLogSuffix()}`);
|
|
11728
12544
|
}
|
|
11729
12545
|
if (isDirectRun()) {
|
|
11730
12546
|
run2(process.argv.slice(2)).catch((err) => {
|