@parcha/pi-browser 0.0.0-bootstrap.0 → 0.1.0-beta.13
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 +16 -0
- package/LICENSE +202 -0
- package/NOTICE +33 -0
- package/README.md +328 -1
- package/dist/coding-agent-local.d.ts +16 -0
- package/dist/coding-agent-local.js +138 -0
- package/dist/coding-agent.d.ts +78 -0
- package/dist/coding-agent.js +446 -0
- package/dist/core/contract.d.ts +26 -0
- package/dist/core/contract.js +154 -0
- package/dist/core/custody.d.ts +111 -0
- package/dist/core/custody.js +122 -0
- package/dist/core/decisions.d.ts +43 -0
- package/dist/core/decisions.js +4 -0
- package/dist/core/downloads.d.ts +35 -0
- package/dist/core/downloads.js +131 -0
- package/dist/core/effects.d.ts +63 -0
- package/dist/core/effects.js +256 -0
- package/dist/core/evidence.d.ts +43 -0
- package/dist/core/evidence.js +6 -0
- package/dist/core/failures.d.ts +28 -0
- package/dist/core/failures.js +59 -0
- package/dist/core/find.d.ts +32 -0
- package/dist/core/find.js +179 -0
- package/dist/core/guard.d.ts +6 -0
- package/dist/core/guard.js +24 -0
- package/dist/core/host.d.ts +279 -0
- package/dist/core/host.js +2 -0
- package/dist/core/images.d.ts +37 -0
- package/dist/core/images.js +60 -0
- package/dist/core/lease.d.ts +16 -0
- package/dist/core/lease.js +30 -0
- package/dist/core/receipts.d.ts +19 -0
- package/dist/core/receipts.js +22 -0
- package/dist/core/redact.d.ts +13 -0
- package/dist/core/redact.js +83 -0
- package/dist/core/session-control.d.ts +25 -0
- package/dist/core/session-control.js +75 -0
- package/dist/core/sites.d.ts +33 -0
- package/dist/core/sites.js +102 -0
- package/dist/core/tools.d.ts +37 -0
- package/dist/core/tools.js +170 -0
- package/dist/core/uri.d.ts +11 -0
- package/dist/core/uri.js +37 -0
- package/dist/core/usage.d.ts +38 -0
- package/dist/core/usage.js +44 -0
- package/dist/core/web.d.ts +98 -0
- package/dist/core/web.js +327 -0
- package/dist/driver/stagehand.d.ts +25 -0
- package/dist/driver/stagehand.js +141 -0
- package/dist/durable-result.d.ts +6 -0
- package/dist/durable-result.js +2 -0
- package/dist/durable.d.ts +75 -0
- package/dist/durable.js +484 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/providers/browserbase-net.d.ts +13 -0
- package/dist/providers/browserbase-net.js +96 -0
- package/dist/providers/browserbase.d.ts +152 -0
- package/dist/providers/browserbase.js +262 -0
- package/dist/providers/cdp-call.d.ts +6 -0
- package/dist/providers/cdp-call.js +25 -0
- package/dist/providers/cdp.d.ts +48 -0
- package/dist/providers/cdp.js +353 -0
- package/dist/providers/http.d.ts +2 -0
- package/dist/providers/http.js +21 -0
- package/dist/providers/kernel.d.ts +49 -0
- package/dist/providers/kernel.js +246 -0
- package/dist/providers/shared.d.ts +47 -0
- package/dist/providers/shared.js +82 -0
- package/dist/recorder/credential.d.ts +9 -0
- package/dist/recorder/credential.js +49 -0
- package/dist/recorder/follow.d.ts +26 -0
- package/dist/recorder/follow.js +138 -0
- package/dist/recorder/frames.d.ts +80 -0
- package/dist/recorder/frames.js +309 -0
- package/dist/recorder/index.d.ts +3 -0
- package/dist/recorder/index.js +6 -0
- package/dist/recorder/jpeg.d.ts +5 -0
- package/dist/recorder/jpeg.js +34 -0
- package/dist/store.d.ts +56 -0
- package/dist/store.js +196 -0
- package/dist/testing/backend.d.ts +231 -0
- package/dist/testing/backend.js +414 -0
- package/dist/testing/driver.d.ts +28 -0
- package/dist/testing/driver.js +32 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/pages.d.ts +3 -0
- package/dist/testing/pages.js +10 -0
- package/dist/testing/sentinels.d.ts +29 -0
- package/dist/testing/sentinels.js +38 -0
- package/dist/vendor/stagehand-facade/contract.d.ts +348 -0
- package/dist/vendor/stagehand-facade/contract.js +155 -0
- package/dist/vendor/stagehand-facade/runtime.d.ts +90 -0
- package/dist/vendor/stagehand-facade/runtime.js +1640 -0
- package/dist/vendor/stagehand-facade/screenshot-transport.d.ts +15 -0
- package/dist/vendor/stagehand-facade/screenshot-transport.js +51 -0
- package/dist/vendor/stagehand-facade/tools.d.ts +31 -0
- package/dist/vendor/stagehand-facade/tools.js +139 -0
- package/dist/web.d.ts +41 -0
- package/dist/web.js +38 -0
- package/package.json +125 -1
- package/src/vendor/stagehand-facade/UPSTREAM.json +24 -0
|
@@ -0,0 +1,1640 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a Playwright-shaped facade entirely inside a Stagehand callback batch.
|
|
3
|
+
* Keep this function self-contained: its source is serialized into the
|
|
4
|
+
* extension service worker with Function#toString.
|
|
5
|
+
*/
|
|
6
|
+
export async function createPlaywrightCompatRuntime(stagehand) {
|
|
7
|
+
const stats = { calls: {}, misses: {} };
|
|
8
|
+
const record = (bucket, method) => {
|
|
9
|
+
stats[bucket][method] = (stats[bucket][method] ?? 0) + 1;
|
|
10
|
+
};
|
|
11
|
+
const matcher = (value, exact = false) => value instanceof RegExp
|
|
12
|
+
? { kind: "regexp", source: value.source, flags: value.flags }
|
|
13
|
+
: { kind: "string", value: String(value), exact };
|
|
14
|
+
const unsupported = (surface, method) => {
|
|
15
|
+
const name = `${surface}.${String(method)}`;
|
|
16
|
+
record("misses", name);
|
|
17
|
+
throw new Error(`Playwright compatibility facade does not implement ${name}`);
|
|
18
|
+
};
|
|
19
|
+
const guard = (surface, target) => new Proxy(target, {
|
|
20
|
+
get(current, property, receiver) {
|
|
21
|
+
if (property === "then")
|
|
22
|
+
return undefined;
|
|
23
|
+
if (Reflect.has(current, property))
|
|
24
|
+
return Reflect.get(current, property, receiver);
|
|
25
|
+
return (..._args) => unsupported(surface, property);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
// This function is serialized independently by Stagehand page.evaluate, so
|
|
29
|
+
// every query helper must remain nested inside it rather than closing over
|
|
30
|
+
// the callback-batch scope.
|
|
31
|
+
async function executeQueryInPage(input) {
|
|
32
|
+
const normalize = (value) => value.replace(/\s+/gu, " ").trim();
|
|
33
|
+
const matches = (value, expected) => {
|
|
34
|
+
const normalized = normalize(value);
|
|
35
|
+
if (expected.kind === "regexp") {
|
|
36
|
+
return new RegExp(expected.source, expected.flags).test(normalized);
|
|
37
|
+
}
|
|
38
|
+
const target = normalize(expected.value);
|
|
39
|
+
return expected.exact
|
|
40
|
+
? normalized === target
|
|
41
|
+
: normalized.toLocaleLowerCase().includes(target.toLocaleLowerCase());
|
|
42
|
+
};
|
|
43
|
+
const visible = (element) => {
|
|
44
|
+
const style = getComputedStyle(element);
|
|
45
|
+
if (style.visibility === "hidden" || style.display === "none")
|
|
46
|
+
return false;
|
|
47
|
+
const rect = element.getBoundingClientRect?.();
|
|
48
|
+
return Boolean(rect && rect.width > 0 && rect.height > 0);
|
|
49
|
+
};
|
|
50
|
+
const dedupe = (elements) => {
|
|
51
|
+
const seen = new Set();
|
|
52
|
+
return elements.filter((element) => {
|
|
53
|
+
if (seen.has(element))
|
|
54
|
+
return false;
|
|
55
|
+
seen.add(element);
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const queryCssDeep = (root, selector) => {
|
|
60
|
+
const direct = [...root.querySelectorAll(selector)];
|
|
61
|
+
const ownShadow = root instanceof Element && root.shadowRoot ? queryCssDeep(root.shadowRoot, selector) : [];
|
|
62
|
+
const nested = [...root.querySelectorAll("*")].flatMap((element) => element.shadowRoot ? queryCssDeep(element.shadowRoot, selector) : []);
|
|
63
|
+
return dedupe([...direct, ...ownShadow, ...nested]);
|
|
64
|
+
};
|
|
65
|
+
const smallestTextMatches = (elements, expected) => elements.filter((element) => matches(element.textContent ?? "", expected) &&
|
|
66
|
+
![...element.children].some((child) => matches(child.textContent ?? "", expected)));
|
|
67
|
+
const queryXPath = (root, expression) => {
|
|
68
|
+
const documentNode = root instanceof Document ? root : root.ownerDocument;
|
|
69
|
+
const result = documentNode.evaluate(expression, root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
|
70
|
+
const elements = [];
|
|
71
|
+
for (let index = 0; index < result.snapshotLength; index += 1) {
|
|
72
|
+
const node = result.snapshotItem(index);
|
|
73
|
+
if (node instanceof Element)
|
|
74
|
+
elements.push(node);
|
|
75
|
+
}
|
|
76
|
+
return elements;
|
|
77
|
+
};
|
|
78
|
+
const splitSelectorList = (selector) => {
|
|
79
|
+
const parts = [];
|
|
80
|
+
let start = 0;
|
|
81
|
+
let depth = 0;
|
|
82
|
+
let quote = "";
|
|
83
|
+
for (let index = 0; index < selector.length; index += 1) {
|
|
84
|
+
const character = selector[index];
|
|
85
|
+
if (quote) {
|
|
86
|
+
if (character === quote && selector[index - 1] !== "\\")
|
|
87
|
+
quote = "";
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (character === '"' || character === "'") {
|
|
91
|
+
quote = character;
|
|
92
|
+
}
|
|
93
|
+
else if (character === "(" || character === "[") {
|
|
94
|
+
depth += 1;
|
|
95
|
+
}
|
|
96
|
+
else if (character === ")" || character === "]") {
|
|
97
|
+
depth = Math.max(0, depth - 1);
|
|
98
|
+
}
|
|
99
|
+
else if (character === "," && depth === 0) {
|
|
100
|
+
parts.push(selector.slice(start, index));
|
|
101
|
+
start = index + 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
parts.push(selector.slice(start));
|
|
105
|
+
return parts;
|
|
106
|
+
};
|
|
107
|
+
const querySelector = (root, rawSelector) => {
|
|
108
|
+
const selector = rawSelector.trim();
|
|
109
|
+
if (selector === "..") {
|
|
110
|
+
return root instanceof Element && root.parentElement ? [root.parentElement] : [];
|
|
111
|
+
}
|
|
112
|
+
if (/^(?:xpath=|\/|\()/u.test(selector)) {
|
|
113
|
+
return queryXPath(root, selector.replace(/^xpath=/u, ""));
|
|
114
|
+
}
|
|
115
|
+
if (/^text=/iu.test(selector)) {
|
|
116
|
+
const text = selector.replace(/^text=/iu, "").replace(/^(?:"(.*)"|'(.*)')$/u, "$1$2");
|
|
117
|
+
const regexp = text.match(/^\/(.*)\/([dgimsuvy]*)$/u);
|
|
118
|
+
return smallestTextMatches(queryCssDeep(root, "*"), regexp
|
|
119
|
+
? { kind: "regexp", source: regexp[1] ?? "", flags: regexp[2] ?? "" }
|
|
120
|
+
: { kind: "string", value: text, exact: false });
|
|
121
|
+
}
|
|
122
|
+
return dedupe(splitSelectorList(selector).flatMap((rawPart) => {
|
|
123
|
+
let part = rawPart.trim().replace(/^css=/u, "");
|
|
124
|
+
if (/^text=/iu.test(part)) {
|
|
125
|
+
const text = part.replace(/^text=/iu, "").replace(/^(?:"(.*)"|'(.*)')$/u, "$1$2");
|
|
126
|
+
const regexp = text.match(/^\/(.*)\/([dgimsuvy]*)$/u);
|
|
127
|
+
return smallestTextMatches(queryCssDeep(root, "*"), regexp
|
|
128
|
+
? { kind: "regexp", source: regexp[1] ?? "", flags: regexp[2] ?? "" }
|
|
129
|
+
: { kind: "string", value: text, exact: false });
|
|
130
|
+
}
|
|
131
|
+
const requireVisible = /:visible\b/u.test(part);
|
|
132
|
+
part = part.replace(/:visible\b/gu, "").replace(/\s*>>>?\s*/gu, " ");
|
|
133
|
+
const pseudo = part.match(/^(.*?):(has-text|text-is|text)\((['"])(.*?)\3\)(.*)$/u);
|
|
134
|
+
let elements;
|
|
135
|
+
if (pseudo) {
|
|
136
|
+
const anchors = queryCssDeep(root, pseudo[1]?.trim() || "*").filter((element) => matches(element.textContent ?? "", {
|
|
137
|
+
kind: "string",
|
|
138
|
+
value: pseudo[4] ?? "",
|
|
139
|
+
exact: pseudo[2] === "text-is",
|
|
140
|
+
}));
|
|
141
|
+
const suffix = pseudo[5]?.trim();
|
|
142
|
+
elements = suffix
|
|
143
|
+
? dedupe(anchors.flatMap((anchor) => queryCssDeep(anchor, suffix)))
|
|
144
|
+
: anchors;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
elements = queryCssDeep(root, part || "*");
|
|
148
|
+
}
|
|
149
|
+
return requireVisible ? elements.filter(visible) : elements;
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
152
|
+
const implicitRole = (element) => {
|
|
153
|
+
const explicit = element.getAttribute("role")?.trim().split(/\s+/u)[0];
|
|
154
|
+
if (explicit)
|
|
155
|
+
return explicit;
|
|
156
|
+
const tag = element.tagName.toLocaleLowerCase();
|
|
157
|
+
if (tag === "button")
|
|
158
|
+
return "button";
|
|
159
|
+
if (tag === "a" && element.hasAttribute("href"))
|
|
160
|
+
return "link";
|
|
161
|
+
if (tag === "img")
|
|
162
|
+
return "img";
|
|
163
|
+
if (/^h[1-6]$/u.test(tag))
|
|
164
|
+
return "heading";
|
|
165
|
+
if (tag === "textarea")
|
|
166
|
+
return "textbox";
|
|
167
|
+
if (tag === "select")
|
|
168
|
+
return element.hasAttribute("multiple") ? "listbox" : "combobox";
|
|
169
|
+
if (tag === "option")
|
|
170
|
+
return "option";
|
|
171
|
+
if (tag === "ul" || tag === "ol")
|
|
172
|
+
return "list";
|
|
173
|
+
if (tag === "li")
|
|
174
|
+
return "listitem";
|
|
175
|
+
if (tag === "table")
|
|
176
|
+
return "table";
|
|
177
|
+
if (tag === "tr")
|
|
178
|
+
return "row";
|
|
179
|
+
if (tag === "th")
|
|
180
|
+
return "columnheader";
|
|
181
|
+
if (tag === "td")
|
|
182
|
+
return "cell";
|
|
183
|
+
if (tag === "nav")
|
|
184
|
+
return "navigation";
|
|
185
|
+
if (tag === "main")
|
|
186
|
+
return "main";
|
|
187
|
+
if (tag === "form")
|
|
188
|
+
return "form";
|
|
189
|
+
if (tag === "input") {
|
|
190
|
+
const type = (element.getAttribute("type") || "text").toLocaleLowerCase();
|
|
191
|
+
if (["button", "submit", "reset", "image"].includes(type))
|
|
192
|
+
return "button";
|
|
193
|
+
if (type === "checkbox")
|
|
194
|
+
return "checkbox";
|
|
195
|
+
if (type === "radio")
|
|
196
|
+
return "radio";
|
|
197
|
+
if (type === "range")
|
|
198
|
+
return "slider";
|
|
199
|
+
if (type === "number")
|
|
200
|
+
return "spinbutton";
|
|
201
|
+
if (type === "search")
|
|
202
|
+
return "searchbox";
|
|
203
|
+
if (!["hidden", "file"].includes(type))
|
|
204
|
+
return "textbox";
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
};
|
|
208
|
+
const labelText = (element) => {
|
|
209
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
210
|
+
if (labelledBy) {
|
|
211
|
+
const text = labelledBy
|
|
212
|
+
.split(/\s+/u)
|
|
213
|
+
.map((id) => element.ownerDocument.getElementById(id)?.textContent ?? "")
|
|
214
|
+
.join(" ");
|
|
215
|
+
if (normalize(text))
|
|
216
|
+
return text;
|
|
217
|
+
}
|
|
218
|
+
const htmlElement = element;
|
|
219
|
+
if (htmlElement.labels?.length) {
|
|
220
|
+
return [...htmlElement.labels].map((label) => label.textContent ?? "").join(" ");
|
|
221
|
+
}
|
|
222
|
+
return "";
|
|
223
|
+
};
|
|
224
|
+
const accessibleName = (element) => {
|
|
225
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
226
|
+
if (ariaLabel)
|
|
227
|
+
return ariaLabel;
|
|
228
|
+
const label = labelText(element);
|
|
229
|
+
if (normalize(label))
|
|
230
|
+
return label;
|
|
231
|
+
if (element instanceof HTMLImageElement && element.alt)
|
|
232
|
+
return element.alt;
|
|
233
|
+
if (element instanceof HTMLInputElement &&
|
|
234
|
+
["button", "submit", "reset"].includes(element.type)) {
|
|
235
|
+
return element.value;
|
|
236
|
+
}
|
|
237
|
+
return element.textContent || element.getAttribute("title") || "";
|
|
238
|
+
};
|
|
239
|
+
const descendants = (roots) => dedupe(roots.flatMap((root) => queryCssDeep(root, "*")));
|
|
240
|
+
const resolve = (steps, initialRoots = [document]) => {
|
|
241
|
+
let current = [];
|
|
242
|
+
let roots = initialRoots;
|
|
243
|
+
for (const step of steps) {
|
|
244
|
+
if (step.kind === "selector") {
|
|
245
|
+
current = dedupe(roots.flatMap((root) => querySelector(root, step.value)));
|
|
246
|
+
}
|
|
247
|
+
else if (step.kind === "text") {
|
|
248
|
+
current = smallestTextMatches(descendants(roots), step.matcher);
|
|
249
|
+
}
|
|
250
|
+
else if (step.kind === "attribute") {
|
|
251
|
+
current = descendants(roots).filter((element) => matches(element.getAttribute(step.name) ?? "", step.matcher));
|
|
252
|
+
}
|
|
253
|
+
else if (step.kind === "label") {
|
|
254
|
+
current = descendants(roots).filter((element) => matches(labelText(element), step.matcher));
|
|
255
|
+
}
|
|
256
|
+
else if (step.kind === "role") {
|
|
257
|
+
current = descendants(roots).filter((element) => {
|
|
258
|
+
if (implicitRole(element) !== step.role)
|
|
259
|
+
return false;
|
|
260
|
+
if (!step.includeHidden && !visible(element))
|
|
261
|
+
return false;
|
|
262
|
+
if (step.name && !matches(accessibleName(element), step.name))
|
|
263
|
+
return false;
|
|
264
|
+
if (step.checked !== undefined &&
|
|
265
|
+
element.checked !== step.checked)
|
|
266
|
+
return false;
|
|
267
|
+
if (step.disabled !== undefined &&
|
|
268
|
+
element.disabled !== step.disabled)
|
|
269
|
+
return false;
|
|
270
|
+
if (step.selected !== undefined &&
|
|
271
|
+
element.selected !== step.selected)
|
|
272
|
+
return false;
|
|
273
|
+
if (step.expanded !== undefined &&
|
|
274
|
+
element.getAttribute("aria-expanded") !== String(step.expanded))
|
|
275
|
+
return false;
|
|
276
|
+
if (step.pressed !== undefined &&
|
|
277
|
+
element.getAttribute("aria-pressed") !== String(step.pressed))
|
|
278
|
+
return false;
|
|
279
|
+
if (step.level !== undefined && Number(element.tagName.slice(1)) !== step.level)
|
|
280
|
+
return false;
|
|
281
|
+
return true;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
else if (step.kind === "filter") {
|
|
285
|
+
current = current.filter((element) => {
|
|
286
|
+
const text = element.textContent ?? "";
|
|
287
|
+
if (step.hasText && !matches(text, step.hasText))
|
|
288
|
+
return false;
|
|
289
|
+
if (step.hasNotText && matches(text, step.hasNotText))
|
|
290
|
+
return false;
|
|
291
|
+
if (step.visible !== undefined && visible(element) !== step.visible)
|
|
292
|
+
return false;
|
|
293
|
+
if (step.has && resolve(step.has, [element]).length === 0)
|
|
294
|
+
return false;
|
|
295
|
+
if (step.hasNot && resolve(step.hasNot, [element]).length > 0)
|
|
296
|
+
return false;
|
|
297
|
+
return true;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
else if (step.kind === "nth") {
|
|
301
|
+
const index = step.index < 0 ? current.length + step.index : step.index;
|
|
302
|
+
current = index >= 0 && index < current.length ? [current[index]] : [];
|
|
303
|
+
}
|
|
304
|
+
roots = current;
|
|
305
|
+
}
|
|
306
|
+
return current;
|
|
307
|
+
};
|
|
308
|
+
if (input.operation === "pageContent") {
|
|
309
|
+
return { count: 1, value: document.documentElement.outerHTML };
|
|
310
|
+
}
|
|
311
|
+
if (input.operation === "pageEvaluateHandle") {
|
|
312
|
+
const fn = (0, eval)(`(${input.functionSource})`);
|
|
313
|
+
const result = await fn(input.argument);
|
|
314
|
+
if (result instanceof Element) {
|
|
315
|
+
const token = input.token;
|
|
316
|
+
result.setAttribute("data-stagehand-pw-compat", token);
|
|
317
|
+
return { count: 1, token, handleKind: "element" };
|
|
318
|
+
}
|
|
319
|
+
return { count: 1, value: result, handleKind: "value" };
|
|
320
|
+
}
|
|
321
|
+
const elements = resolve(input.plan ?? []);
|
|
322
|
+
const first = elements[0];
|
|
323
|
+
if (input.operation === "inspect") {
|
|
324
|
+
return { count: elements.length, visible: first ? visible(first) : false };
|
|
325
|
+
}
|
|
326
|
+
if (input.operation === "untag") {
|
|
327
|
+
document
|
|
328
|
+
.querySelectorAll(`[data-stagehand-pw-compat="${CSS.escape(input.token ?? "")}"]`)
|
|
329
|
+
.forEach((element) => element.removeAttribute("data-stagehand-pw-compat"));
|
|
330
|
+
return { count: 0 };
|
|
331
|
+
}
|
|
332
|
+
if (input.operation === "tag") {
|
|
333
|
+
if (!first)
|
|
334
|
+
return { count: 0 };
|
|
335
|
+
first.setAttribute("data-stagehand-pw-compat", input.token);
|
|
336
|
+
return { count: elements.length, token: input.token };
|
|
337
|
+
}
|
|
338
|
+
if (input.operation === "tagAll") {
|
|
339
|
+
const prefix = input.token;
|
|
340
|
+
const tokens = elements.map((element, index) => {
|
|
341
|
+
const token = `${prefix}-${index}`;
|
|
342
|
+
element.setAttribute("data-stagehand-pw-compat", token);
|
|
343
|
+
return token;
|
|
344
|
+
});
|
|
345
|
+
return { count: elements.length, values: tokens };
|
|
346
|
+
}
|
|
347
|
+
if (input.operation === "allTextContents") {
|
|
348
|
+
return {
|
|
349
|
+
count: elements.length,
|
|
350
|
+
values: elements.map((element) => element.textContent ?? ""),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
if (input.operation === "allInnerTexts") {
|
|
354
|
+
return {
|
|
355
|
+
count: elements.length,
|
|
356
|
+
values: elements.map((element) => element.innerText),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
if (input.operation === "evaluateAll") {
|
|
360
|
+
const fn = (0, eval)(`(${input.functionSource})`);
|
|
361
|
+
return { count: elements.length, value: await fn(elements, input.argument) };
|
|
362
|
+
}
|
|
363
|
+
if (!first)
|
|
364
|
+
return { count: 0 };
|
|
365
|
+
if (input.operation === "textContent")
|
|
366
|
+
return { count: elements.length, value: first.textContent };
|
|
367
|
+
if (input.operation === "innerText")
|
|
368
|
+
return { count: elements.length, value: first.innerText };
|
|
369
|
+
if (input.operation === "innerHTML")
|
|
370
|
+
return { count: elements.length, value: first.innerHTML };
|
|
371
|
+
if (input.operation === "inputValue")
|
|
372
|
+
return { count: elements.length, value: first.value };
|
|
373
|
+
if (input.operation === "isChecked")
|
|
374
|
+
return { count: elements.length, value: Boolean(first.checked) };
|
|
375
|
+
if (input.operation === "isDisabled")
|
|
376
|
+
return {
|
|
377
|
+
count: elements.length,
|
|
378
|
+
value: first.matches(":disabled") ||
|
|
379
|
+
first.getAttribute("aria-disabled")?.toLocaleLowerCase() === "true",
|
|
380
|
+
};
|
|
381
|
+
if (input.operation === "isEnabled")
|
|
382
|
+
return {
|
|
383
|
+
count: elements.length,
|
|
384
|
+
value: !first.matches(":disabled") &&
|
|
385
|
+
first.getAttribute("aria-disabled")?.toLocaleLowerCase() !== "true",
|
|
386
|
+
};
|
|
387
|
+
if (input.operation === "getAttribute")
|
|
388
|
+
return { count: elements.length, value: first.getAttribute(input.attribute) };
|
|
389
|
+
if (input.operation === "boundingBox") {
|
|
390
|
+
const rect = first.getBoundingClientRect?.();
|
|
391
|
+
return {
|
|
392
|
+
count: elements.length,
|
|
393
|
+
value: rect ? { x: rect.x, y: rect.y, width: rect.width, height: rect.height } : null,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
if (input.operation === "focus") {
|
|
397
|
+
first.focus();
|
|
398
|
+
return { count: elements.length };
|
|
399
|
+
}
|
|
400
|
+
if (input.operation === "blur") {
|
|
401
|
+
first.blur();
|
|
402
|
+
return { count: elements.length };
|
|
403
|
+
}
|
|
404
|
+
if (input.operation === "selectText") {
|
|
405
|
+
const selection = window.getSelection();
|
|
406
|
+
const range = document.createRange();
|
|
407
|
+
range.selectNodeContents(first);
|
|
408
|
+
selection?.removeAllRanges();
|
|
409
|
+
selection?.addRange(range);
|
|
410
|
+
return { count: elements.length };
|
|
411
|
+
}
|
|
412
|
+
if (input.operation === "domClick") {
|
|
413
|
+
first.click();
|
|
414
|
+
return { count: elements.length };
|
|
415
|
+
}
|
|
416
|
+
if (input.operation === "scrollIntoView") {
|
|
417
|
+
first.scrollIntoView({ block: "center", inline: "center" });
|
|
418
|
+
return { count: elements.length };
|
|
419
|
+
}
|
|
420
|
+
if (input.operation === "evaluate" || input.operation === "elementEvaluateHandle") {
|
|
421
|
+
const fn = (0, eval)(`(${input.functionSource})`);
|
|
422
|
+
const result = await fn(first, input.argument);
|
|
423
|
+
if (input.operation === "elementEvaluateHandle" && result instanceof Element) {
|
|
424
|
+
const token = input.token;
|
|
425
|
+
result.setAttribute("data-stagehand-pw-compat", token);
|
|
426
|
+
return { count: elements.length, token, handleKind: "element" };
|
|
427
|
+
}
|
|
428
|
+
return { count: elements.length, value: result, handleKind: "value" };
|
|
429
|
+
}
|
|
430
|
+
return { count: elements.length };
|
|
431
|
+
}
|
|
432
|
+
const buildQueryEvaluationExpression = (query) => {
|
|
433
|
+
const functionSource = JSON.stringify(Function.prototype.toString.call(executeQueryInPage));
|
|
434
|
+
const querySource = JSON.stringify(query);
|
|
435
|
+
return `(async () => {
|
|
436
|
+
const identity = (target) => target;
|
|
437
|
+
for (let index = 0; index <= 32; index += 1) {
|
|
438
|
+
globalThis[index === 0 ? "__name" : "__name" + index] = identity;
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const execute = (0, eval)("(" + ${functionSource} + ")");
|
|
442
|
+
return await execute(${querySource});
|
|
443
|
+
} catch (error) {
|
|
444
|
+
return {
|
|
445
|
+
count: 0,
|
|
446
|
+
error: {
|
|
447
|
+
name: typeof error?.name === "string" ? error.name : "Error",
|
|
448
|
+
message: typeof error?.message === "string" ? error.message : String(error),
|
|
449
|
+
...(typeof error?.stack === "string" ? { stack: error.stack } : {}),
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
})()`;
|
|
454
|
+
};
|
|
455
|
+
const rawContext = stagehand.context;
|
|
456
|
+
const pageKey = (page) => page.pageId ?? page;
|
|
457
|
+
const compatPages = new Map();
|
|
458
|
+
const closedPages = new Set();
|
|
459
|
+
let closeRequested = false;
|
|
460
|
+
const contextPageListeners = new Map();
|
|
461
|
+
const screenshotArtifacts = [];
|
|
462
|
+
const encodeBase64 = (bytes) => {
|
|
463
|
+
let binary = "";
|
|
464
|
+
const chunkSize = 0x8000;
|
|
465
|
+
for (let offset = 0; offset < bytes.length; offset += chunkSize) {
|
|
466
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + chunkSize));
|
|
467
|
+
}
|
|
468
|
+
return btoa(binary);
|
|
469
|
+
};
|
|
470
|
+
class CompatLocator {
|
|
471
|
+
plan;
|
|
472
|
+
state;
|
|
473
|
+
constructor(plan, state) {
|
|
474
|
+
this.plan = plan;
|
|
475
|
+
this.state = state;
|
|
476
|
+
}
|
|
477
|
+
derived(step) {
|
|
478
|
+
return locatorProxy(new CompatLocator([...this.plan, step], this.state));
|
|
479
|
+
}
|
|
480
|
+
locator(selector, options = {}) {
|
|
481
|
+
record("calls", "locator.locator");
|
|
482
|
+
const located = this.derived({ kind: "selector", value: selector });
|
|
483
|
+
return Object.keys(options).length > 0 ? located.filter(options) : located;
|
|
484
|
+
}
|
|
485
|
+
getByText(value, options = {}) {
|
|
486
|
+
record("calls", "locator.getByText");
|
|
487
|
+
return this.derived({ kind: "text", matcher: matcher(value, options.exact) });
|
|
488
|
+
}
|
|
489
|
+
getByRole(role, options = {}) {
|
|
490
|
+
record("calls", "locator.getByRole");
|
|
491
|
+
return this.derived({
|
|
492
|
+
kind: "role",
|
|
493
|
+
role,
|
|
494
|
+
...(options.name === undefined
|
|
495
|
+
? {}
|
|
496
|
+
: { name: matcher(options.name, options.exact === true) }),
|
|
497
|
+
...(typeof options.checked === "boolean" ? { checked: options.checked } : {}),
|
|
498
|
+
...(typeof options.disabled === "boolean" ? { disabled: options.disabled } : {}),
|
|
499
|
+
...(typeof options.selected === "boolean" ? { selected: options.selected } : {}),
|
|
500
|
+
...(typeof options.expanded === "boolean" ? { expanded: options.expanded } : {}),
|
|
501
|
+
...(typeof options.pressed === "boolean" ? { pressed: options.pressed } : {}),
|
|
502
|
+
...(typeof options.includeHidden === "boolean"
|
|
503
|
+
? { includeHidden: options.includeHidden }
|
|
504
|
+
: {}),
|
|
505
|
+
...(typeof options.level === "number" ? { level: options.level } : {}),
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
getByLabel(value, options = {}) {
|
|
509
|
+
record("calls", "locator.getByLabel");
|
|
510
|
+
return this.derived({ kind: "label", matcher: matcher(value, options.exact) });
|
|
511
|
+
}
|
|
512
|
+
byAttribute(name, value, exact) {
|
|
513
|
+
return this.derived({ kind: "attribute", name, matcher: matcher(value, exact) });
|
|
514
|
+
}
|
|
515
|
+
getByPlaceholder(value, options = {}) {
|
|
516
|
+
record("calls", "locator.getByPlaceholder");
|
|
517
|
+
return this.byAttribute("placeholder", value, options.exact);
|
|
518
|
+
}
|
|
519
|
+
getByAltText(value, options = {}) {
|
|
520
|
+
record("calls", "locator.getByAltText");
|
|
521
|
+
return this.byAttribute("alt", value, options.exact);
|
|
522
|
+
}
|
|
523
|
+
getByTitle(value, options = {}) {
|
|
524
|
+
record("calls", "locator.getByTitle");
|
|
525
|
+
return this.byAttribute("title", value, options.exact);
|
|
526
|
+
}
|
|
527
|
+
getByTestId(value) {
|
|
528
|
+
record("calls", "locator.getByTestId");
|
|
529
|
+
return this.byAttribute("data-testid", value, true);
|
|
530
|
+
}
|
|
531
|
+
filter(options) {
|
|
532
|
+
record("calls", "locator.filter");
|
|
533
|
+
const has = options.has instanceof CompatLocator ? options.has.plan : undefined;
|
|
534
|
+
const hasNot = options.hasNot instanceof CompatLocator ? options.hasNot.plan : undefined;
|
|
535
|
+
return this.derived({
|
|
536
|
+
kind: "filter",
|
|
537
|
+
...(options.hasText === undefined ? {} : { hasText: matcher(options.hasText) }),
|
|
538
|
+
...(options.hasNotText === undefined ? {} : { hasNotText: matcher(options.hasNotText) }),
|
|
539
|
+
...(has ? { has } : {}),
|
|
540
|
+
...(hasNot ? { hasNot } : {}),
|
|
541
|
+
...(typeof options.visible === "boolean" ? { visible: options.visible } : {}),
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
first() {
|
|
545
|
+
record("calls", "locator.first");
|
|
546
|
+
return this.derived({ kind: "nth", index: 0 });
|
|
547
|
+
}
|
|
548
|
+
last() {
|
|
549
|
+
record("calls", "locator.last");
|
|
550
|
+
return this.derived({ kind: "nth", index: -1 });
|
|
551
|
+
}
|
|
552
|
+
nth(index) {
|
|
553
|
+
record("calls", "locator.nth");
|
|
554
|
+
return this.derived({ kind: "nth", index });
|
|
555
|
+
}
|
|
556
|
+
async count() {
|
|
557
|
+
record("calls", "locator.count");
|
|
558
|
+
return (await this.state.execute(this.plan, "inspect")).count;
|
|
559
|
+
}
|
|
560
|
+
async all() {
|
|
561
|
+
record("calls", "locator.all");
|
|
562
|
+
const prefix = crypto.randomUUID();
|
|
563
|
+
const result = await this.state.execute(this.plan, "tagAll", { token: prefix });
|
|
564
|
+
return result.values.map((token) => locatorProxy(new CompatLocator([
|
|
565
|
+
{ kind: "selector", value: `[data-stagehand-pw-compat="${token}"]` },
|
|
566
|
+
{ kind: "nth", index: 0 },
|
|
567
|
+
], this.state)));
|
|
568
|
+
}
|
|
569
|
+
async allTextContents() {
|
|
570
|
+
record("calls", "locator.allTextContents");
|
|
571
|
+
return (await this.state.execute(this.plan, "allTextContents")).values;
|
|
572
|
+
}
|
|
573
|
+
async allInnerTexts() {
|
|
574
|
+
record("calls", "locator.allInnerTexts");
|
|
575
|
+
return (await this.state.execute(this.plan, "allInnerTexts")).values;
|
|
576
|
+
}
|
|
577
|
+
async singleValue(operation, extra = {}) {
|
|
578
|
+
const result = await this.state.execute(this.plan, operation, extra);
|
|
579
|
+
if (result.count === 0)
|
|
580
|
+
throw new Error(`locator.${operation}: no element matched`);
|
|
581
|
+
return result.value;
|
|
582
|
+
}
|
|
583
|
+
async textContent() {
|
|
584
|
+
record("calls", "locator.textContent");
|
|
585
|
+
return (await this.singleValue("textContent"));
|
|
586
|
+
}
|
|
587
|
+
async innerText() {
|
|
588
|
+
record("calls", "locator.innerText");
|
|
589
|
+
return (await this.singleValue("innerText"));
|
|
590
|
+
}
|
|
591
|
+
async innerHTML() {
|
|
592
|
+
record("calls", "locator.innerHTML");
|
|
593
|
+
return (await this.singleValue("innerHTML"));
|
|
594
|
+
}
|
|
595
|
+
async inputValue() {
|
|
596
|
+
record("calls", "locator.inputValue");
|
|
597
|
+
return (await this.singleValue("inputValue"));
|
|
598
|
+
}
|
|
599
|
+
async getAttribute(name) {
|
|
600
|
+
record("calls", "locator.getAttribute");
|
|
601
|
+
return (await this.singleValue("getAttribute", { attribute: name }));
|
|
602
|
+
}
|
|
603
|
+
async isVisible() {
|
|
604
|
+
record("calls", "locator.isVisible");
|
|
605
|
+
const result = await this.state.execute(this.plan, "inspect");
|
|
606
|
+
return result.count > 0 && result.visible === true;
|
|
607
|
+
}
|
|
608
|
+
async isChecked() {
|
|
609
|
+
record("calls", "locator.isChecked");
|
|
610
|
+
return (await this.singleValue("isChecked"));
|
|
611
|
+
}
|
|
612
|
+
async isDisabled() {
|
|
613
|
+
record("calls", "locator.isDisabled");
|
|
614
|
+
return (await this.singleValue("isDisabled"));
|
|
615
|
+
}
|
|
616
|
+
async isEnabled() {
|
|
617
|
+
record("calls", "locator.isEnabled");
|
|
618
|
+
return (await this.singleValue("isEnabled"));
|
|
619
|
+
}
|
|
620
|
+
async boundingBox() {
|
|
621
|
+
record("calls", "locator.boundingBox");
|
|
622
|
+
const result = await this.state.execute(this.plan, "boundingBox");
|
|
623
|
+
return result.count === 0
|
|
624
|
+
? null
|
|
625
|
+
: result.value;
|
|
626
|
+
}
|
|
627
|
+
getBoundingClientRect() {
|
|
628
|
+
record("calls", "locator.getBoundingClientRect");
|
|
629
|
+
return this.boundingBox();
|
|
630
|
+
}
|
|
631
|
+
async evaluate(fn, arg) {
|
|
632
|
+
record("calls", "locator.evaluate");
|
|
633
|
+
return (await this.singleValue("evaluate", {
|
|
634
|
+
functionSource: Function.prototype.toString.call(fn),
|
|
635
|
+
...(arg === undefined ? {} : { argument: arg }),
|
|
636
|
+
}));
|
|
637
|
+
}
|
|
638
|
+
async evaluateAll(fn, arg) {
|
|
639
|
+
record("calls", "locator.evaluateAll");
|
|
640
|
+
return (await this.state.execute(this.plan, "evaluateAll", {
|
|
641
|
+
functionSource: Function.prototype.toString.call(fn),
|
|
642
|
+
...(arg === undefined ? {} : { argument: arg }),
|
|
643
|
+
})).value;
|
|
644
|
+
}
|
|
645
|
+
async evaluateHandle(fn, arg) {
|
|
646
|
+
record("calls", "locator.evaluateHandle");
|
|
647
|
+
const token = crypto.randomUUID();
|
|
648
|
+
const result = await this.state.execute(this.plan, "elementEvaluateHandle", {
|
|
649
|
+
functionSource: Function.prototype.toString.call(fn),
|
|
650
|
+
...(arg === undefined ? {} : { argument: arg }),
|
|
651
|
+
token,
|
|
652
|
+
});
|
|
653
|
+
return jsHandle(result, this.state);
|
|
654
|
+
}
|
|
655
|
+
async focus() {
|
|
656
|
+
record("calls", "locator.focus");
|
|
657
|
+
await this.singleValue("focus");
|
|
658
|
+
}
|
|
659
|
+
async blur() {
|
|
660
|
+
record("calls", "locator.blur");
|
|
661
|
+
await this.singleValue("blur");
|
|
662
|
+
}
|
|
663
|
+
async selectText() {
|
|
664
|
+
record("calls", "locator.selectText");
|
|
665
|
+
await this.singleValue("selectText");
|
|
666
|
+
}
|
|
667
|
+
async waitFor(options = {}) {
|
|
668
|
+
record("calls", "locator.waitFor");
|
|
669
|
+
const state = options.state ?? "visible";
|
|
670
|
+
const timeout = options.timeout ?? 30_000;
|
|
671
|
+
const deadline = Date.now() + timeout;
|
|
672
|
+
do {
|
|
673
|
+
const result = await this.state.execute(this.plan, "inspect");
|
|
674
|
+
const ready = state === "attached"
|
|
675
|
+
? result.count > 0
|
|
676
|
+
: state === "detached"
|
|
677
|
+
? result.count === 0
|
|
678
|
+
: state === "hidden"
|
|
679
|
+
? result.count === 0 || result.visible !== true
|
|
680
|
+
: result.count > 0 && result.visible === true;
|
|
681
|
+
if (ready)
|
|
682
|
+
return;
|
|
683
|
+
await this.state.rawPage.waitForTimeout(50);
|
|
684
|
+
} while (Date.now() < deadline);
|
|
685
|
+
throw new Error(`locator.waitFor: timed out after ${timeout}ms waiting for ${state}`);
|
|
686
|
+
}
|
|
687
|
+
async scrollIntoViewIfNeeded() {
|
|
688
|
+
record("calls", "locator.scrollIntoViewIfNeeded");
|
|
689
|
+
await this.singleValue("scrollIntoView");
|
|
690
|
+
}
|
|
691
|
+
async withTaggedTarget(method, action, options = {}) {
|
|
692
|
+
record("calls", method);
|
|
693
|
+
const timeout = options.timeout ?? 30_000;
|
|
694
|
+
const deadline = Date.now() + timeout;
|
|
695
|
+
let result = { count: 0 };
|
|
696
|
+
let lastActionError;
|
|
697
|
+
while (Date.now() <= deadline) {
|
|
698
|
+
result = await this.state.execute(this.plan, "inspect");
|
|
699
|
+
if (result.count > 1) {
|
|
700
|
+
throw new Error(`${method}: strict mode violation: ${result.count} elements matched`);
|
|
701
|
+
}
|
|
702
|
+
if (result.count === 1) {
|
|
703
|
+
// Playwright actions scroll their target into view. Do this before tagging so
|
|
704
|
+
// Stagehand receives a unique, attached selector without imposing a viewport-
|
|
705
|
+
// visibility precondition that its own locator action can already satisfy.
|
|
706
|
+
await this.state.execute(this.plan, "scrollIntoView").catch(() => undefined);
|
|
707
|
+
const token = crypto.randomUUID();
|
|
708
|
+
await this.state.execute(this.plan, "tag", { token });
|
|
709
|
+
let actionSucceeded = false;
|
|
710
|
+
try {
|
|
711
|
+
await action(this.state.rawPage.locator(`[data-stagehand-pw-compat="${token}"]`));
|
|
712
|
+
actionSucceeded = true;
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
lastActionError = error;
|
|
716
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
717
|
+
const retryable = /(?:not found|could not find|no (?:element|node)|detached|not visible|(?:box model|layout object)|execution context|session|target closed|timed? out|timeout)/iu.test(message);
|
|
718
|
+
if (!retryable || Date.now() >= deadline)
|
|
719
|
+
throw error;
|
|
720
|
+
}
|
|
721
|
+
finally {
|
|
722
|
+
await this.state.execute([], "untag", { token }).catch(() => undefined);
|
|
723
|
+
}
|
|
724
|
+
if (actionSucceeded) {
|
|
725
|
+
await this.state.refreshUrl();
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
if (Date.now() < deadline)
|
|
730
|
+
await this.state.rawPage.waitForTimeout(50);
|
|
731
|
+
}
|
|
732
|
+
if (lastActionError)
|
|
733
|
+
throw lastActionError;
|
|
734
|
+
throw new Error(`${method}: no element matched within ${timeout}ms`);
|
|
735
|
+
}
|
|
736
|
+
async click(options = {}) {
|
|
737
|
+
if (options.force === true) {
|
|
738
|
+
record("calls", "locator.click");
|
|
739
|
+
const result = await this.state.execute(this.plan, "inspect");
|
|
740
|
+
if (result.count === 0)
|
|
741
|
+
throw new Error("locator.click: no element matched");
|
|
742
|
+
if (result.count > 1) {
|
|
743
|
+
throw new Error(`locator.click: strict mode violation: ${result.count} elements matched`);
|
|
744
|
+
}
|
|
745
|
+
await this.state.execute(this.plan, "domClick");
|
|
746
|
+
await this.state.refreshUrl();
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
await this.withTaggedTarget("locator.click", (locator) => locator.click({
|
|
750
|
+
...(typeof options.button === "string"
|
|
751
|
+
? { button: options.button }
|
|
752
|
+
: {}),
|
|
753
|
+
...(typeof options.clickCount === "number" ? { clickCount: options.clickCount } : {}),
|
|
754
|
+
}), options);
|
|
755
|
+
}
|
|
756
|
+
async fill(value, options = {}) {
|
|
757
|
+
await this.withTaggedTarget("locator.fill", (locator) => locator.fill(value), options);
|
|
758
|
+
}
|
|
759
|
+
async type(value, options = {}) {
|
|
760
|
+
await this.withTaggedTarget("locator.type", (locator) => locator.type(value, typeof options.delay === "number" ? { delay: options.delay } : undefined), options);
|
|
761
|
+
}
|
|
762
|
+
pressSequentially(value, options = {}) {
|
|
763
|
+
record("calls", "locator.pressSequentially");
|
|
764
|
+
return this.type(value, options);
|
|
765
|
+
}
|
|
766
|
+
async press(key, options = {}) {
|
|
767
|
+
await this.withTaggedTarget("locator.press", async (locator) => {
|
|
768
|
+
await locator.click();
|
|
769
|
+
await this.state.rawPage.keyPress(key, typeof options.delay === "number" ? { delay: options.delay } : undefined);
|
|
770
|
+
}, options);
|
|
771
|
+
}
|
|
772
|
+
async hover(options = {}) {
|
|
773
|
+
await this.withTaggedTarget("locator.hover", (locator) => locator.hover(), options);
|
|
774
|
+
}
|
|
775
|
+
async selectOption(values, options = {}) {
|
|
776
|
+
const requested = Array.isArray(values) ? values : [values];
|
|
777
|
+
const indices = requested
|
|
778
|
+
.map((value, position) => typeof value === "object" && value !== null && typeof value.index === "number"
|
|
779
|
+
? { position, index: value.index }
|
|
780
|
+
: null)
|
|
781
|
+
.filter((value) => value !== null);
|
|
782
|
+
const indexedValues = indices.length === 0
|
|
783
|
+
? []
|
|
784
|
+
: await this.evaluate((element, requestedIndices) => {
|
|
785
|
+
const select = element;
|
|
786
|
+
return requestedIndices.map(({ index }) => select.options[index]?.value ?? null);
|
|
787
|
+
}, indices);
|
|
788
|
+
const normalized = requested.map((value, position) => {
|
|
789
|
+
if (typeof value === "string")
|
|
790
|
+
return value;
|
|
791
|
+
if (typeof value.value === "string")
|
|
792
|
+
return value.value;
|
|
793
|
+
if (typeof value.label === "string")
|
|
794
|
+
return value.label;
|
|
795
|
+
const indexedPosition = indices.findIndex((entry) => entry.position === position);
|
|
796
|
+
const indexedValue = indexedValues[indexedPosition];
|
|
797
|
+
if (typeof indexedValue === "string")
|
|
798
|
+
return indexedValue;
|
|
799
|
+
throw new Error(`locator.selectOption: option index ${String(value.index)} did not match`);
|
|
800
|
+
});
|
|
801
|
+
let selected = [];
|
|
802
|
+
await this.withTaggedTarget("locator.selectOption", async (locator) => {
|
|
803
|
+
selected = await locator.selectOption(Array.isArray(values) ? normalized : normalized[0]);
|
|
804
|
+
}, options);
|
|
805
|
+
return selected;
|
|
806
|
+
}
|
|
807
|
+
async setInputFiles(files, options = {}) {
|
|
808
|
+
await this.withTaggedTarget("locator.setInputFiles", (locator) => locator.setInputFiles(files), options);
|
|
809
|
+
}
|
|
810
|
+
async check(options = {}) {
|
|
811
|
+
record("calls", "locator.check");
|
|
812
|
+
if (!(await this.isChecked()))
|
|
813
|
+
await this.click(options);
|
|
814
|
+
}
|
|
815
|
+
async uncheck(options = {}) {
|
|
816
|
+
record("calls", "locator.uncheck");
|
|
817
|
+
if (await this.isChecked())
|
|
818
|
+
await this.click(options);
|
|
819
|
+
}
|
|
820
|
+
async clear(options = {}) {
|
|
821
|
+
record("calls", "locator.clear");
|
|
822
|
+
await this.fill("", options);
|
|
823
|
+
}
|
|
824
|
+
async $(selector) {
|
|
825
|
+
record("calls", "element.$");
|
|
826
|
+
const locator = (await this.locator(selector).all())[0];
|
|
827
|
+
return locator ? markElementHandle(locator, this.state) : null;
|
|
828
|
+
}
|
|
829
|
+
async $$(selector) {
|
|
830
|
+
record("calls", "element.$$");
|
|
831
|
+
return (await this.locator(selector).all()).map((locator) => markElementHandle(locator, this.state));
|
|
832
|
+
}
|
|
833
|
+
async $eval(selector, fn, arg) {
|
|
834
|
+
record("calls", "element.$eval");
|
|
835
|
+
return this.locator(selector).first().evaluate(fn, arg);
|
|
836
|
+
}
|
|
837
|
+
async $$eval(selector, fn, arg) {
|
|
838
|
+
record("calls", "element.$$eval");
|
|
839
|
+
return this.locator(selector).evaluateAll(fn, arg);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
const locatorProxy = (locator) => guard("locator", locator);
|
|
843
|
+
const handleMetadata = new WeakMap();
|
|
844
|
+
const pageStateMetadata = new WeakMap();
|
|
845
|
+
const markElementHandle = (locator, state) => {
|
|
846
|
+
handleMetadata.set(locator, {
|
|
847
|
+
element: locator,
|
|
848
|
+
result: { count: 1, handleKind: "element" },
|
|
849
|
+
state,
|
|
850
|
+
});
|
|
851
|
+
return locator;
|
|
852
|
+
};
|
|
853
|
+
const jsHandle = (result, state) => {
|
|
854
|
+
const element = result.handleKind === "element" && result.token
|
|
855
|
+
? locatorProxy(new CompatLocator([
|
|
856
|
+
{ kind: "selector", value: `[data-stagehand-pw-compat="${result.token}"]` },
|
|
857
|
+
{ kind: "nth", index: 0 },
|
|
858
|
+
], state))
|
|
859
|
+
: null;
|
|
860
|
+
const target = {
|
|
861
|
+
asElement: () => element,
|
|
862
|
+
jsonValue: async () => result.value,
|
|
863
|
+
evaluate: (fn, arg) => element
|
|
864
|
+
? element.evaluate(fn, arg)
|
|
865
|
+
: state.rawPage.evaluate((payload) => {
|
|
866
|
+
const evaluate = (0, eval)(`(${payload.functionSource})`);
|
|
867
|
+
return evaluate(payload.value, payload.argument);
|
|
868
|
+
}, {
|
|
869
|
+
functionSource: Function.prototype.toString.call(fn),
|
|
870
|
+
...(result.value === undefined ? {} : { value: result.value }),
|
|
871
|
+
...(arg === undefined ? {} : { argument: arg }),
|
|
872
|
+
}),
|
|
873
|
+
evaluateHandle: (fn, arg) => element?.evaluateHandle(fn, arg) ?? unsupported("jsHandle", "evaluateHandle(value)"),
|
|
874
|
+
dispose: async () => {
|
|
875
|
+
if (result.token)
|
|
876
|
+
await state.execute([], "untag", { token: result.token });
|
|
877
|
+
},
|
|
878
|
+
$: (selector) => element?.$(selector) ?? null,
|
|
879
|
+
$$: async (selector) => element?.$$(selector) ?? [],
|
|
880
|
+
};
|
|
881
|
+
const handle = guard("jsHandle", target);
|
|
882
|
+
handleMetadata.set(handle, { element, result, state });
|
|
883
|
+
return handle;
|
|
884
|
+
};
|
|
885
|
+
let waitForNewPage;
|
|
886
|
+
const createPage = async (page) => {
|
|
887
|
+
const key = pageKey(page);
|
|
888
|
+
const existing = compatPages.get(key);
|
|
889
|
+
if (existing)
|
|
890
|
+
return existing;
|
|
891
|
+
const state = {
|
|
892
|
+
rawPage: page,
|
|
893
|
+
cachedUrl: await page.url(),
|
|
894
|
+
viewport: await page.evaluate("({ width: innerWidth, height: innerHeight })"),
|
|
895
|
+
closed: false,
|
|
896
|
+
execute: async (plan, operation, extra = {}) => {
|
|
897
|
+
const result = await page.evaluate(buildQueryEvaluationExpression({ plan, operation, ...extra }));
|
|
898
|
+
if (result.error) {
|
|
899
|
+
const error = new Error(result.error.message);
|
|
900
|
+
error.name = result.error.name;
|
|
901
|
+
if (result.error.stack)
|
|
902
|
+
error.stack = result.error.stack;
|
|
903
|
+
throw error;
|
|
904
|
+
}
|
|
905
|
+
return result;
|
|
906
|
+
},
|
|
907
|
+
refreshUrl: async () => {
|
|
908
|
+
state.cachedUrl = await page.url();
|
|
909
|
+
for (const candidate of await rawContext.pages())
|
|
910
|
+
await createPage(candidate);
|
|
911
|
+
},
|
|
912
|
+
};
|
|
913
|
+
const root = () => locatorProxy(new CompatLocator([], state));
|
|
914
|
+
const requestFetch = async (url, options = {}) => {
|
|
915
|
+
record("calls", "request.fetch");
|
|
916
|
+
if (rawContext.request)
|
|
917
|
+
return await rawContext.request.fetch(url, options);
|
|
918
|
+
const response = await page.evaluate(async (payload) => {
|
|
919
|
+
const result = await fetch(payload.url, payload.options);
|
|
920
|
+
return {
|
|
921
|
+
body: await result.text(),
|
|
922
|
+
headers: Object.fromEntries(result.headers.entries()),
|
|
923
|
+
ok: result.ok,
|
|
924
|
+
status: result.status,
|
|
925
|
+
statusText: result.statusText,
|
|
926
|
+
url: result.url,
|
|
927
|
+
};
|
|
928
|
+
}, { url, options });
|
|
929
|
+
const value = response;
|
|
930
|
+
return guard("apiResponse", {
|
|
931
|
+
ok: () => value.ok,
|
|
932
|
+
status: () => value.status,
|
|
933
|
+
statusText: () => value.statusText,
|
|
934
|
+
url: () => value.url,
|
|
935
|
+
headers: () => ({ ...value.headers }),
|
|
936
|
+
text: async () => value.body,
|
|
937
|
+
json: async () => JSON.parse(value.body),
|
|
938
|
+
body: async () => new TextEncoder().encode(value.body),
|
|
939
|
+
});
|
|
940
|
+
};
|
|
941
|
+
const request = guard("request", {
|
|
942
|
+
fetch: (url, options) => requestFetch(url, options),
|
|
943
|
+
get: (url, options = {}) => requestFetch(url, { ...options, method: "GET" }),
|
|
944
|
+
post: (url, options = {}) => requestFetch(url, { ...options, method: "POST" }),
|
|
945
|
+
});
|
|
946
|
+
const eventSubscriptions = new Map();
|
|
947
|
+
const routeSubscriptions = [];
|
|
948
|
+
const encodeTextBase64 = (value) => {
|
|
949
|
+
const bytes = new TextEncoder().encode(value);
|
|
950
|
+
let binary = "";
|
|
951
|
+
for (const byte of bytes)
|
|
952
|
+
binary += String.fromCharCode(byte);
|
|
953
|
+
return btoa(binary);
|
|
954
|
+
};
|
|
955
|
+
const networkRequests = new Map();
|
|
956
|
+
const requestFromEvent = (event) => {
|
|
957
|
+
const params = event.params ?? {};
|
|
958
|
+
const descriptor = (params.request ?? {});
|
|
959
|
+
const headers = (descriptor.headers ?? {});
|
|
960
|
+
const requestId = String(params.requestId ?? "");
|
|
961
|
+
const request = guard("request", {
|
|
962
|
+
url: () => String(descriptor.url ?? ""),
|
|
963
|
+
method: () => String(descriptor.method ?? "GET"),
|
|
964
|
+
headers: () => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, String(value)])),
|
|
965
|
+
postData: () => (descriptor.postData === undefined ? null : String(descriptor.postData)),
|
|
966
|
+
resourceType: () => String(params.type ?? "other").toLowerCase(),
|
|
967
|
+
isNavigationRequest: () => params.type === "Document",
|
|
968
|
+
});
|
|
969
|
+
if (requestId)
|
|
970
|
+
networkRequests.set(requestId, request);
|
|
971
|
+
return request;
|
|
972
|
+
};
|
|
973
|
+
const responseFromEvent = (event) => {
|
|
974
|
+
const params = event.params ?? {};
|
|
975
|
+
const descriptor = (params.response ?? {});
|
|
976
|
+
const headers = (descriptor.headers ?? {});
|
|
977
|
+
const request = networkRequests.get(String(params.requestId ?? ""));
|
|
978
|
+
const status = Number(descriptor.status ?? 0);
|
|
979
|
+
return guard("response", {
|
|
980
|
+
url: () => String(descriptor.url ?? ""),
|
|
981
|
+
status: () => status,
|
|
982
|
+
statusText: () => String(descriptor.statusText ?? ""),
|
|
983
|
+
ok: () => status >= 200 && status <= 299,
|
|
984
|
+
headers: () => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, String(value)])),
|
|
985
|
+
request: () => request,
|
|
986
|
+
});
|
|
987
|
+
};
|
|
988
|
+
const failedRequestFromEvent = (event) => {
|
|
989
|
+
const params = event.params ?? {};
|
|
990
|
+
const request = networkRequests.get(String(params.requestId ?? ""));
|
|
991
|
+
if (!request)
|
|
992
|
+
return requestFromEvent(event);
|
|
993
|
+
return new Proxy(request, {
|
|
994
|
+
get(target, property, receiver) {
|
|
995
|
+
if (property === "failure") {
|
|
996
|
+
return () => ({ errorText: String(params.errorText ?? "Request failed") });
|
|
997
|
+
}
|
|
998
|
+
return Reflect.get(target, property, receiver);
|
|
999
|
+
},
|
|
1000
|
+
});
|
|
1001
|
+
};
|
|
1002
|
+
const consoleMessageFromEvent = (event) => {
|
|
1003
|
+
const params = event.params ?? {};
|
|
1004
|
+
const args = Array.isArray(params.args) ? params.args : [];
|
|
1005
|
+
const text = args
|
|
1006
|
+
.map((entry) => {
|
|
1007
|
+
const value = (entry ?? {});
|
|
1008
|
+
if (value.value !== undefined)
|
|
1009
|
+
return String(value.value);
|
|
1010
|
+
if (value.description !== undefined)
|
|
1011
|
+
return String(value.description);
|
|
1012
|
+
return String(value.type ?? "");
|
|
1013
|
+
})
|
|
1014
|
+
.join(" ");
|
|
1015
|
+
return guard("consoleMessage", {
|
|
1016
|
+
type: () => String(params.type ?? "log"),
|
|
1017
|
+
text: () => text,
|
|
1018
|
+
});
|
|
1019
|
+
};
|
|
1020
|
+
const downloadFromEvent = (event) => {
|
|
1021
|
+
const params = event.params ?? {};
|
|
1022
|
+
const guid = String(params.guid ?? "");
|
|
1023
|
+
return guard("download", {
|
|
1024
|
+
url: () => String(params.url ?? ""),
|
|
1025
|
+
suggestedFilename: () => String(params.suggestedFilename ?? (guid || "download")),
|
|
1026
|
+
failure: async () => null,
|
|
1027
|
+
path: async () => null,
|
|
1028
|
+
cancel: async () => {
|
|
1029
|
+
if (guid)
|
|
1030
|
+
await page.sendCDP("Browser.cancelDownload", { guid });
|
|
1031
|
+
},
|
|
1032
|
+
saveAs: async () => unsupported("download", "saveAs"),
|
|
1033
|
+
});
|
|
1034
|
+
};
|
|
1035
|
+
const pageErrorFromEvent = (event) => {
|
|
1036
|
+
const details = (event.params?.exceptionDetails ?? {});
|
|
1037
|
+
const exception = (details.exception ?? {});
|
|
1038
|
+
const error = new Error(String(exception.description ?? exception.value ?? details.text ?? "Page error"));
|
|
1039
|
+
error.name = String(exception.className ?? "Error");
|
|
1040
|
+
return error;
|
|
1041
|
+
};
|
|
1042
|
+
const subscribeEvent = (event, listener, once) => {
|
|
1043
|
+
if (event !== "download" &&
|
|
1044
|
+
event !== "console" &&
|
|
1045
|
+
event !== "request" &&
|
|
1046
|
+
event !== "response" &&
|
|
1047
|
+
event !== "requestfailed" &&
|
|
1048
|
+
event !== "pageerror" &&
|
|
1049
|
+
event !== "framenavigated") {
|
|
1050
|
+
unsupported("page", `on(${event})`);
|
|
1051
|
+
}
|
|
1052
|
+
let wrapped;
|
|
1053
|
+
wrapped = (value) => {
|
|
1054
|
+
if (once) {
|
|
1055
|
+
const subscriptions = eventSubscriptions.get(event);
|
|
1056
|
+
const subscription = subscriptions?.get(listener);
|
|
1057
|
+
subscriptions?.delete(listener);
|
|
1058
|
+
if (subscriptions?.size === 0)
|
|
1059
|
+
eventSubscriptions.delete(event);
|
|
1060
|
+
void subscription?.then((active) => active.unsubscribe());
|
|
1061
|
+
}
|
|
1062
|
+
const facadeValue = event === "download"
|
|
1063
|
+
? downloadFromEvent(value)
|
|
1064
|
+
: event === "console"
|
|
1065
|
+
? consoleMessageFromEvent(value)
|
|
1066
|
+
: event === "request"
|
|
1067
|
+
? requestFromEvent(value)
|
|
1068
|
+
: event === "response"
|
|
1069
|
+
? responseFromEvent(value)
|
|
1070
|
+
: event === "requestfailed"
|
|
1071
|
+
? failedRequestFromEvent(value)
|
|
1072
|
+
: event === "pageerror"
|
|
1073
|
+
? pageErrorFromEvent(value)
|
|
1074
|
+
: pageProxy;
|
|
1075
|
+
return listener(facadeValue);
|
|
1076
|
+
};
|
|
1077
|
+
const primarySubscription = event === "pageerror"
|
|
1078
|
+
? page.onCDP("Runtime.exceptionThrown", wrapped)
|
|
1079
|
+
: event === "framenavigated"
|
|
1080
|
+
? page.onCDP("Page.frameNavigated", (value) => {
|
|
1081
|
+
const frame = (value.params?.frame ?? {});
|
|
1082
|
+
if (frame.parentId === undefined)
|
|
1083
|
+
return wrapped(value);
|
|
1084
|
+
})
|
|
1085
|
+
: page.on(event, wrapped);
|
|
1086
|
+
const requestSubscription = event === "response" || event === "requestfailed"
|
|
1087
|
+
? page.onCDP("Network.requestWillBeSent", requestFromEvent)
|
|
1088
|
+
: undefined;
|
|
1089
|
+
const subscription = requestSubscription
|
|
1090
|
+
? Promise.all([primarySubscription, requestSubscription]).then(([primary, requests]) => ({
|
|
1091
|
+
unsubscribe: async () => {
|
|
1092
|
+
await Promise.all([primary.unsubscribe(), requests.unsubscribe()]);
|
|
1093
|
+
},
|
|
1094
|
+
}))
|
|
1095
|
+
: primarySubscription;
|
|
1096
|
+
const subscriptions = eventSubscriptions.get(event) ?? new Map();
|
|
1097
|
+
subscriptions.set(listener, subscription);
|
|
1098
|
+
eventSubscriptions.set(event, subscriptions);
|
|
1099
|
+
return subscription;
|
|
1100
|
+
};
|
|
1101
|
+
const waitForResponse = async (predicate, options = {}) => {
|
|
1102
|
+
record("calls", "page.waitForResponse");
|
|
1103
|
+
const timeout = options.timeout ?? 30_000;
|
|
1104
|
+
return await new Promise((resolve, reject) => {
|
|
1105
|
+
let settled = false;
|
|
1106
|
+
let subscription;
|
|
1107
|
+
const finish = (result, error) => {
|
|
1108
|
+
if (settled)
|
|
1109
|
+
return;
|
|
1110
|
+
settled = true;
|
|
1111
|
+
clearTimeout(timer);
|
|
1112
|
+
const subscriptions = eventSubscriptions.get("response");
|
|
1113
|
+
subscriptions?.delete(listener);
|
|
1114
|
+
if (subscriptions?.size === 0)
|
|
1115
|
+
eventSubscriptions.delete("response");
|
|
1116
|
+
void subscription
|
|
1117
|
+
.then((active) => active.unsubscribe())
|
|
1118
|
+
.catch(() => undefined);
|
|
1119
|
+
if (error)
|
|
1120
|
+
reject(error);
|
|
1121
|
+
else
|
|
1122
|
+
resolve(result);
|
|
1123
|
+
};
|
|
1124
|
+
const listener = async (response) => {
|
|
1125
|
+
try {
|
|
1126
|
+
if (predicate instanceof RegExp)
|
|
1127
|
+
predicate.lastIndex = 0;
|
|
1128
|
+
const matched = typeof predicate === "function"
|
|
1129
|
+
? await predicate(response)
|
|
1130
|
+
: predicate instanceof RegExp
|
|
1131
|
+
? predicate.test(response.url())
|
|
1132
|
+
: response.url() === predicate;
|
|
1133
|
+
if (matched)
|
|
1134
|
+
finish(response);
|
|
1135
|
+
}
|
|
1136
|
+
catch (error) {
|
|
1137
|
+
finish(undefined, error instanceof Error ? error : new Error(String(error)));
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
const timer = setTimeout(() => finish(undefined, new Error(`page.waitForResponse: timed out after ${timeout}ms`)), timeout);
|
|
1141
|
+
subscription = subscribeEvent("response", listener, false);
|
|
1142
|
+
void subscription.catch((error) => finish(undefined, error instanceof Error ? error : new Error(String(error))));
|
|
1143
|
+
});
|
|
1144
|
+
};
|
|
1145
|
+
const waitForPageEvent = async (event, options = {}) => {
|
|
1146
|
+
if (event === "popup")
|
|
1147
|
+
return await waitForNewPage(options);
|
|
1148
|
+
if (event !== "download")
|
|
1149
|
+
return unsupported("page", `waitForEvent(${event})`);
|
|
1150
|
+
await page.sendCDP("Page.enable").catch(() => undefined);
|
|
1151
|
+
await page
|
|
1152
|
+
.sendCDP("Page.setDownloadBehavior", { behavior: "allow" })
|
|
1153
|
+
.catch(() => undefined);
|
|
1154
|
+
const timeout = options.timeout ?? 30_000;
|
|
1155
|
+
return await new Promise((resolve, reject) => {
|
|
1156
|
+
let subscription;
|
|
1157
|
+
const listener = (download) => {
|
|
1158
|
+
clearTimeout(timer);
|
|
1159
|
+
resolve(download);
|
|
1160
|
+
};
|
|
1161
|
+
const timer = setTimeout(() => {
|
|
1162
|
+
const subscriptions = eventSubscriptions.get(event);
|
|
1163
|
+
subscriptions?.delete(listener);
|
|
1164
|
+
if (subscriptions?.size === 0)
|
|
1165
|
+
eventSubscriptions.delete(event);
|
|
1166
|
+
void subscription.then((active) => active.unsubscribe());
|
|
1167
|
+
reject(new Error(`page.waitForEvent(download): timed out after ${timeout}ms`));
|
|
1168
|
+
}, timeout);
|
|
1169
|
+
subscription = subscribeEvent("download", listener, true);
|
|
1170
|
+
});
|
|
1171
|
+
};
|
|
1172
|
+
const pageObject = {
|
|
1173
|
+
goto: async (url, options) => {
|
|
1174
|
+
record("calls", "page.goto");
|
|
1175
|
+
const response = await page.goto(url, options);
|
|
1176
|
+
await state.refreshUrl();
|
|
1177
|
+
return response;
|
|
1178
|
+
},
|
|
1179
|
+
reload: async (options) => {
|
|
1180
|
+
record("calls", "page.reload");
|
|
1181
|
+
const response = await page.reload(options);
|
|
1182
|
+
await state.refreshUrl();
|
|
1183
|
+
return response;
|
|
1184
|
+
},
|
|
1185
|
+
goBack: async (options) => {
|
|
1186
|
+
record("calls", "page.goBack");
|
|
1187
|
+
const response = await page.goBack(options);
|
|
1188
|
+
await state.refreshUrl();
|
|
1189
|
+
return response;
|
|
1190
|
+
},
|
|
1191
|
+
goForward: async (options) => {
|
|
1192
|
+
record("calls", "page.goForward");
|
|
1193
|
+
const response = await page.goForward(options);
|
|
1194
|
+
await state.refreshUrl();
|
|
1195
|
+
return response;
|
|
1196
|
+
},
|
|
1197
|
+
url: () => {
|
|
1198
|
+
record("calls", "page.url");
|
|
1199
|
+
return state.cachedUrl;
|
|
1200
|
+
},
|
|
1201
|
+
title: () => {
|
|
1202
|
+
record("calls", "page.title");
|
|
1203
|
+
return page.title();
|
|
1204
|
+
},
|
|
1205
|
+
content: async () => {
|
|
1206
|
+
record("calls", "page.content");
|
|
1207
|
+
return (await state.execute([], "pageContent")).value;
|
|
1208
|
+
},
|
|
1209
|
+
evaluate: (fn, arg) => {
|
|
1210
|
+
record("calls", "page.evaluate");
|
|
1211
|
+
const metadata = arg && typeof arg === "object" ? handleMetadata.get(arg) : undefined;
|
|
1212
|
+
if (metadata?.element && typeof fn === "function") {
|
|
1213
|
+
return metadata.element.evaluate(fn);
|
|
1214
|
+
}
|
|
1215
|
+
return page.evaluate(fn, arg);
|
|
1216
|
+
},
|
|
1217
|
+
evaluateHandle: async (fn, arg) => {
|
|
1218
|
+
record("calls", "page.evaluateHandle");
|
|
1219
|
+
const metadata = arg && typeof arg === "object" ? handleMetadata.get(arg) : undefined;
|
|
1220
|
+
if (metadata?.element)
|
|
1221
|
+
return metadata.element.evaluateHandle(fn);
|
|
1222
|
+
const token = crypto.randomUUID();
|
|
1223
|
+
return jsHandle(await state.execute([], "pageEvaluateHandle", {
|
|
1224
|
+
functionSource: Function.prototype.toString.call(fn),
|
|
1225
|
+
...(arg === undefined ? {} : { argument: arg }),
|
|
1226
|
+
token,
|
|
1227
|
+
}), state);
|
|
1228
|
+
},
|
|
1229
|
+
locator: (selector, options = {}) => {
|
|
1230
|
+
record("calls", "page.locator");
|
|
1231
|
+
const located = locatorProxy(new CompatLocator([{ kind: "selector", value: selector }], state));
|
|
1232
|
+
return Object.keys(options).length > 0 ? located.filter(options) : located;
|
|
1233
|
+
},
|
|
1234
|
+
getByText: (value, options) => {
|
|
1235
|
+
record("calls", "page.getByText");
|
|
1236
|
+
return root().getByText(value, options);
|
|
1237
|
+
},
|
|
1238
|
+
getByRole: (role, options) => {
|
|
1239
|
+
record("calls", "page.getByRole");
|
|
1240
|
+
return root().getByRole(role, options);
|
|
1241
|
+
},
|
|
1242
|
+
getByLabel: (value, options) => {
|
|
1243
|
+
record("calls", "page.getByLabel");
|
|
1244
|
+
return root().getByLabel(value, options);
|
|
1245
|
+
},
|
|
1246
|
+
getByPlaceholder: (value, options) => root().getByPlaceholder(value, options),
|
|
1247
|
+
getByAltText: (value, options) => root().getByAltText(value, options),
|
|
1248
|
+
getByTitle: (value, options) => root().getByTitle(value, options),
|
|
1249
|
+
getByTestId: (value) => root().getByTestId(value),
|
|
1250
|
+
$: async (selector) => {
|
|
1251
|
+
record("calls", "page.$");
|
|
1252
|
+
const locator = (await pageObject.locator(selector).all())[0];
|
|
1253
|
+
return locator ? markElementHandle(locator, state) : null;
|
|
1254
|
+
},
|
|
1255
|
+
$$: async (selector) => {
|
|
1256
|
+
record("calls", "page.$$");
|
|
1257
|
+
return (await pageObject.locator(selector).all()).map((locator) => markElementHandle(locator, state));
|
|
1258
|
+
},
|
|
1259
|
+
$x: async (expression) => {
|
|
1260
|
+
record("calls", "page.$x");
|
|
1261
|
+
return (await pageObject.locator(`xpath=${expression}`).all()).map((locator) => markElementHandle(locator, state));
|
|
1262
|
+
},
|
|
1263
|
+
$eval: (selector, fn, arg) => {
|
|
1264
|
+
record("calls", "page.$eval");
|
|
1265
|
+
return pageObject.locator(selector).first().evaluate(fn, arg);
|
|
1266
|
+
},
|
|
1267
|
+
$$eval: (selector, fn, arg) => {
|
|
1268
|
+
record("calls", "page.$$eval");
|
|
1269
|
+
return pageObject.locator(selector).evaluateAll(fn, arg);
|
|
1270
|
+
},
|
|
1271
|
+
click: (selector, options) => pageObject.locator(selector).click(options),
|
|
1272
|
+
hover: (selector, options) => pageObject.locator(selector).hover(options),
|
|
1273
|
+
fill: (selector, value, options) => pageObject.locator(selector).fill(value, options),
|
|
1274
|
+
type: (selector, value, options) => pageObject.locator(selector).type(value, options),
|
|
1275
|
+
press: (selector, key, options) => pageObject.locator(selector).press(key, options),
|
|
1276
|
+
focus: (selector) => pageObject.locator(selector).focus(),
|
|
1277
|
+
check: (selector, options) => pageObject.locator(selector).check(options),
|
|
1278
|
+
uncheck: (selector, options) => pageObject.locator(selector).uncheck(options),
|
|
1279
|
+
selectOption: (selector, values, options) => pageObject.locator(selector).selectOption(values, options),
|
|
1280
|
+
getAttribute: (selector, name) => pageObject.locator(selector).getAttribute(name),
|
|
1281
|
+
textContent: (selector) => pageObject.locator(selector).textContent(),
|
|
1282
|
+
innerText: (selector) => pageObject.locator(selector).innerText(),
|
|
1283
|
+
inputValue: (selector) => pageObject.locator(selector).inputValue(),
|
|
1284
|
+
isVisible: (selector) => pageObject.locator(selector).isVisible(),
|
|
1285
|
+
isChecked: (selector) => pageObject.locator(selector).isChecked(),
|
|
1286
|
+
isDisabled: (selector) => pageObject.locator(selector).isDisabled(),
|
|
1287
|
+
isEnabled: (selector) => pageObject.locator(selector).isEnabled(),
|
|
1288
|
+
screenshot: async (options = {}) => {
|
|
1289
|
+
record("calls", "page.screenshot");
|
|
1290
|
+
const { path: requestedPath, ...supported } = options;
|
|
1291
|
+
const inferredType = supported.type === undefined &&
|
|
1292
|
+
typeof requestedPath === "string" &&
|
|
1293
|
+
/\.jpe?g$/iu.test(requestedPath)
|
|
1294
|
+
? "jpeg"
|
|
1295
|
+
: undefined;
|
|
1296
|
+
const bytes = await page.screenshot({
|
|
1297
|
+
...supported,
|
|
1298
|
+
...(inferredType ? { type: inferredType } : {}),
|
|
1299
|
+
});
|
|
1300
|
+
if (typeof requestedPath === "string") {
|
|
1301
|
+
screenshotArtifacts.push({ path: requestedPath, base64: encodeBase64(bytes) });
|
|
1302
|
+
}
|
|
1303
|
+
return bytes;
|
|
1304
|
+
},
|
|
1305
|
+
waitForTimeout: async (ms) => {
|
|
1306
|
+
record("calls", "page.waitForTimeout");
|
|
1307
|
+
await page.waitForTimeout(ms);
|
|
1308
|
+
for (const candidate of await rawContext.pages())
|
|
1309
|
+
await createPage(candidate);
|
|
1310
|
+
},
|
|
1311
|
+
waitForLoadState: (state = "load", options = {}) => {
|
|
1312
|
+
record("calls", "page.waitForLoadState");
|
|
1313
|
+
return page.waitForLoadState(state, options.timeout);
|
|
1314
|
+
},
|
|
1315
|
+
waitForSelector: async (selector, options) => {
|
|
1316
|
+
record("calls", "page.waitForSelector");
|
|
1317
|
+
return (await page.waitForSelector(selector, options))
|
|
1318
|
+
? pageObject.locator(selector).first()
|
|
1319
|
+
: null;
|
|
1320
|
+
},
|
|
1321
|
+
waitForNavigation: async (options = {}) => {
|
|
1322
|
+
record("calls", "page.waitForNavigation");
|
|
1323
|
+
const before = state.cachedUrl;
|
|
1324
|
+
const deadline = Date.now() + (options.timeout ?? 30_000);
|
|
1325
|
+
while (Date.now() < deadline) {
|
|
1326
|
+
const next = await page.url();
|
|
1327
|
+
if (next !== before) {
|
|
1328
|
+
state.cachedUrl = next;
|
|
1329
|
+
if (options.waitUntil)
|
|
1330
|
+
await page.waitForLoadState(options.waitUntil, options.timeout);
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1333
|
+
await page.waitForTimeout(50);
|
|
1334
|
+
}
|
|
1335
|
+
throw new Error("page.waitForNavigation: timed out");
|
|
1336
|
+
},
|
|
1337
|
+
waitForResponse,
|
|
1338
|
+
waitForEvent: waitForPageEvent,
|
|
1339
|
+
setViewportSize: async (size) => {
|
|
1340
|
+
record("calls", "page.setViewportSize");
|
|
1341
|
+
state.viewport = { width: size.width, height: size.height };
|
|
1342
|
+
await page.setViewportSize(size.width, size.height);
|
|
1343
|
+
},
|
|
1344
|
+
viewportSize: () => {
|
|
1345
|
+
record("calls", "page.viewportSize");
|
|
1346
|
+
return state.viewport;
|
|
1347
|
+
},
|
|
1348
|
+
setExtraHTTPHeaders: (headers) => {
|
|
1349
|
+
record("calls", "page.setExtraHTTPHeaders");
|
|
1350
|
+
return page.setExtraHTTPHeaders(headers);
|
|
1351
|
+
},
|
|
1352
|
+
addInitScript: (script, arg) => {
|
|
1353
|
+
record("calls", "page.addInitScript");
|
|
1354
|
+
return page.addInitScript(script, arg);
|
|
1355
|
+
},
|
|
1356
|
+
close: async () => {
|
|
1357
|
+
record("calls", "page.close");
|
|
1358
|
+
await page.close();
|
|
1359
|
+
state.closed = true;
|
|
1360
|
+
closedPages.add(key);
|
|
1361
|
+
},
|
|
1362
|
+
isClosed: () => state.closed,
|
|
1363
|
+
name: () => "",
|
|
1364
|
+
context: () => context,
|
|
1365
|
+
bringToFront: async () => {
|
|
1366
|
+
record("calls", "page.bringToFront");
|
|
1367
|
+
await rawContext.setActivePage(page);
|
|
1368
|
+
},
|
|
1369
|
+
frames: () => {
|
|
1370
|
+
record("calls", "page.frames");
|
|
1371
|
+
return [pageProxy];
|
|
1372
|
+
},
|
|
1373
|
+
on: (event, listener) => {
|
|
1374
|
+
record("calls", "page.on");
|
|
1375
|
+
subscribeEvent(event, listener, false);
|
|
1376
|
+
return pageProxy;
|
|
1377
|
+
},
|
|
1378
|
+
once: (event, listener) => {
|
|
1379
|
+
record("calls", "page.once");
|
|
1380
|
+
subscribeEvent(event, listener, true);
|
|
1381
|
+
return pageProxy;
|
|
1382
|
+
},
|
|
1383
|
+
off: (event, listener) => {
|
|
1384
|
+
record("calls", "page.off");
|
|
1385
|
+
const subscriptions = eventSubscriptions.get(event);
|
|
1386
|
+
const subscription = subscriptions?.get(listener);
|
|
1387
|
+
subscriptions?.delete(listener);
|
|
1388
|
+
if (subscriptions?.size === 0)
|
|
1389
|
+
eventSubscriptions.delete(event);
|
|
1390
|
+
void subscription?.then((active) => active.unsubscribe());
|
|
1391
|
+
return pageProxy;
|
|
1392
|
+
},
|
|
1393
|
+
removeListener: (event, listener) => {
|
|
1394
|
+
record("calls", "page.removeListener");
|
|
1395
|
+
const subscriptions = eventSubscriptions.get(event);
|
|
1396
|
+
const subscription = subscriptions?.get(listener);
|
|
1397
|
+
subscriptions?.delete(listener);
|
|
1398
|
+
if (subscriptions?.size === 0)
|
|
1399
|
+
eventSubscriptions.delete(event);
|
|
1400
|
+
void subscription?.then((active) => active.unsubscribe());
|
|
1401
|
+
return pageProxy;
|
|
1402
|
+
},
|
|
1403
|
+
route: async (pattern, handler) => {
|
|
1404
|
+
record("calls", "page.route");
|
|
1405
|
+
const urlPattern = typeof pattern === "string" ? pattern : "*";
|
|
1406
|
+
await page.sendCDP("Fetch.enable", { patterns: [{ urlPattern }] });
|
|
1407
|
+
const subscription = page.onCDP("Fetch.requestPaused", async (event) => {
|
|
1408
|
+
const params = event.params ?? {};
|
|
1409
|
+
const requestId = String(params.requestId ?? "");
|
|
1410
|
+
const cdpRequest = (params.request ?? {});
|
|
1411
|
+
let handled = false;
|
|
1412
|
+
const requestHeaders = (cdpRequest.headers ?? {});
|
|
1413
|
+
const route = {
|
|
1414
|
+
request: () => ({
|
|
1415
|
+
url: () => String(cdpRequest.url ?? ""),
|
|
1416
|
+
method: () => String(cdpRequest.method ?? "GET"),
|
|
1417
|
+
headers: () => ({ ...requestHeaders }),
|
|
1418
|
+
postData: () => cdpRequest.postData === undefined ? null : String(cdpRequest.postData),
|
|
1419
|
+
}),
|
|
1420
|
+
continue: async (options = {}) => {
|
|
1421
|
+
handled = true;
|
|
1422
|
+
const headers = options.headers;
|
|
1423
|
+
await page.sendCDP("Fetch.continueRequest", {
|
|
1424
|
+
requestId,
|
|
1425
|
+
...(headers
|
|
1426
|
+
? { headers: Object.entries(headers).map(([name, value]) => ({ name, value })) }
|
|
1427
|
+
: {}),
|
|
1428
|
+
...(typeof options.url === "string" ? { url: options.url } : {}),
|
|
1429
|
+
...(typeof options.method === "string" ? { method: options.method } : {}),
|
|
1430
|
+
...(typeof options.postData === "string"
|
|
1431
|
+
? { postData: encodeTextBase64(options.postData) }
|
|
1432
|
+
: {}),
|
|
1433
|
+
});
|
|
1434
|
+
},
|
|
1435
|
+
abort: async (errorReason = "Failed") => {
|
|
1436
|
+
handled = true;
|
|
1437
|
+
await page.sendCDP("Fetch.failRequest", { requestId, errorReason });
|
|
1438
|
+
},
|
|
1439
|
+
fulfill: async (options = {}) => {
|
|
1440
|
+
handled = true;
|
|
1441
|
+
const headers = { ...(options.headers ?? {}) };
|
|
1442
|
+
const responseBody = options.json === undefined
|
|
1443
|
+
? typeof options.body === "string"
|
|
1444
|
+
? options.body
|
|
1445
|
+
: undefined
|
|
1446
|
+
: JSON.stringify(options.json);
|
|
1447
|
+
if (options.json !== undefined && !("content-type" in headers)) {
|
|
1448
|
+
headers["content-type"] = "application/json";
|
|
1449
|
+
}
|
|
1450
|
+
const body = responseBody === undefined ? undefined : encodeTextBase64(responseBody);
|
|
1451
|
+
await page.sendCDP("Fetch.fulfillRequest", {
|
|
1452
|
+
requestId,
|
|
1453
|
+
responseCode: typeof options.status === "number" ? options.status : 200,
|
|
1454
|
+
responseHeaders: Object.entries(headers).map(([name, value]) => ({ name, value })),
|
|
1455
|
+
...(body === undefined ? {} : { body }),
|
|
1456
|
+
});
|
|
1457
|
+
},
|
|
1458
|
+
};
|
|
1459
|
+
await handler(route);
|
|
1460
|
+
if (!handled)
|
|
1461
|
+
await route.continue();
|
|
1462
|
+
});
|
|
1463
|
+
await subscription;
|
|
1464
|
+
routeSubscriptions.push({ pattern, handler, subscription });
|
|
1465
|
+
},
|
|
1466
|
+
unroute: async (pattern, handler) => {
|
|
1467
|
+
const matches = routeSubscriptions.filter((entry) => entry.pattern === pattern && (handler === undefined || entry.handler === handler));
|
|
1468
|
+
for (const entry of matches) {
|
|
1469
|
+
routeSubscriptions.splice(routeSubscriptions.indexOf(entry), 1);
|
|
1470
|
+
await (await entry.subscription).unsubscribe();
|
|
1471
|
+
}
|
|
1472
|
+
if (routeSubscriptions.length === 0)
|
|
1473
|
+
await page.sendCDP("Fetch.disable");
|
|
1474
|
+
},
|
|
1475
|
+
request,
|
|
1476
|
+
accessibility: {
|
|
1477
|
+
snapshot: (options) => page.snapshot(options),
|
|
1478
|
+
},
|
|
1479
|
+
keyboard: {
|
|
1480
|
+
type: (text, options) => page.type(text, options),
|
|
1481
|
+
insertText: (text) => page.type(text),
|
|
1482
|
+
press: (key, options) => page.keyPress(key, options),
|
|
1483
|
+
},
|
|
1484
|
+
mouse: (() => {
|
|
1485
|
+
let x = 0;
|
|
1486
|
+
let y = 0;
|
|
1487
|
+
let down = false;
|
|
1488
|
+
return {
|
|
1489
|
+
click: (nextX, nextY, options) => page.click(nextX, nextY, options),
|
|
1490
|
+
move: async (nextX, nextY) => {
|
|
1491
|
+
x = nextX;
|
|
1492
|
+
y = nextY;
|
|
1493
|
+
await page.hover(x, y);
|
|
1494
|
+
},
|
|
1495
|
+
wheel: (deltaX, deltaY) => page.scroll(x, y, deltaX, deltaY),
|
|
1496
|
+
down: async () => {
|
|
1497
|
+
down = true;
|
|
1498
|
+
},
|
|
1499
|
+
up: async () => {
|
|
1500
|
+
if (down)
|
|
1501
|
+
await page.click(x, y);
|
|
1502
|
+
down = false;
|
|
1503
|
+
},
|
|
1504
|
+
};
|
|
1505
|
+
})(),
|
|
1506
|
+
};
|
|
1507
|
+
const pageProxy = guard("page", pageObject);
|
|
1508
|
+
pageStateMetadata.set(pageProxy, state);
|
|
1509
|
+
compatPages.set(key, pageProxy);
|
|
1510
|
+
closedPages.delete(key);
|
|
1511
|
+
for (const [listener, once] of contextPageListeners) {
|
|
1512
|
+
listener(pageProxy);
|
|
1513
|
+
if (once)
|
|
1514
|
+
contextPageListeners.delete(listener);
|
|
1515
|
+
}
|
|
1516
|
+
return pageProxy;
|
|
1517
|
+
};
|
|
1518
|
+
const initialPage = await createPage(stagehand.page);
|
|
1519
|
+
const contextRequest = initialPage.request;
|
|
1520
|
+
const initialRawPages = await rawContext.pages();
|
|
1521
|
+
for (const page of initialRawPages)
|
|
1522
|
+
await createPage(page);
|
|
1523
|
+
waitForNewPage = async (options = {}) => {
|
|
1524
|
+
const existing = new Set(compatPages.keys());
|
|
1525
|
+
const timeout = options.timeout ?? 30_000;
|
|
1526
|
+
const deadline = Date.now() + timeout;
|
|
1527
|
+
do {
|
|
1528
|
+
for (const candidate of await rawContext.pages()) {
|
|
1529
|
+
const key = pageKey(candidate);
|
|
1530
|
+
if (!existing.has(key))
|
|
1531
|
+
return await createPage(candidate);
|
|
1532
|
+
}
|
|
1533
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1534
|
+
} while (Date.now() < deadline);
|
|
1535
|
+
throw new Error(`context.waitForEvent(page): timed out after ${timeout}ms`);
|
|
1536
|
+
};
|
|
1537
|
+
const contextObject = {
|
|
1538
|
+
pages: () => {
|
|
1539
|
+
record("calls", "context.pages");
|
|
1540
|
+
return [...compatPages.entries()]
|
|
1541
|
+
.filter(([key]) => !closedPages.has(key))
|
|
1542
|
+
.map(([, page]) => page);
|
|
1543
|
+
},
|
|
1544
|
+
newPage: async () => {
|
|
1545
|
+
record("calls", "context.newPage");
|
|
1546
|
+
return await createPage(await rawContext.newPage());
|
|
1547
|
+
},
|
|
1548
|
+
cookies: (urls) => {
|
|
1549
|
+
record("calls", "context.cookies");
|
|
1550
|
+
return rawContext.cookies(urls);
|
|
1551
|
+
},
|
|
1552
|
+
addCookies: (cookies) => rawContext.addCookies(cookies),
|
|
1553
|
+
clearCookies: (options) => {
|
|
1554
|
+
record("calls", "context.clearCookies");
|
|
1555
|
+
return rawContext.clearCookies(options);
|
|
1556
|
+
},
|
|
1557
|
+
setExtraHTTPHeaders: (headers) => rawContext.setExtraHTTPHeaders(headers),
|
|
1558
|
+
addInitScript: (script, arg) => {
|
|
1559
|
+
record("calls", "context.addInitScript");
|
|
1560
|
+
return rawContext.addInitScript(script, arg);
|
|
1561
|
+
},
|
|
1562
|
+
waitForEvent: (event, options) => {
|
|
1563
|
+
if (event !== "page")
|
|
1564
|
+
return unsupported("context", `waitForEvent(${event})`);
|
|
1565
|
+
return waitForNewPage(options);
|
|
1566
|
+
},
|
|
1567
|
+
on: (event, listener) => {
|
|
1568
|
+
record("calls", "context.on");
|
|
1569
|
+
if (event !== "page")
|
|
1570
|
+
return unsupported("context", `on(${event})`);
|
|
1571
|
+
contextPageListeners.set(listener, false);
|
|
1572
|
+
return context;
|
|
1573
|
+
},
|
|
1574
|
+
once: (event, listener) => {
|
|
1575
|
+
record("calls", "context.once");
|
|
1576
|
+
if (event !== "page")
|
|
1577
|
+
return unsupported("context", `once(${event})`);
|
|
1578
|
+
contextPageListeners.set(listener, true);
|
|
1579
|
+
return context;
|
|
1580
|
+
},
|
|
1581
|
+
off: (event, listener) => {
|
|
1582
|
+
record("calls", "context.off");
|
|
1583
|
+
if (event !== "page")
|
|
1584
|
+
return unsupported("context", `off(${event})`);
|
|
1585
|
+
contextPageListeners.delete(listener);
|
|
1586
|
+
return context;
|
|
1587
|
+
},
|
|
1588
|
+
removeListener: (event, listener) => {
|
|
1589
|
+
record("calls", "context.removeListener");
|
|
1590
|
+
if (event !== "page")
|
|
1591
|
+
return unsupported("context", `removeListener(${event})`);
|
|
1592
|
+
contextPageListeners.delete(listener);
|
|
1593
|
+
return context;
|
|
1594
|
+
},
|
|
1595
|
+
newCDPSession: async (compatPage) => {
|
|
1596
|
+
record("calls", "context.newCDPSession");
|
|
1597
|
+
const target = pageStateMetadata.get(compatPage);
|
|
1598
|
+
if (!target)
|
|
1599
|
+
throw new Error("context.newCDPSession: page does not belong to this context");
|
|
1600
|
+
const subscriptions = [];
|
|
1601
|
+
return guard("cdpSession", {
|
|
1602
|
+
send: (method, params) => target.rawPage.sendCDP(method, params),
|
|
1603
|
+
on: (method, listener) => {
|
|
1604
|
+
subscriptions.push(target.rawPage.onCDP(method, (event) => listener(event.params ?? {})));
|
|
1605
|
+
},
|
|
1606
|
+
detach: async () => {
|
|
1607
|
+
await Promise.all(subscriptions.map(async (subscription) => (await subscription).unsubscribe()));
|
|
1608
|
+
},
|
|
1609
|
+
});
|
|
1610
|
+
},
|
|
1611
|
+
request: contextRequest,
|
|
1612
|
+
};
|
|
1613
|
+
const context = guard("context", contextObject);
|
|
1614
|
+
const browser = guard("browser", {
|
|
1615
|
+
contexts: () => [context],
|
|
1616
|
+
isConnected: () => !closeRequested,
|
|
1617
|
+
// Do not close Chrome from inside experimentalBatch — the callback is
|
|
1618
|
+
// running in that browser. Host-side run() reads closeRequested() and
|
|
1619
|
+
// tears down Stagehand + the keep-alive session after the batch returns.
|
|
1620
|
+
close: async () => {
|
|
1621
|
+
record("calls", "browser.close");
|
|
1622
|
+
closeRequested = true;
|
|
1623
|
+
},
|
|
1624
|
+
// Stagehand v4 exposes one attached context. Returning that context preserves
|
|
1625
|
+
// Playwright-shaped control flow without pretending an isolated context exists.
|
|
1626
|
+
newContext: async () => {
|
|
1627
|
+
record("calls", "browser.newContext");
|
|
1628
|
+
return context;
|
|
1629
|
+
},
|
|
1630
|
+
newPage: () => contextObject.newPage(),
|
|
1631
|
+
});
|
|
1632
|
+
return {
|
|
1633
|
+
page: initialPage,
|
|
1634
|
+
context,
|
|
1635
|
+
browser,
|
|
1636
|
+
telemetry: () => ({ calls: { ...stats.calls }, misses: { ...stats.misses } }),
|
|
1637
|
+
artifacts: () => screenshotArtifacts.map((artifact) => ({ ...artifact })),
|
|
1638
|
+
closeRequested: () => closeRequested,
|
|
1639
|
+
};
|
|
1640
|
+
}
|