@querying/sneaky 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +159 -2
- package/bin/sneaky-mcp.mjs +36 -0
- package/bin/sneaky.mjs +36 -0
- package/dist/agent/index.d.ts +275 -0
- package/dist/agent/index.js +319 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/browser/index.d.ts +69 -0
- package/dist/browser/index.js +326 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/cli/index.d.ts +51 -0
- package/dist/cli/index.js +189 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/driver/cdp.d.ts +36 -0
- package/dist/driver/cdp.js +240 -0
- package/dist/driver/cdp.js.map +1 -0
- package/dist/driver/frame.d.ts +229 -0
- package/dist/driver/frame.js +794 -0
- package/dist/driver/frame.js.map +1 -0
- package/dist/driver/index.d.ts +13 -0
- package/dist/driver/index.js +6 -0
- package/dist/driver/index.js.map +1 -0
- package/dist/driver/keys.d.ts +9 -0
- package/dist/driver/keys.js +65 -0
- package/dist/driver/keys.js.map +1 -0
- package/dist/driver/launcher.d.ts +49 -0
- package/dist/driver/launcher.js +251 -0
- package/dist/driver/launcher.js.map +1 -0
- package/dist/driver/page.d.ts +391 -0
- package/dist/driver/page.js +1594 -0
- package/dist/driver/page.js.map +1 -0
- package/dist/index.d.ts +319 -0
- package/dist/index.js +511 -0
- package/dist/index.js.map +1 -0
- package/dist/request/index.d.ts +265 -0
- package/dist/request/index.js +898 -0
- package/dist/request/index.js.map +1 -0
- package/package.json +79 -4
|
@@ -0,0 +1,794 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
/**
|
|
3
|
+
* Shared in-page selector engine serialized into expressions.
|
|
4
|
+
* Supports CSS selectors, text=..., :has-text(...), role=..., and >> chaining.
|
|
5
|
+
*/
|
|
6
|
+
const QUERY_HELPER_SRC = `(() => {
|
|
7
|
+
const norm = (s) => String(s || "").replace(/\\u200b/g, "").replace(/\\s+/g, " ").trim();
|
|
8
|
+
const isVis = (el) => {
|
|
9
|
+
if (!el || el.nodeType !== 1 || !el.isConnected) return false;
|
|
10
|
+
const st = getComputedStyle(el);
|
|
11
|
+
if (!st || st.display === "none" || st.visibility === "hidden" || parseFloat(st.opacity) === 0) return false;
|
|
12
|
+
const r = el.getBoundingClientRect();
|
|
13
|
+
return r.width > 0 && r.height > 0;
|
|
14
|
+
};
|
|
15
|
+
const splitChain = (sel) => {
|
|
16
|
+
const parts = [];
|
|
17
|
+
let cur = "", q = "";
|
|
18
|
+
for (let i = 0; i < sel.length; i++) {
|
|
19
|
+
const ch = sel[i];
|
|
20
|
+
if (q) { cur += ch; if (ch === q && sel[i - 1] !== "\\\\") q = ""; continue; }
|
|
21
|
+
if (ch === '"' || ch === "'") { q = ch; cur += ch; continue; }
|
|
22
|
+
if (ch === ">" && sel[i + 1] === ">") { parts.push(cur.trim()); cur = ""; i++; continue; }
|
|
23
|
+
cur += ch;
|
|
24
|
+
}
|
|
25
|
+
if (cur.trim()) parts.push(cur.trim());
|
|
26
|
+
return parts;
|
|
27
|
+
};
|
|
28
|
+
const matchStep = (roots, raw) => {
|
|
29
|
+
const out = [];
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
const push = (el) => { if (el && !seen.has(el)) { seen.add(el); out.push(el); } };
|
|
32
|
+
if (raw.startsWith("text=")) {
|
|
33
|
+
let needle = raw.slice(5).trim();
|
|
34
|
+
let exact = false;
|
|
35
|
+
if ((needle.startsWith('"') && needle.endsWith('"')) || (needle.startsWith("'") && needle.endsWith("'"))) {
|
|
36
|
+
needle = needle.slice(1, -1);
|
|
37
|
+
exact = true;
|
|
38
|
+
}
|
|
39
|
+
const want = exact ? norm(needle) : norm(needle).toLowerCase();
|
|
40
|
+
for (const r of roots) {
|
|
41
|
+
const all = r.querySelectorAll ? r.querySelectorAll("*") : [];
|
|
42
|
+
for (const el of all) {
|
|
43
|
+
if (el.tagName === "SCRIPT" || el.tagName === "STYLE") continue;
|
|
44
|
+
const t = norm(el.innerText || el.textContent || "");
|
|
45
|
+
if (!t) continue;
|
|
46
|
+
const ok = exact ? t === want : t.toLowerCase().includes(want);
|
|
47
|
+
if (!ok) continue;
|
|
48
|
+
let childOk = false;
|
|
49
|
+
for (const c of el.children) {
|
|
50
|
+
const ct = norm(c.innerText || c.textContent || "");
|
|
51
|
+
if (ct && (exact ? ct === want : ct.toLowerCase().includes(want))) { childOk = true; break; }
|
|
52
|
+
}
|
|
53
|
+
if (!childOk) push(el);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
const hasTextMatch = /^(.*?):has-text\\((["'])(.*)\\2\\)$/.exec(raw);
|
|
59
|
+
if (hasTextMatch) {
|
|
60
|
+
const baseCss = hasTextMatch[1].trim() || "*";
|
|
61
|
+
const want = norm(hasTextMatch[3]).toLowerCase();
|
|
62
|
+
for (const r of roots) {
|
|
63
|
+
if (!r.querySelectorAll) continue;
|
|
64
|
+
for (const el of r.querySelectorAll(baseCss)) {
|
|
65
|
+
if (norm(el.innerText || el.textContent || "").toLowerCase().includes(want)) push(el);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
const roleMatch = /^role=([a-zA-Z_-]+)(?:\\[name=(["'])(.*)\\2(i)?\\])?$/.exec(raw);
|
|
71
|
+
if (roleMatch) {
|
|
72
|
+
const wantRole = roleMatch[1].toLowerCase();
|
|
73
|
+
const wantName = roleMatch[3] !== undefined ? norm(roleMatch[3]) : null;
|
|
74
|
+
const ci = Boolean(roleMatch[4]);
|
|
75
|
+
const getRole = (el) => {
|
|
76
|
+
const er = (el.getAttribute("role") || "").toLowerCase();
|
|
77
|
+
if (er) return er;
|
|
78
|
+
const tag = el.tagName;
|
|
79
|
+
if (tag === "BUTTON") return "button";
|
|
80
|
+
if (tag === "A" && el.hasAttribute("href")) return "link";
|
|
81
|
+
if (tag === "TEXTAREA") return "textbox";
|
|
82
|
+
if (tag === "SELECT") return "combobox";
|
|
83
|
+
if (tag === "INPUT") {
|
|
84
|
+
const t = (el.getAttribute("type") || "text").toLowerCase();
|
|
85
|
+
if (t === "checkbox") return "checkbox";
|
|
86
|
+
if (t === "radio") return "radio";
|
|
87
|
+
if (t === "submit" || t === "button") return "button";
|
|
88
|
+
if (t === "search") return "searchbox";
|
|
89
|
+
return "textbox";
|
|
90
|
+
}
|
|
91
|
+
return "";
|
|
92
|
+
};
|
|
93
|
+
const getName = (el) => {
|
|
94
|
+
const al = el.getAttribute("aria-label");
|
|
95
|
+
if (al) return norm(al);
|
|
96
|
+
if (el.id) {
|
|
97
|
+
const lb = document.querySelector('label[for="' + CSS.escape(el.id) + '"]');
|
|
98
|
+
if (lb) return norm(lb.textContent || "");
|
|
99
|
+
}
|
|
100
|
+
const pl = el.closest && el.closest("label");
|
|
101
|
+
if (pl) return norm(pl.textContent || "");
|
|
102
|
+
return norm(el.innerText || el.textContent || el.getAttribute("placeholder") || el.getAttribute("title") || "");
|
|
103
|
+
};
|
|
104
|
+
for (const r of roots) {
|
|
105
|
+
if (!r.querySelectorAll) continue;
|
|
106
|
+
for (const el of r.querySelectorAll("*")) {
|
|
107
|
+
if (getRole(el) !== wantRole) continue;
|
|
108
|
+
if (wantName !== null) {
|
|
109
|
+
const got = getName(el);
|
|
110
|
+
const ok = ci ? got.toLowerCase().includes(wantName.toLowerCase()) : got === wantName;
|
|
111
|
+
if (!ok) continue;
|
|
112
|
+
}
|
|
113
|
+
push(el);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
if (raw.includes(":visible")) {
|
|
119
|
+
const splitComma = (s) => {
|
|
120
|
+
const parts = [];
|
|
121
|
+
let cur = "", q = "", depth = 0;
|
|
122
|
+
for (let i = 0; i < s.length; i++) {
|
|
123
|
+
const ch = s[i];
|
|
124
|
+
if (q) { cur += ch; if (ch === q && s[i - 1] !== "\\\\") q = ""; continue; }
|
|
125
|
+
if (ch === '"' || ch === "'") { q = ch; cur += ch; continue; }
|
|
126
|
+
if (ch === "(" || ch === "[") depth++;
|
|
127
|
+
else if ((ch === ")" || ch === "]") && depth > 0) depth--;
|
|
128
|
+
else if (ch === "," && depth === 0) { if (cur.trim()) parts.push(cur.trim()); cur = ""; continue; }
|
|
129
|
+
cur += ch;
|
|
130
|
+
}
|
|
131
|
+
if (cur.trim()) parts.push(cur.trim());
|
|
132
|
+
return parts;
|
|
133
|
+
};
|
|
134
|
+
for (const branch of splitComma(raw)) {
|
|
135
|
+
const needVis = branch.includes(":visible");
|
|
136
|
+
const clean = branch.replace(/:visible\\b/g, "").trim() || "*";
|
|
137
|
+
for (const r of roots) {
|
|
138
|
+
if (!r.querySelectorAll) continue;
|
|
139
|
+
for (const el of r.querySelectorAll(clean)) {
|
|
140
|
+
if (!needVis || isVis(el)) push(el);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
for (const r of roots) {
|
|
147
|
+
if (!r.querySelectorAll) continue;
|
|
148
|
+
for (const el of r.querySelectorAll(raw)) push(el);
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
};
|
|
152
|
+
const queryAll = (steps) => {
|
|
153
|
+
let cur = [document];
|
|
154
|
+
for (const step of steps) {
|
|
155
|
+
const chain = splitChain(step.selector);
|
|
156
|
+
for (const part of chain) cur = matchStep(cur, part);
|
|
157
|
+
if (typeof step.nth === "number") {
|
|
158
|
+
const idx = step.nth < 0 ? cur.length + step.nth : step.nth;
|
|
159
|
+
cur = idx >= 0 && idx < cur.length ? [cur[idx]] : [];
|
|
160
|
+
}
|
|
161
|
+
if (cur.length === 0) break;
|
|
162
|
+
}
|
|
163
|
+
return cur;
|
|
164
|
+
};
|
|
165
|
+
return { queryAll, isVis, norm };
|
|
166
|
+
})()`;
|
|
167
|
+
function timeoutError(message) {
|
|
168
|
+
const err = new Error(message);
|
|
169
|
+
err.name = "TimeoutError";
|
|
170
|
+
return err;
|
|
171
|
+
}
|
|
172
|
+
function serializeCall(fn, arg, hasArg) {
|
|
173
|
+
if (typeof fn === "string")
|
|
174
|
+
return fn;
|
|
175
|
+
const fnSrc = fn.toString();
|
|
176
|
+
if (!hasArg)
|
|
177
|
+
return `(${fnSrc})()`;
|
|
178
|
+
const argJson = arg === undefined ? "undefined" : JSON.stringify(arg);
|
|
179
|
+
return `(${fnSrc})(${argJson})`;
|
|
180
|
+
}
|
|
181
|
+
export class SneakyElementHandle {
|
|
182
|
+
frame;
|
|
183
|
+
objectId;
|
|
184
|
+
backendNodeId;
|
|
185
|
+
disposed = false;
|
|
186
|
+
constructor(frame, objectId, backendNodeId) {
|
|
187
|
+
this.frame = frame;
|
|
188
|
+
this.objectId = objectId;
|
|
189
|
+
this.backendNodeId = backendNodeId;
|
|
190
|
+
}
|
|
191
|
+
async evaluate(fn, arg) {
|
|
192
|
+
const args = arg === undefined ? [] : [{ value: arg }];
|
|
193
|
+
const reply = await this.frame.cdp.send("Runtime.callFunctionOn", {
|
|
194
|
+
objectId: this.objectId,
|
|
195
|
+
functionDeclaration: `function(__arg) { return (${fn.toString()})(this, __arg); }`,
|
|
196
|
+
arguments: args,
|
|
197
|
+
returnByValue: true,
|
|
198
|
+
awaitPromise: true,
|
|
199
|
+
}, this.frame.sessionId);
|
|
200
|
+
if (reply.exceptionDetails) {
|
|
201
|
+
const msg = reply.exceptionDetails.exception?.description || reply.exceptionDetails.text || "evaluation failed";
|
|
202
|
+
throw new Error(msg);
|
|
203
|
+
}
|
|
204
|
+
return reply.result?.value;
|
|
205
|
+
}
|
|
206
|
+
async boundingBox() {
|
|
207
|
+
const rect = await this.evaluate((el) => {
|
|
208
|
+
if (!el.isConnected)
|
|
209
|
+
return null;
|
|
210
|
+
const r = el.getBoundingClientRect();
|
|
211
|
+
if (r.width === 0 && r.height === 0)
|
|
212
|
+
return null;
|
|
213
|
+
return { x: r.left, y: r.top, width: r.width, height: r.height };
|
|
214
|
+
}).catch(() => null);
|
|
215
|
+
if (!rect)
|
|
216
|
+
return null;
|
|
217
|
+
const off = await this.frame.pageOffset();
|
|
218
|
+
return { x: rect.x + off.x, y: rect.y + off.y, width: rect.width, height: rect.height };
|
|
219
|
+
}
|
|
220
|
+
async scrollIntoViewIfNeeded(_options) {
|
|
221
|
+
if (this.backendNodeId) {
|
|
222
|
+
await this.frame.cdp
|
|
223
|
+
.send("DOM.scrollIntoViewIfNeeded", { backendNodeId: this.backendNodeId }, this.frame.sessionId)
|
|
224
|
+
.catch(() => { });
|
|
225
|
+
}
|
|
226
|
+
await this.evaluate((el) => {
|
|
227
|
+
if (typeof el.scrollIntoView === "function") {
|
|
228
|
+
el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
|
|
229
|
+
}
|
|
230
|
+
}).catch(() => { });
|
|
231
|
+
}
|
|
232
|
+
async isVisible() {
|
|
233
|
+
return this.evaluate((el) => {
|
|
234
|
+
if (!el.isConnected)
|
|
235
|
+
return false;
|
|
236
|
+
const st = getComputedStyle(el);
|
|
237
|
+
if (!st || st.display === "none" || st.visibility === "hidden" || parseFloat(st.opacity) === 0)
|
|
238
|
+
return false;
|
|
239
|
+
const r = el.getBoundingClientRect();
|
|
240
|
+
return r.width > 0 && r.height > 0;
|
|
241
|
+
}).catch(() => false);
|
|
242
|
+
}
|
|
243
|
+
async getAttribute(name) {
|
|
244
|
+
return this.evaluate((el, n) => el.getAttribute(n), name);
|
|
245
|
+
}
|
|
246
|
+
async click(options = {}) {
|
|
247
|
+
await this.scrollIntoViewIfNeeded(options);
|
|
248
|
+
const box = await this.boundingBox();
|
|
249
|
+
if (!box)
|
|
250
|
+
throw new Error("Element is not visible or has zero size");
|
|
251
|
+
const x = options.position ? box.x + options.position.x : box.x + box.width / 2;
|
|
252
|
+
const y = options.position ? box.y + options.position.y : box.y + box.height / 2;
|
|
253
|
+
if (this.frame.parentFrame()) {
|
|
254
|
+
// Ensure Chromium's Viz compositor has committed the OOPIF HitTestRegionList before dispatching mouse input.
|
|
255
|
+
await this.frame.evalRaw("new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))").catch(() => { });
|
|
256
|
+
}
|
|
257
|
+
await this.frame.host.mouse.click(x, y, {
|
|
258
|
+
button: options.button,
|
|
259
|
+
clickCount: options.clickCount,
|
|
260
|
+
delay: options.delay,
|
|
261
|
+
});
|
|
262
|
+
if (this.frame.parentFrame()) {
|
|
263
|
+
// Wait one compositor frame so cross-origin OOPIF renderer finishes processing the dispatched click.
|
|
264
|
+
await this.frame.evalRaw("new Promise((r) => requestAnimationFrame(r))").catch(() => { });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async screenshot(options = {}) {
|
|
268
|
+
await this.scrollIntoViewIfNeeded(options);
|
|
269
|
+
const box = await this.boundingBox();
|
|
270
|
+
if (!box || box.width <= 0 || box.height <= 0)
|
|
271
|
+
throw new Error("Element has zero size for screenshot");
|
|
272
|
+
return this.frame.host.screenshot({ ...options, clip: box });
|
|
273
|
+
}
|
|
274
|
+
async dispose() {
|
|
275
|
+
if (this.disposed)
|
|
276
|
+
return;
|
|
277
|
+
this.disposed = true;
|
|
278
|
+
await this.frame.cdp.send("Runtime.releaseObject", { objectId: this.objectId }, this.frame.sessionId).catch(() => { });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
export class SneakyLocator {
|
|
282
|
+
frame;
|
|
283
|
+
steps;
|
|
284
|
+
constructor(frame, steps) {
|
|
285
|
+
this.frame = frame;
|
|
286
|
+
this.steps = steps;
|
|
287
|
+
}
|
|
288
|
+
locator(selector) {
|
|
289
|
+
return new SneakyLocator(this.frame, [...this.steps, { selector }]);
|
|
290
|
+
}
|
|
291
|
+
first() {
|
|
292
|
+
return this.nth(0);
|
|
293
|
+
}
|
|
294
|
+
last() {
|
|
295
|
+
return this.nth(-1);
|
|
296
|
+
}
|
|
297
|
+
nth(index) {
|
|
298
|
+
const next = this.steps.slice();
|
|
299
|
+
const last = next[next.length - 1];
|
|
300
|
+
if (last && last.nth === undefined) {
|
|
301
|
+
next[next.length - 1] = { ...last, nth: index };
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
next.push({ selector: ":scope", nth: index });
|
|
305
|
+
}
|
|
306
|
+
return new SneakyLocator(this.frame, next);
|
|
307
|
+
}
|
|
308
|
+
evalWithMatched(bodySrc, extra, returnByValue = true) {
|
|
309
|
+
const payload = JSON.stringify({ steps: this.steps, extra: extra ?? {} });
|
|
310
|
+
const expr = `(() => {
|
|
311
|
+
const __h = ${QUERY_HELPER_SRC};
|
|
312
|
+
const __p = ${payload};
|
|
313
|
+
const __els = __h.queryAll(__p.steps);
|
|
314
|
+
const __el = __els[0] || null;
|
|
315
|
+
const __extra = __p.extra;
|
|
316
|
+
${bodySrc}
|
|
317
|
+
})()`;
|
|
318
|
+
return this.frame.evalRaw(expr, returnByValue);
|
|
319
|
+
}
|
|
320
|
+
async count() {
|
|
321
|
+
return this.evalWithMatched("return __els.length;");
|
|
322
|
+
}
|
|
323
|
+
async all() {
|
|
324
|
+
const n = await this.count();
|
|
325
|
+
const out = [];
|
|
326
|
+
for (let i = 0; i < n; i++)
|
|
327
|
+
out.push(this.nth(i));
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
async elementHandle(options) {
|
|
331
|
+
if (options?.timeout) {
|
|
332
|
+
await this.waitFor({ state: "attached", timeout: options.timeout }).catch(() => { });
|
|
333
|
+
}
|
|
334
|
+
const objId = await this.frame.evalForObjectId(`(() => {
|
|
335
|
+
const __h = ${QUERY_HELPER_SRC};
|
|
336
|
+
const __els = __h.queryAll(${JSON.stringify(this.steps)});
|
|
337
|
+
return __els[0] || null;
|
|
338
|
+
})()`);
|
|
339
|
+
return objId ? new SneakyElementHandle(this.frame, objId) : null;
|
|
340
|
+
}
|
|
341
|
+
async isVisible(_options) {
|
|
342
|
+
return this.evalWithMatched("return Boolean(__el && __h.isVis(__el));").catch(() => false);
|
|
343
|
+
}
|
|
344
|
+
async isHidden(options) {
|
|
345
|
+
return !(await this.isVisible(options));
|
|
346
|
+
}
|
|
347
|
+
async isEnabled() {
|
|
348
|
+
return this.evalWithMatched(`if (!__el) return false; return !(__el.disabled || __el.getAttribute("aria-disabled") === "true");`);
|
|
349
|
+
}
|
|
350
|
+
async isDisabled() {
|
|
351
|
+
return !(await this.isEnabled());
|
|
352
|
+
}
|
|
353
|
+
async isChecked() {
|
|
354
|
+
return this.evalWithMatched(`if (!__el) return false; return Boolean(__el.checked || __el.getAttribute("aria-checked") === "true");`);
|
|
355
|
+
}
|
|
356
|
+
async boundingBox(_options) {
|
|
357
|
+
const rect = await this.evalWithMatched(`
|
|
358
|
+
if (!__el || !__el.isConnected) return null;
|
|
359
|
+
const r = __el.getBoundingClientRect();
|
|
360
|
+
if (r.width === 0 && r.height === 0) return null;
|
|
361
|
+
return { x: r.left, y: r.top, width: r.width, height: r.height };
|
|
362
|
+
`).catch(() => null);
|
|
363
|
+
if (!rect)
|
|
364
|
+
return null;
|
|
365
|
+
const off = await this.frame.pageOffset();
|
|
366
|
+
return { x: rect.x + off.x, y: rect.y + off.y, width: rect.width, height: rect.height };
|
|
367
|
+
}
|
|
368
|
+
async scrollIntoViewIfNeeded(_options) {
|
|
369
|
+
const scrolled = await this.evalWithMatched(`
|
|
370
|
+
if (!__el || typeof __el.scrollIntoView !== "function") return false;
|
|
371
|
+
const r = __el.getBoundingClientRect();
|
|
372
|
+
const vw = window.innerWidth || document.documentElement.clientWidth || 0;
|
|
373
|
+
const vh = window.innerHeight || document.documentElement.clientHeight || 0;
|
|
374
|
+
if (r.top >= 0 && r.left >= 0 && r.bottom <= vh && r.right <= vw) return false;
|
|
375
|
+
__el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
|
|
376
|
+
return true;
|
|
377
|
+
`).catch(() => false);
|
|
378
|
+
let parentScrolled = false;
|
|
379
|
+
if (this.frame.parentFrame()) {
|
|
380
|
+
const fe = await this.frame.frameElement().catch(() => null);
|
|
381
|
+
if (fe) {
|
|
382
|
+
const feBox = await fe.boundingBox().catch(() => null);
|
|
383
|
+
const vp = this.frame.host.viewportSize();
|
|
384
|
+
if (feBox && vp && (feBox.y < 0 || feBox.x < 0 || feBox.y + feBox.height > vp.height || feBox.x + feBox.width > vp.width)) {
|
|
385
|
+
await fe.scrollIntoViewIfNeeded().catch(() => { });
|
|
386
|
+
parentScrolled = true;
|
|
387
|
+
}
|
|
388
|
+
await fe.dispose().catch(() => { });
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (scrolled || parentScrolled) {
|
|
392
|
+
await this.frame.evalRaw("new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))").catch(() => { });
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async waitFor(options = {}) {
|
|
396
|
+
const state = options.state ?? "visible";
|
|
397
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
398
|
+
const deadline = Date.now() + timeout;
|
|
399
|
+
while (Date.now() < deadline) {
|
|
400
|
+
const ok = await this.evalWithMatched(`
|
|
401
|
+
if (__extra.state === "detached") return !__el;
|
|
402
|
+
if (__extra.state === "hidden") return !__el || !__h.isVis(__el);
|
|
403
|
+
if (__extra.state === "attached") return Boolean(__el);
|
|
404
|
+
return Boolean(__el && __h.isVis(__el));
|
|
405
|
+
`, { state }).catch(() => state === "detached" || state === "hidden");
|
|
406
|
+
if (ok)
|
|
407
|
+
return;
|
|
408
|
+
await new Promise((r) => setTimeout(r, 35));
|
|
409
|
+
}
|
|
410
|
+
throw timeoutError(`Locator waitFor(${state}) timed out after ${timeout}ms: ${JSON.stringify(this.steps)}`);
|
|
411
|
+
}
|
|
412
|
+
async click(options = {}) {
|
|
413
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
414
|
+
if (!options.force)
|
|
415
|
+
await this.waitFor({ state: "visible", timeout });
|
|
416
|
+
await this.scrollIntoViewIfNeeded({ timeout });
|
|
417
|
+
const box = await this.boundingBox();
|
|
418
|
+
if (!box)
|
|
419
|
+
throw new Error(`Locator has no bounding box: ${JSON.stringify(this.steps)}`);
|
|
420
|
+
const x = options.position ? box.x + options.position.x : box.x + box.width / 2;
|
|
421
|
+
const y = options.position ? box.y + options.position.y : box.y + box.height / 2;
|
|
422
|
+
if (this.frame.parentFrame()) {
|
|
423
|
+
// Ensure Chromium's Viz compositor has committed the OOPIF HitTestRegionList before dispatching mouse input.
|
|
424
|
+
await this.frame.evalRaw("new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))").catch(() => { });
|
|
425
|
+
}
|
|
426
|
+
await this.frame.host.mouse.click(x, y, {
|
|
427
|
+
button: options.button,
|
|
428
|
+
clickCount: options.clickCount,
|
|
429
|
+
delay: options.delay,
|
|
430
|
+
});
|
|
431
|
+
if (this.frame.parentFrame()) {
|
|
432
|
+
// Wait one compositor frame so cross-origin OOPIF renderer finishes processing the dispatched click.
|
|
433
|
+
await this.frame.evalRaw("new Promise((r) => requestAnimationFrame(r))").catch(() => { });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
async dblclick(options = {}) {
|
|
437
|
+
return this.click({ ...options, clickCount: 2 });
|
|
438
|
+
}
|
|
439
|
+
async hover(options = {}) {
|
|
440
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
441
|
+
await this.waitFor({ state: "visible", timeout });
|
|
442
|
+
await this.scrollIntoViewIfNeeded({ timeout });
|
|
443
|
+
const box = await this.boundingBox();
|
|
444
|
+
if (!box)
|
|
445
|
+
throw new Error(`Locator has no bounding box: ${JSON.stringify(this.steps)}`);
|
|
446
|
+
const x = options.position ? box.x + options.position.x : box.x + box.width / 2;
|
|
447
|
+
const y = options.position ? box.y + options.position.y : box.y + box.height / 2;
|
|
448
|
+
await this.frame.host.mouse.move(x, y);
|
|
449
|
+
}
|
|
450
|
+
async fill(value, options = {}) {
|
|
451
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
452
|
+
await this.waitFor({ state: "visible", timeout });
|
|
453
|
+
await this.scrollIntoViewIfNeeded({ timeout });
|
|
454
|
+
const ok = await this.evalWithMatched(`
|
|
455
|
+
if (!__el) return false;
|
|
456
|
+
if (typeof __el.focus === "function") __el.focus();
|
|
457
|
+
if (__el.isContentEditable) {
|
|
458
|
+
__el.textContent = __extra.value;
|
|
459
|
+
__el.dispatchEvent(new InputEvent("input", { bubbles: true, data: __extra.value }));
|
|
460
|
+
__el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
if ("value" in __el) {
|
|
464
|
+
const proto = Object.getPrototypeOf(__el);
|
|
465
|
+
const desc = proto ? Object.getOwnPropertyDescriptor(proto, "value") : null;
|
|
466
|
+
if (desc && typeof desc.set === "function") desc.set.call(__el, __extra.value);
|
|
467
|
+
else __el.value = __extra.value;
|
|
468
|
+
__el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
469
|
+
__el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
`, { value });
|
|
474
|
+
if (!ok)
|
|
475
|
+
throw new Error(`Locator target is not fillable: ${JSON.stringify(this.steps)}`);
|
|
476
|
+
}
|
|
477
|
+
async type(text, options = {}) {
|
|
478
|
+
await this.click({ timeout: options.timeout });
|
|
479
|
+
await this.frame.host.keyboard.type(text, { delay: options.delay });
|
|
480
|
+
}
|
|
481
|
+
async press(key, options = {}) {
|
|
482
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
483
|
+
await this.waitFor({ state: "attached", timeout });
|
|
484
|
+
await this.evalWithMatched(`if (__el && typeof __el.focus === "function") __el.focus(); return true;`);
|
|
485
|
+
await this.frame.host.keyboard.press(key, { delay: options.delay });
|
|
486
|
+
}
|
|
487
|
+
async check(options = {}) {
|
|
488
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
489
|
+
await this.waitFor({ state: "visible", timeout });
|
|
490
|
+
if (!(await this.isChecked()))
|
|
491
|
+
await this.click({ timeout });
|
|
492
|
+
}
|
|
493
|
+
async uncheck(options = {}) {
|
|
494
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
495
|
+
await this.waitFor({ state: "visible", timeout });
|
|
496
|
+
if (await this.isChecked())
|
|
497
|
+
await this.click({ timeout });
|
|
498
|
+
}
|
|
499
|
+
async selectOption(values, options = {}) {
|
|
500
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
501
|
+
await this.waitFor({ state: "attached", timeout });
|
|
502
|
+
const first = Array.isArray(values) ? values[0] : values;
|
|
503
|
+
const val = typeof first === "string" ? first : (first?.value ?? "");
|
|
504
|
+
const label = typeof first === "string" ? "" : (first?.label ?? "");
|
|
505
|
+
const selected = await this.evalWithMatched(`
|
|
506
|
+
if (!__el || __el.tagName !== "SELECT") return null;
|
|
507
|
+
const opt = [...__el.options].find((o) =>
|
|
508
|
+
(__extra.val !== "" && o.value === __extra.val) ||
|
|
509
|
+
(__extra.label !== "" && __h.norm(o.textContent) === __h.norm(__extra.label)) ||
|
|
510
|
+
(__extra.val !== "" && __h.norm(o.textContent) === __h.norm(__extra.val))
|
|
511
|
+
);
|
|
512
|
+
if (!opt) return [];
|
|
513
|
+
__el.value = opt.value;
|
|
514
|
+
__el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
515
|
+
__el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
516
|
+
return [opt.value];
|
|
517
|
+
`, { val, label });
|
|
518
|
+
if (!selected || selected.length === 0)
|
|
519
|
+
throw new Error(`Option not found in <select>: ${JSON.stringify(values)}`);
|
|
520
|
+
return selected;
|
|
521
|
+
}
|
|
522
|
+
async textContent(options) {
|
|
523
|
+
if (options?.timeout)
|
|
524
|
+
await this.waitFor({ state: "attached", timeout: options.timeout });
|
|
525
|
+
return this.evalWithMatched("return __el ? __el.textContent : null;");
|
|
526
|
+
}
|
|
527
|
+
async innerText(options) {
|
|
528
|
+
if (options?.timeout)
|
|
529
|
+
await this.waitFor({ state: "visible", timeout: options.timeout });
|
|
530
|
+
return this.evalWithMatched('return __el ? String(__el.innerText ?? __el.textContent ?? "") : "";');
|
|
531
|
+
}
|
|
532
|
+
async innerHTML(options) {
|
|
533
|
+
if (options?.timeout)
|
|
534
|
+
await this.waitFor({ state: "attached", timeout: options.timeout });
|
|
535
|
+
return this.evalWithMatched('return __el ? String(__el.innerHTML ?? "") : "";');
|
|
536
|
+
}
|
|
537
|
+
async inputValue(options) {
|
|
538
|
+
if (options?.timeout)
|
|
539
|
+
await this.waitFor({ state: "attached", timeout: options.timeout });
|
|
540
|
+
return this.evalWithMatched('return __el && "value" in __el ? String(__el.value ?? "") : "";');
|
|
541
|
+
}
|
|
542
|
+
async getAttribute(name, options) {
|
|
543
|
+
if (options?.timeout)
|
|
544
|
+
await this.waitFor({ state: "attached", timeout: options.timeout });
|
|
545
|
+
return this.evalWithMatched("return __el ? __el.getAttribute(__extra.name) : null;", { name });
|
|
546
|
+
}
|
|
547
|
+
async evaluate(fn, arg) {
|
|
548
|
+
const argJson = arg === undefined ? "undefined" : JSON.stringify(arg);
|
|
549
|
+
return this.evalWithMatched(`
|
|
550
|
+
if (!__el) throw new Error("Locator matched no elements");
|
|
551
|
+
return (${fn.toString()})(__el, ${argJson});
|
|
552
|
+
`);
|
|
553
|
+
}
|
|
554
|
+
async evaluateAll(fn, arg) {
|
|
555
|
+
const argJson = arg === undefined ? "undefined" : JSON.stringify(arg);
|
|
556
|
+
return this.evalWithMatched(`return (${fn.toString()})(__els, ${argJson});`);
|
|
557
|
+
}
|
|
558
|
+
async screenshot(options = {}) {
|
|
559
|
+
const timeout = options.timeout ?? this.frame.host.defaultTimeoutMs;
|
|
560
|
+
await this.waitFor({ state: "visible", timeout });
|
|
561
|
+
await this.scrollIntoViewIfNeeded({ timeout });
|
|
562
|
+
const box = await this.boundingBox();
|
|
563
|
+
if (!box || box.width <= 0 || box.height <= 0) {
|
|
564
|
+
throw new Error(`Locator has zero size for screenshot: ${JSON.stringify(this.steps)}`);
|
|
565
|
+
}
|
|
566
|
+
const buf = await this.frame.host.screenshot({ ...options, clip: box, path: undefined });
|
|
567
|
+
if (options.path)
|
|
568
|
+
writeFileSync(options.path, buf);
|
|
569
|
+
return buf;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
export class SneakyFrame {
|
|
573
|
+
host;
|
|
574
|
+
id;
|
|
575
|
+
targetId;
|
|
576
|
+
sessionId;
|
|
577
|
+
isTargetRoot;
|
|
578
|
+
urlValue = "";
|
|
579
|
+
nameValue = "";
|
|
580
|
+
parentFrameId = null;
|
|
581
|
+
detached = false;
|
|
582
|
+
isolatedContextId = null;
|
|
583
|
+
constructor(host, id, targetId, sessionId, isTargetRoot) {
|
|
584
|
+
this.host = host;
|
|
585
|
+
this.id = id;
|
|
586
|
+
this.targetId = targetId;
|
|
587
|
+
this.sessionId = sessionId;
|
|
588
|
+
this.isTargetRoot = isTargetRoot;
|
|
589
|
+
}
|
|
590
|
+
get cdp() {
|
|
591
|
+
return this.host.cdp;
|
|
592
|
+
}
|
|
593
|
+
url() {
|
|
594
|
+
return this.urlValue;
|
|
595
|
+
}
|
|
596
|
+
name() {
|
|
597
|
+
return this.nameValue;
|
|
598
|
+
}
|
|
599
|
+
isDetached() {
|
|
600
|
+
return this.detached;
|
|
601
|
+
}
|
|
602
|
+
page() {
|
|
603
|
+
return this.host;
|
|
604
|
+
}
|
|
605
|
+
parentFrame() {
|
|
606
|
+
if (!this.parentFrameId)
|
|
607
|
+
return null;
|
|
608
|
+
return this.host.frameById(this.parentFrameId) ?? null;
|
|
609
|
+
}
|
|
610
|
+
childFrames() {
|
|
611
|
+
return this.host.childFramesOf(this.id);
|
|
612
|
+
}
|
|
613
|
+
/** Resolves the <iframe> ElementHandle in the parent frame using CDP DOM.getFrameOwner (works for OOPIFs too). */
|
|
614
|
+
async frameElement() {
|
|
615
|
+
const parent = this.parentFrame();
|
|
616
|
+
if (!parent)
|
|
617
|
+
throw new Error("Main frame has no frameElement");
|
|
618
|
+
const owner = await this.cdp.send("DOM.getFrameOwner", { frameId: this.id }, parent.sessionId);
|
|
619
|
+
if (!owner.backendNodeId)
|
|
620
|
+
throw new Error(`Frame owner not found for ${this.id}`);
|
|
621
|
+
const resolved = await this.cdp.send("DOM.resolveNode", { backendNodeId: owner.backendNodeId }, parent.sessionId);
|
|
622
|
+
if (!resolved.object?.objectId)
|
|
623
|
+
throw new Error(`Could not resolve frameElement for ${this.id}`);
|
|
624
|
+
return new SneakyElementHandle(parent, resolved.object.objectId, owner.backendNodeId);
|
|
625
|
+
}
|
|
626
|
+
/** Top-viewport offset of this frame's content origin. */
|
|
627
|
+
async pageOffset() {
|
|
628
|
+
const parent = this.parentFrame();
|
|
629
|
+
if (!parent)
|
|
630
|
+
return { x: 0, y: 0 };
|
|
631
|
+
const el = await this.frameElement().catch(() => null);
|
|
632
|
+
if (!el)
|
|
633
|
+
return { x: 0, y: 0 };
|
|
634
|
+
try {
|
|
635
|
+
const box = await el.boundingBox();
|
|
636
|
+
if (!box)
|
|
637
|
+
return { x: 0, y: 0 };
|
|
638
|
+
const border = await el
|
|
639
|
+
.evaluate((node) => {
|
|
640
|
+
const st = getComputedStyle(node);
|
|
641
|
+
return {
|
|
642
|
+
left: (parseFloat(st.borderLeftWidth) || 0) + (parseFloat(st.paddingLeft) || 0),
|
|
643
|
+
top: (parseFloat(st.borderTopWidth) || 0) + (parseFloat(st.paddingTop) || 0),
|
|
644
|
+
};
|
|
645
|
+
})
|
|
646
|
+
.catch(() => ({ left: 0, top: 0 }));
|
|
647
|
+
return { x: box.x + border.left, y: box.y + border.top };
|
|
648
|
+
}
|
|
649
|
+
finally {
|
|
650
|
+
await el.dispose().catch(() => { });
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
async ensureIsolatedContext() {
|
|
654
|
+
if (this.isolatedContextId)
|
|
655
|
+
return this.isolatedContextId;
|
|
656
|
+
const created = await this.cdp.send("Page.createIsolatedWorld", { frameId: this.id, worldName: "sneaky_agent", grantUniveralAccess: true }, this.sessionId);
|
|
657
|
+
this.isolatedContextId = created.executionContextId;
|
|
658
|
+
return created.executionContextId;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Evaluates an expression inside this frame WITHOUT ever calling Runtime.enable.
|
|
662
|
+
* Main frames and OOPIF roots evaluate directly on their own CDP session (full window.* + DOM access);
|
|
663
|
+
* same-origin child frames evaluate via their owner's contentWindow or isolated world fallback.
|
|
664
|
+
*/
|
|
665
|
+
async evalRaw(expression, returnByValue = true) {
|
|
666
|
+
if (this.isTargetRoot) {
|
|
667
|
+
const reply = await this.cdp.send("Runtime.evaluate", { expression, returnByValue, awaitPromise: true }, this.sessionId);
|
|
668
|
+
if (reply.exceptionDetails) {
|
|
669
|
+
const msg = reply.exceptionDetails.exception?.description || reply.exceptionDetails.text || "evaluation failed";
|
|
670
|
+
throw new Error(msg);
|
|
671
|
+
}
|
|
672
|
+
return (returnByValue ? reply.result?.value : reply.result?.objectId);
|
|
673
|
+
}
|
|
674
|
+
// Same-origin child iframe sharing parent's sessionId: try contentWindow.eval first for window.* parity,
|
|
675
|
+
// falling back to Page.createIsolatedWorld if CSP restricts eval.
|
|
676
|
+
const parent = this.parentFrame();
|
|
677
|
+
if (parent && returnByValue) {
|
|
678
|
+
const owner = await this.frameElement().catch(() => null);
|
|
679
|
+
if (owner) {
|
|
680
|
+
try {
|
|
681
|
+
const reply = await this.cdp.send("Runtime.callFunctionOn", {
|
|
682
|
+
objectId: owner.objectId,
|
|
683
|
+
functionDeclaration: `async function(expr) {
|
|
684
|
+
try {
|
|
685
|
+
const w = this.contentWindow;
|
|
686
|
+
if (!w) return { ok: false, error: "detached frame" };
|
|
687
|
+
return { ok: true, value: await w.eval(expr) };
|
|
688
|
+
} catch (e) {
|
|
689
|
+
if (e && e.name === "EvalError") return { ok: false, csp: true };
|
|
690
|
+
return { ok: false, error: String(e && e.message || e) };
|
|
691
|
+
}
|
|
692
|
+
}`,
|
|
693
|
+
arguments: [{ value: expression }],
|
|
694
|
+
returnByValue: true,
|
|
695
|
+
awaitPromise: true,
|
|
696
|
+
}, parent.sessionId);
|
|
697
|
+
const val = reply.result?.value;
|
|
698
|
+
if (val?.ok)
|
|
699
|
+
return val.value;
|
|
700
|
+
if (val && !val.csp && val.error)
|
|
701
|
+
throw new Error(val.error);
|
|
702
|
+
}
|
|
703
|
+
finally {
|
|
704
|
+
await owner.dispose().catch(() => { });
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
const runIsolated = async () => {
|
|
709
|
+
const contextId = await this.ensureIsolatedContext();
|
|
710
|
+
const reply = await this.cdp.send("Runtime.evaluate", { expression, contextId, returnByValue, awaitPromise: true }, this.sessionId);
|
|
711
|
+
if (reply.exceptionDetails) {
|
|
712
|
+
const msg = reply.exceptionDetails.exception?.description || reply.exceptionDetails.text || "evaluation failed";
|
|
713
|
+
throw new Error(msg);
|
|
714
|
+
}
|
|
715
|
+
return (returnByValue ? reply.result?.value : reply.result?.objectId);
|
|
716
|
+
};
|
|
717
|
+
try {
|
|
718
|
+
return await runIsolated();
|
|
719
|
+
}
|
|
720
|
+
catch (err) {
|
|
721
|
+
if (String(err).includes("Cannot find context")) {
|
|
722
|
+
this.isolatedContextId = null;
|
|
723
|
+
return await runIsolated();
|
|
724
|
+
}
|
|
725
|
+
throw err;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
async evalForObjectId(expression) {
|
|
729
|
+
const res = await this.evalRaw(expression, false);
|
|
730
|
+
return res || null;
|
|
731
|
+
}
|
|
732
|
+
evaluate(fn, arg) {
|
|
733
|
+
const expr = serializeCall(fn, arg, arguments.length >= 2);
|
|
734
|
+
return this.evalRaw(expr, true);
|
|
735
|
+
}
|
|
736
|
+
locator(selector) {
|
|
737
|
+
return new SneakyLocator(this, [{ selector }]);
|
|
738
|
+
}
|
|
739
|
+
getByRole(role, options = {}) {
|
|
740
|
+
const sel = options.name !== undefined
|
|
741
|
+
? `role=${role}[name=${JSON.stringify(options.name)}${options.exact ? "" : "i"}]`
|
|
742
|
+
: `role=${role}`;
|
|
743
|
+
return this.locator(sel);
|
|
744
|
+
}
|
|
745
|
+
getByText(text, options = {}) {
|
|
746
|
+
return this.locator(options.exact ? `text=${JSON.stringify(text)}` : `text=${text}`);
|
|
747
|
+
}
|
|
748
|
+
getByLabel(text) {
|
|
749
|
+
return this.locator(`label:has-text(${JSON.stringify(text)}) input, label:has-text(${JSON.stringify(text)}) textarea, label:has-text(${JSON.stringify(text)}) select`);
|
|
750
|
+
}
|
|
751
|
+
async $(selector) {
|
|
752
|
+
return this.locator(selector).elementHandle();
|
|
753
|
+
}
|
|
754
|
+
async $$(selector) {
|
|
755
|
+
const count = await this.locator(selector).count();
|
|
756
|
+
const handles = [];
|
|
757
|
+
for (let i = 0; i < count; i++) {
|
|
758
|
+
const h = await this.locator(selector).nth(i).elementHandle();
|
|
759
|
+
if (h)
|
|
760
|
+
handles.push(h);
|
|
761
|
+
}
|
|
762
|
+
return handles;
|
|
763
|
+
}
|
|
764
|
+
async waitForSelector(selector, options = {}) {
|
|
765
|
+
const loc = this.locator(selector);
|
|
766
|
+
await loc.waitFor(options);
|
|
767
|
+
if (options.state === "detached" || options.state === "hidden")
|
|
768
|
+
return null;
|
|
769
|
+
return loc.elementHandle();
|
|
770
|
+
}
|
|
771
|
+
async waitForFunction(fn, arg, options = {}) {
|
|
772
|
+
const timeout = options.timeout ?? this.host.defaultTimeoutMs;
|
|
773
|
+
const polling = options.polling ?? 50;
|
|
774
|
+
const deadline = Date.now() + timeout;
|
|
775
|
+
while (Date.now() < deadline) {
|
|
776
|
+
const val = await this.evaluate(fn, arg).catch(() => undefined);
|
|
777
|
+
if (val)
|
|
778
|
+
return val;
|
|
779
|
+
await new Promise((r) => setTimeout(r, polling));
|
|
780
|
+
}
|
|
781
|
+
throw timeoutError(`waitForFunction timed out after ${timeout}ms`);
|
|
782
|
+
}
|
|
783
|
+
content() {
|
|
784
|
+
return this.evaluate(() => {
|
|
785
|
+
const dt = document.doctype;
|
|
786
|
+
const prefix = dt ? `<!DOCTYPE ${dt.name}>\n` : "";
|
|
787
|
+
return prefix + (document.documentElement?.outerHTML ?? "");
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
title() {
|
|
791
|
+
return this.evaluate(() => document.title || "");
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
//# sourceMappingURL=frame.js.map
|