@agenticmail/enterprise 0.5.78 → 0.5.80

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.
Files changed (101) hide show
  1. package/dist/chunk-7MILGDAA.js +2191 -0
  2. package/dist/chunk-7RNT4O5T.js +15198 -0
  3. package/dist/chunk-AGFOJCSB.js +2191 -0
  4. package/dist/chunk-F4GSFCM3.js +898 -0
  5. package/dist/chunk-GWUIYH7I.js +15035 -0
  6. package/dist/chunk-PZA7YOJE.js +898 -0
  7. package/dist/chunk-Q3V7VZFQ.js +2191 -0
  8. package/dist/chunk-RRFB6G6M.js +15198 -0
  9. package/dist/chunk-VX3VFMVB.js +409 -0
  10. package/dist/chunk-WRPZCOWC.js +898 -0
  11. package/dist/cli.js +1 -1
  12. package/dist/dashboard/pages/agent-detail.js +313 -1
  13. package/dist/index.js +3 -3
  14. package/dist/pw-ai-KPETTB25.js +2212 -0
  15. package/dist/routes-PDHMCIXU.js +6676 -0
  16. package/dist/runtime-7HW4GX5L.js +48 -0
  17. package/dist/runtime-GYVO3NF3.js +47 -0
  18. package/dist/runtime-XXDCZZIK.js +48 -0
  19. package/dist/server-FMP4BFGW.js +12 -0
  20. package/dist/server-JRHDUNII.js +12 -0
  21. package/dist/server-VNW6G4GB.js +12 -0
  22. package/dist/setup-AANLREEL.js +20 -0
  23. package/dist/setup-O5FPRLK4.js +20 -0
  24. package/dist/setup-S4Z4PPIJ.js +20 -0
  25. package/package.json +15 -2
  26. package/src/agent-tools/common.ts +25 -0
  27. package/src/agent-tools/index.ts +4 -0
  28. package/src/agent-tools/schema/typebox.ts +25 -0
  29. package/src/agent-tools/tools/browser-tool.schema.ts +112 -0
  30. package/src/agent-tools/tools/browser-tool.ts +388 -0
  31. package/src/agent-tools/tools/gateway.ts +126 -0
  32. package/src/agent-tools/tools/nodes-utils.ts +80 -0
  33. package/src/browser/bridge-auth-registry.ts +34 -0
  34. package/src/browser/bridge-server.ts +93 -0
  35. package/src/browser/cdp.helpers.ts +180 -0
  36. package/src/browser/cdp.ts +466 -0
  37. package/src/browser/chrome.executables.ts +625 -0
  38. package/src/browser/chrome.profile-decoration.ts +198 -0
  39. package/src/browser/chrome.ts +349 -0
  40. package/src/browser/client-actions-core.ts +259 -0
  41. package/src/browser/client-actions-observe.ts +184 -0
  42. package/src/browser/client-actions-state.ts +284 -0
  43. package/src/browser/client-actions-types.ts +16 -0
  44. package/src/browser/client-actions-url.ts +11 -0
  45. package/src/browser/client-actions.ts +4 -0
  46. package/src/browser/client-fetch.ts +253 -0
  47. package/src/browser/client.ts +337 -0
  48. package/src/browser/config.ts +296 -0
  49. package/src/browser/constants.ts +8 -0
  50. package/src/browser/control-auth.ts +94 -0
  51. package/src/browser/control-service.ts +81 -0
  52. package/src/browser/csrf.ts +87 -0
  53. package/src/browser/enterprise-compat.ts +518 -0
  54. package/src/browser/extension-relay.ts +834 -0
  55. package/src/browser/http-auth.ts +63 -0
  56. package/src/browser/navigation-guard.ts +50 -0
  57. package/src/browser/paths.ts +49 -0
  58. package/src/browser/profiles-service.ts +187 -0
  59. package/src/browser/profiles.ts +113 -0
  60. package/src/browser/proxy-files.ts +41 -0
  61. package/src/browser/pw-ai-module.ts +52 -0
  62. package/src/browser/pw-ai-state.ts +9 -0
  63. package/src/browser/pw-ai.ts +65 -0
  64. package/src/browser/pw-role-snapshot.ts +434 -0
  65. package/src/browser/pw-session.ts +810 -0
  66. package/src/browser/pw-tools-core.activity.ts +68 -0
  67. package/src/browser/pw-tools-core.downloads.ts +281 -0
  68. package/src/browser/pw-tools-core.interactions.ts +646 -0
  69. package/src/browser/pw-tools-core.responses.ts +124 -0
  70. package/src/browser/pw-tools-core.shared.ts +70 -0
  71. package/src/browser/pw-tools-core.snapshot.ts +213 -0
  72. package/src/browser/pw-tools-core.state.ts +209 -0
  73. package/src/browser/pw-tools-core.storage.ts +128 -0
  74. package/src/browser/pw-tools-core.trace.ts +37 -0
  75. package/src/browser/pw-tools-core.ts +8 -0
  76. package/src/browser/resolved-config-refresh.ts +59 -0
  77. package/src/browser/routes/agent.act.shared.ts +52 -0
  78. package/src/browser/routes/agent.act.ts +575 -0
  79. package/src/browser/routes/agent.debug.ts +149 -0
  80. package/src/browser/routes/agent.shared.ts +143 -0
  81. package/src/browser/routes/agent.snapshot.ts +333 -0
  82. package/src/browser/routes/agent.storage.ts +451 -0
  83. package/src/browser/routes/agent.ts +13 -0
  84. package/src/browser/routes/basic.ts +202 -0
  85. package/src/browser/routes/dispatcher.ts +126 -0
  86. package/src/browser/routes/index.ts +11 -0
  87. package/src/browser/routes/path-output.ts +1 -0
  88. package/src/browser/routes/tabs.ts +217 -0
  89. package/src/browser/routes/types.ts +26 -0
  90. package/src/browser/routes/utils.ts +73 -0
  91. package/src/browser/screenshot.ts +54 -0
  92. package/src/browser/server-context.ts +688 -0
  93. package/src/browser/server-context.types.ts +65 -0
  94. package/src/browser/server-lifecycle.ts +48 -0
  95. package/src/browser/server-middleware.ts +37 -0
  96. package/src/browser/server.ts +110 -0
  97. package/src/browser/target-id.ts +30 -0
  98. package/src/browser/trash.ts +21 -0
  99. package/src/dashboard/pages/agent-detail.js +313 -1
  100. package/src/engine/agent-routes.ts +46 -0
  101. package/src/security/external-content.ts +299 -0
@@ -0,0 +1,466 @@
1
+
2
+ import { appendCdpPath, fetchJson, isLoopbackHost, withCdpSocket } from "./cdp.helpers.js";
3
+ import { assertBrowserNavigationAllowed, withBrowserNavigationPolicy } from "./navigation-guard.js";
4
+ import type { SsrFPolicy } from "./enterprise-compat.js";
5
+
6
+ export { appendCdpPath, fetchJson, fetchOk, getHeadersWithAuth } from "./cdp.helpers.js";
7
+
8
+ export function normalizeCdpWsUrl(wsUrl: string, cdpUrl: string): string {
9
+ const ws = new URL(wsUrl);
10
+ const cdp = new URL(cdpUrl);
11
+ if (isLoopbackHost(ws.hostname) && !isLoopbackHost(cdp.hostname)) {
12
+ ws.hostname = cdp.hostname;
13
+ const cdpPort = cdp.port || (cdp.protocol === "https:" ? "443" : "80");
14
+ if (cdpPort) {
15
+ ws.port = cdpPort;
16
+ }
17
+ ws.protocol = cdp.protocol === "https:" ? "wss:" : "ws:";
18
+ }
19
+ if (cdp.protocol === "https:" && ws.protocol === "ws:") {
20
+ ws.protocol = "wss:";
21
+ }
22
+ if (!ws.username && !ws.password && (cdp.username || cdp.password)) {
23
+ ws.username = cdp.username;
24
+ ws.password = cdp.password;
25
+ }
26
+ for (const [key, value] of cdp.searchParams.entries()) {
27
+ if (!ws.searchParams.has(key)) {
28
+ ws.searchParams.append(key, value);
29
+ }
30
+ }
31
+ return ws.toString();
32
+ }
33
+
34
+ export async function captureScreenshotPng(opts: {
35
+ wsUrl: string;
36
+ fullPage?: boolean;
37
+ }): Promise<Buffer> {
38
+ return await captureScreenshot({
39
+ wsUrl: opts.wsUrl,
40
+ fullPage: opts.fullPage,
41
+ format: "png",
42
+ });
43
+ }
44
+
45
+ export async function captureScreenshot(opts: {
46
+ wsUrl: string;
47
+ fullPage?: boolean;
48
+ format?: "png" | "jpeg";
49
+ quality?: number; // jpeg only (0..100)
50
+ }): Promise<Buffer> {
51
+ return await withCdpSocket(opts.wsUrl, async (send) => {
52
+ await send("Page.enable");
53
+
54
+ let clip: { x: number; y: number; width: number; height: number; scale: number } | undefined;
55
+ if (opts.fullPage) {
56
+ const metrics = (await send("Page.getLayoutMetrics")) as {
57
+ cssContentSize?: { width?: number; height?: number };
58
+ contentSize?: { width?: number; height?: number };
59
+ };
60
+ const size = metrics?.cssContentSize ?? metrics?.contentSize;
61
+ const width = Number(size?.width ?? 0);
62
+ const height = Number(size?.height ?? 0);
63
+ if (width > 0 && height > 0) {
64
+ clip = { x: 0, y: 0, width, height, scale: 1 };
65
+ }
66
+ }
67
+
68
+ const format = opts.format ?? "png";
69
+ const quality =
70
+ format === "jpeg" ? Math.max(0, Math.min(100, Math.round(opts.quality ?? 85))) : undefined;
71
+
72
+ const result = (await send("Page.captureScreenshot", {
73
+ format,
74
+ ...(quality !== undefined ? { quality } : {}),
75
+ fromSurface: true,
76
+ captureBeyondViewport: true,
77
+ ...(clip ? { clip } : {}),
78
+ })) as { data?: string };
79
+
80
+ const base64 = result?.data;
81
+ if (!base64) {
82
+ throw new Error("Screenshot failed: missing data");
83
+ }
84
+ return Buffer.from(base64, "base64");
85
+ });
86
+ }
87
+
88
+ export async function createTargetViaCdp(opts: {
89
+ cdpUrl: string;
90
+ url: string;
91
+ ssrfPolicy?: SsrFPolicy;
92
+ navigationChecked?: boolean;
93
+ }): Promise<{ targetId: string }> {
94
+ if (!opts.navigationChecked) {
95
+ await assertBrowserNavigationAllowed({
96
+ url: opts.url,
97
+ ...withBrowserNavigationPolicy(opts.ssrfPolicy),
98
+ });
99
+ }
100
+
101
+ const version = await fetchJson<{ webSocketDebuggerUrl?: string }>(
102
+ appendCdpPath(opts.cdpUrl, "/json/version"),
103
+ 1500,
104
+ );
105
+ const wsUrlRaw = String(version?.webSocketDebuggerUrl ?? "").trim();
106
+ const wsUrl = wsUrlRaw ? normalizeCdpWsUrl(wsUrlRaw, opts.cdpUrl) : "";
107
+ if (!wsUrl) {
108
+ throw new Error("CDP /json/version missing webSocketDebuggerUrl");
109
+ }
110
+
111
+ return await withCdpSocket(wsUrl, async (send) => {
112
+ const created = (await send("Target.createTarget", { url: opts.url })) as {
113
+ targetId?: string;
114
+ };
115
+ const targetId = String(created?.targetId ?? "").trim();
116
+ if (!targetId) {
117
+ throw new Error("CDP Target.createTarget returned no targetId");
118
+ }
119
+ return { targetId };
120
+ });
121
+ }
122
+
123
+ export type CdpRemoteObject = {
124
+ type: string;
125
+ subtype?: string;
126
+ value?: unknown;
127
+ description?: string;
128
+ unserializableValue?: string;
129
+ preview?: unknown;
130
+ };
131
+
132
+ export type CdpExceptionDetails = {
133
+ text?: string;
134
+ lineNumber?: number;
135
+ columnNumber?: number;
136
+ exception?: CdpRemoteObject;
137
+ stackTrace?: unknown;
138
+ };
139
+
140
+ export async function evaluateJavaScript(opts: {
141
+ wsUrl: string;
142
+ expression: string;
143
+ awaitPromise?: boolean;
144
+ returnByValue?: boolean;
145
+ }): Promise<{
146
+ result: CdpRemoteObject;
147
+ exceptionDetails?: CdpExceptionDetails;
148
+ }> {
149
+ return await withCdpSocket(opts.wsUrl, async (send) => {
150
+ await send("Runtime.enable").catch(() => {});
151
+ const evaluated = (await send("Runtime.evaluate", {
152
+ expression: opts.expression,
153
+ awaitPromise: Boolean(opts.awaitPromise),
154
+ returnByValue: opts.returnByValue ?? true,
155
+ userGesture: true,
156
+ includeCommandLineAPI: true,
157
+ })) as {
158
+ result?: CdpRemoteObject;
159
+ exceptionDetails?: CdpExceptionDetails;
160
+ };
161
+
162
+ const result = evaluated?.result;
163
+ if (!result) {
164
+ throw new Error("CDP Runtime.evaluate returned no result");
165
+ }
166
+ return { result, exceptionDetails: evaluated.exceptionDetails };
167
+ });
168
+ }
169
+
170
+ export type AriaSnapshotNode = {
171
+ ref: string;
172
+ role: string;
173
+ name: string;
174
+ value?: string;
175
+ description?: string;
176
+ backendDOMNodeId?: number;
177
+ depth: number;
178
+ };
179
+
180
+ export type RawAXNode = {
181
+ nodeId?: string;
182
+ role?: { value?: string };
183
+ name?: { value?: string };
184
+ value?: { value?: string };
185
+ description?: { value?: string };
186
+ childIds?: string[];
187
+ backendDOMNodeId?: number;
188
+ };
189
+
190
+ function axValue(v: unknown): string {
191
+ if (!v || typeof v !== "object") {
192
+ return "";
193
+ }
194
+ const value = (v as { value?: unknown }).value;
195
+ if (typeof value === "string") {
196
+ return value;
197
+ }
198
+ if (typeof value === "number" || typeof value === "boolean") {
199
+ return String(value);
200
+ }
201
+ return "";
202
+ }
203
+
204
+ export function formatAriaSnapshot(nodes: RawAXNode[], limit: number): AriaSnapshotNode[] {
205
+ const byId = new Map<string, RawAXNode>();
206
+ for (const n of nodes) {
207
+ if (n.nodeId) {
208
+ byId.set(n.nodeId, n);
209
+ }
210
+ }
211
+
212
+ // Heuristic: pick a root-ish node (one that is not referenced as a child), else first.
213
+ const referenced = new Set<string>();
214
+ for (const n of nodes) {
215
+ for (const c of n.childIds ?? []) {
216
+ referenced.add(c);
217
+ }
218
+ }
219
+ const root = nodes.find((n) => n.nodeId && !referenced.has(n.nodeId)) ?? nodes[0];
220
+ if (!root?.nodeId) {
221
+ return [];
222
+ }
223
+
224
+ const out: AriaSnapshotNode[] = [];
225
+ const stack: Array<{ id: string; depth: number }> = [{ id: root.nodeId, depth: 0 }];
226
+ while (stack.length && out.length < limit) {
227
+ const popped = stack.pop();
228
+ if (!popped) {
229
+ break;
230
+ }
231
+ const { id, depth } = popped;
232
+ const n = byId.get(id);
233
+ if (!n) {
234
+ continue;
235
+ }
236
+ const role = axValue(n.role);
237
+ const name = axValue(n.name);
238
+ const value = axValue(n.value);
239
+ const description = axValue(n.description);
240
+ const ref = `ax${out.length + 1}`;
241
+ out.push({
242
+ ref,
243
+ role: role || "unknown",
244
+ name: name || "",
245
+ ...(value ? { value } : {}),
246
+ ...(description ? { description } : {}),
247
+ ...(typeof n.backendDOMNodeId === "number" ? { backendDOMNodeId: n.backendDOMNodeId } : {}),
248
+ depth,
249
+ });
250
+
251
+ const children = (n.childIds ?? []).filter((c) => byId.has(c));
252
+ for (let i = children.length - 1; i >= 0; i--) {
253
+ const child = children[i];
254
+ if (child) {
255
+ stack.push({ id: child, depth: depth + 1 });
256
+ }
257
+ }
258
+ }
259
+
260
+ return out;
261
+ }
262
+
263
+ export async function snapshotAria(opts: {
264
+ wsUrl: string;
265
+ limit?: number;
266
+ }): Promise<{ nodes: AriaSnapshotNode[] }> {
267
+ const limit = Math.max(1, Math.min(2000, Math.floor(opts.limit ?? 500)));
268
+ return await withCdpSocket(opts.wsUrl, async (send) => {
269
+ await send("Accessibility.enable").catch(() => {});
270
+ const res = (await send("Accessibility.getFullAXTree")) as {
271
+ nodes?: RawAXNode[];
272
+ };
273
+ const nodes = Array.isArray(res?.nodes) ? res.nodes : [];
274
+ return { nodes: formatAriaSnapshot(nodes, limit) };
275
+ });
276
+ }
277
+
278
+ export async function snapshotDom(opts: {
279
+ wsUrl: string;
280
+ limit?: number;
281
+ maxTextChars?: number;
282
+ }): Promise<{
283
+ nodes: DomSnapshotNode[];
284
+ }> {
285
+ const limit = Math.max(1, Math.min(5000, Math.floor(opts.limit ?? 800)));
286
+ const maxTextChars = Math.max(0, Math.min(5000, Math.floor(opts.maxTextChars ?? 220)));
287
+
288
+ const expression = `(() => {
289
+ const maxNodes = ${JSON.stringify(limit)};
290
+ const maxText = ${JSON.stringify(maxTextChars)};
291
+ const nodes = [];
292
+ const root = document.documentElement;
293
+ if (!root) return { nodes };
294
+ const stack = [{ el: root, depth: 0, parentRef: null }];
295
+ while (stack.length && nodes.length < maxNodes) {
296
+ const cur = stack.pop();
297
+ const el = cur.el;
298
+ if (!el || el.nodeType !== 1) continue;
299
+ const ref = "n" + String(nodes.length + 1);
300
+ const tag = (el.tagName || "").toLowerCase();
301
+ const id = el.id ? String(el.id) : undefined;
302
+ const className = el.className ? String(el.className).slice(0, 300) : undefined;
303
+ const role = el.getAttribute && el.getAttribute("role") ? String(el.getAttribute("role")) : undefined;
304
+ const name = el.getAttribute && el.getAttribute("aria-label") ? String(el.getAttribute("aria-label")) : undefined;
305
+ let text = "";
306
+ try { text = String(el.innerText || "").trim(); } catch {}
307
+ if (maxText && text.length > maxText) text = text.slice(0, maxText) + "…";
308
+ const href = (el.href !== undefined && el.href !== null) ? String(el.href) : undefined;
309
+ const type = (el.type !== undefined && el.type !== null) ? String(el.type) : undefined;
310
+ const value = (el.value !== undefined && el.value !== null) ? String(el.value).slice(0, 500) : undefined;
311
+ nodes.push({
312
+ ref,
313
+ parentRef: cur.parentRef,
314
+ depth: cur.depth,
315
+ tag,
316
+ ...(id ? { id } : {}),
317
+ ...(className ? { className } : {}),
318
+ ...(role ? { role } : {}),
319
+ ...(name ? { name } : {}),
320
+ ...(text ? { text } : {}),
321
+ ...(href ? { href } : {}),
322
+ ...(type ? { type } : {}),
323
+ ...(value ? { value } : {}),
324
+ });
325
+ const children = el.children ? Array.from(el.children) : [];
326
+ for (let i = children.length - 1; i >= 0; i--) {
327
+ stack.push({ el: children[i], depth: cur.depth + 1, parentRef: ref });
328
+ }
329
+ }
330
+ return { nodes };
331
+ })()`;
332
+
333
+ const evaluated = await evaluateJavaScript({
334
+ wsUrl: opts.wsUrl,
335
+ expression,
336
+ awaitPromise: true,
337
+ returnByValue: true,
338
+ });
339
+ const value = evaluated.result?.value;
340
+ if (!value || typeof value !== "object") {
341
+ return { nodes: [] };
342
+ }
343
+ const nodes = (value as { nodes?: unknown }).nodes;
344
+ return { nodes: Array.isArray(nodes) ? (nodes as DomSnapshotNode[]) : [] };
345
+ }
346
+
347
+ export type DomSnapshotNode = {
348
+ ref: string;
349
+ parentRef: string | null;
350
+ depth: number;
351
+ tag: string;
352
+ id?: string;
353
+ className?: string;
354
+ role?: string;
355
+ name?: string;
356
+ text?: string;
357
+ href?: string;
358
+ type?: string;
359
+ value?: string;
360
+ };
361
+
362
+ export async function getDomText(opts: {
363
+ wsUrl: string;
364
+ format: "html" | "text";
365
+ maxChars?: number;
366
+ selector?: string;
367
+ }): Promise<{ text: string }> {
368
+ const maxChars = Math.max(0, Math.min(5_000_000, Math.floor(opts.maxChars ?? 200_000)));
369
+ const selectorExpr = opts.selector ? JSON.stringify(opts.selector) : "null";
370
+ const expression = `(() => {
371
+ const fmt = ${JSON.stringify(opts.format)};
372
+ const max = ${JSON.stringify(maxChars)};
373
+ const sel = ${selectorExpr};
374
+ const pick = sel ? document.querySelector(sel) : null;
375
+ let out = "";
376
+ if (fmt === "text") {
377
+ const el = pick || document.body || document.documentElement;
378
+ try { out = String(el && el.innerText ? el.innerText : ""); } catch { out = ""; }
379
+ } else {
380
+ const el = pick || document.documentElement;
381
+ try { out = String(el && el.outerHTML ? el.outerHTML : ""); } catch { out = ""; }
382
+ }
383
+ if (max && out.length > max) out = out.slice(0, max) + "\\n<!-- …truncated… -->";
384
+ return out;
385
+ })()`;
386
+
387
+ const evaluated = await evaluateJavaScript({
388
+ wsUrl: opts.wsUrl,
389
+ expression,
390
+ awaitPromise: true,
391
+ returnByValue: true,
392
+ });
393
+ const textValue = (evaluated.result?.value ?? "") as unknown;
394
+ const text =
395
+ typeof textValue === "string"
396
+ ? textValue
397
+ : typeof textValue === "number" || typeof textValue === "boolean"
398
+ ? String(textValue)
399
+ : "";
400
+ return { text };
401
+ }
402
+
403
+ export async function querySelector(opts: {
404
+ wsUrl: string;
405
+ selector: string;
406
+ limit?: number;
407
+ maxTextChars?: number;
408
+ maxHtmlChars?: number;
409
+ }): Promise<{
410
+ matches: QueryMatch[];
411
+ }> {
412
+ const limit = Math.max(1, Math.min(200, Math.floor(opts.limit ?? 20)));
413
+ const maxText = Math.max(0, Math.min(5000, Math.floor(opts.maxTextChars ?? 500)));
414
+ const maxHtml = Math.max(0, Math.min(20000, Math.floor(opts.maxHtmlChars ?? 1500)));
415
+
416
+ const expression = `(() => {
417
+ const sel = ${JSON.stringify(opts.selector)};
418
+ const lim = ${JSON.stringify(limit)};
419
+ const maxText = ${JSON.stringify(maxText)};
420
+ const maxHtml = ${JSON.stringify(maxHtml)};
421
+ const els = Array.from(document.querySelectorAll(sel)).slice(0, lim);
422
+ return els.map((el, i) => {
423
+ const tag = (el.tagName || "").toLowerCase();
424
+ const id = el.id ? String(el.id) : undefined;
425
+ const className = el.className ? String(el.className).slice(0, 300) : undefined;
426
+ let text = "";
427
+ try { text = String(el.innerText || "").trim(); } catch {}
428
+ if (maxText && text.length > maxText) text = text.slice(0, maxText) + "…";
429
+ const value = (el.value !== undefined && el.value !== null) ? String(el.value).slice(0, 500) : undefined;
430
+ const href = (el.href !== undefined && el.href !== null) ? String(el.href) : undefined;
431
+ let outerHTML = "";
432
+ try { outerHTML = String(el.outerHTML || ""); } catch {}
433
+ if (maxHtml && outerHTML.length > maxHtml) outerHTML = outerHTML.slice(0, maxHtml) + "…";
434
+ return {
435
+ index: i + 1,
436
+ tag,
437
+ ...(id ? { id } : {}),
438
+ ...(className ? { className } : {}),
439
+ ...(text ? { text } : {}),
440
+ ...(value ? { value } : {}),
441
+ ...(href ? { href } : {}),
442
+ ...(outerHTML ? { outerHTML } : {}),
443
+ };
444
+ });
445
+ })()`;
446
+
447
+ const evaluated = await evaluateJavaScript({
448
+ wsUrl: opts.wsUrl,
449
+ expression,
450
+ awaitPromise: true,
451
+ returnByValue: true,
452
+ });
453
+ const matches = evaluated.result?.value;
454
+ return { matches: Array.isArray(matches) ? (matches as QueryMatch[]) : [] };
455
+ }
456
+
457
+ export type QueryMatch = {
458
+ index: number;
459
+ tag: string;
460
+ id?: string;
461
+ className?: string;
462
+ text?: string;
463
+ value?: string;
464
+ href?: string;
465
+ outerHTML?: string;
466
+ };