@yielded/agent-platform-cloudflare 0.1.0-beta.172 → 0.1.0-beta.174
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/dist/{Alarm-BMEAZo3p.mjs → Alarm-4J9B8Fg8.mjs} +54 -32
- package/dist/Alarm-4J9B8Fg8.mjs.map +1 -0
- package/dist/Alarm.mjs +1 -1
- package/dist/BrowserRestCapture.mjs.map +1 -1
- package/dist/BrowserRestCrawl.mjs.map +1 -1
- package/dist/{BrowserSession-Bx0V1-6_.d.mts → BrowserSession-Cojp7nth.d.mts} +3 -2
- package/dist/{BrowserSession-BfNmyayH.mjs → BrowserSession-aovMjfL4.mjs} +14 -14
- package/dist/BrowserSession-aovMjfL4.mjs.map +1 -0
- package/dist/BrowserSession.d.mts +1 -1
- package/dist/BrowserSession.mjs +2 -2
- package/dist/BrowserUse.d.mts +40 -64
- package/dist/BrowserUse.mjs +223 -2
- package/dist/BrowserUse.mjs.map +1 -0
- package/dist/CloudflareBrowser-Vt8qTdYW.mjs.map +1 -1
- package/dist/CloudflareCodeMode.mjs.map +1 -1
- package/dist/CloudflareScheduling.mjs +9 -9
- package/dist/CloudflareScheduling.mjs.map +1 -1
- package/dist/CloudflareSubscriptions.mjs +15 -15
- package/dist/CloudflareSubscriptions.mjs.map +1 -1
- package/dist/{CloudflareThreadClient-DgZVrZzF.mjs → CloudflareThreadClient-DU548EEj.mjs} +42 -39
- package/dist/CloudflareThreadClient-DU548EEj.mjs.map +1 -0
- package/dist/{CloudflareThreadClient-DuRG0MLd.d.mts → CloudflareThreadClient-lTm6baDP.d.mts} +353 -353
- package/dist/CloudflareThreadClient.d.mts +1 -1
- package/dist/CloudflareThreadClient.mjs +1 -1
- package/dist/{InteractiveBrowser-LdKzQeLR.mjs → InteractiveBrowser-BHNlwjZL.mjs} +40 -31
- package/dist/InteractiveBrowser-BHNlwjZL.mjs.map +1 -0
- package/dist/InteractiveBrowser.mjs +1 -1
- package/dist/{ThreadObject-CugPnWsJ.d.mts → ThreadObject-BLYgzcdT.d.mts} +6 -6
- package/dist/{ThreadObject-CGIaz6Jv.mjs → ThreadObject-C2LF3btz.mjs} +13 -14
- package/dist/ThreadObject-C2LF3btz.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/ThreadObject.mjs +1 -1
- package/dist/WakeScheduler.d.mts +1 -1
- package/dist/WakeScheduler.mjs +8 -3
- package/dist/WakeScheduler.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +5 -5
- package/dist/{prepared-admission-CSdzFM_v.mjs → prepared-admission-BoUPHSNQ.mjs} +2 -2
- package/dist/{prepared-admission-CSdzFM_v.mjs.map → prepared-admission-BoUPHSNQ.mjs.map} +1 -1
- package/package.json +1 -1
- package/src/Alarm.ts +82 -39
- package/src/BrowserRestCapture.ts +1 -0
- package/src/BrowserRestCrawl.ts +1 -0
- package/src/BrowserSession.ts +3 -2
- package/src/BrowserUse.ts +287 -1504
- package/src/CloudflareCodeMode.ts +6 -0
- package/src/CloudflareScheduling.ts +103 -103
- package/src/CloudflareSubscriptions.ts +192 -199
- package/src/CloudflareThreadClient.ts +256 -268
- package/src/InteractiveBrowser.ts +43 -17
- package/src/ThreadObject.ts +35 -24
- package/src/WakeScheduler.ts +12 -9
- package/src/internal/browser-binding.ts +8 -0
- package/src/internal/browser-credentials.ts +18 -13
- package/src/internal/browser-file-selection.ts +13 -2
- package/src/internal/browser-quick-action.ts +1 -0
- package/src/internal/browser-session-lifecycle.ts +32 -36
- package/src/internal/due-queue.ts +38 -19
- package/src/internal/layers.ts +53 -53
- package/dist/Alarm-BMEAZo3p.mjs.map +0 -1
- package/dist/BrowserSession-BfNmyayH.mjs.map +0 -1
- package/dist/BrowserUse-Bc2JdLW2.mjs +0 -1528
- package/dist/BrowserUse-Bc2JdLW2.mjs.map +0 -1
- package/dist/CloudflareThreadClient-DgZVrZzF.mjs.map +0 -1
- package/dist/InteractiveBrowser-LdKzQeLR.mjs.map +0 -1
- package/dist/ThreadObject-CGIaz6Jv.mjs.map +0 -1
- package/dist/page-function-CmUCcyNP.mjs +0 -11
- package/dist/page-function-CmUCcyNP.mjs.map +0 -1
- package/src/internal/browser-dom.ts +0 -886
- package/src/internal/browser-jev-dom.ts +0 -362
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
|
|
3
|
-
/* @license
|
|
4
|
-
* Selection and accessible naming adapted from jev-ultrafast snapshot.js at 1231850.
|
|
5
|
-
* Copyright (c) 2026 Browser Use
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import type { Control } from "@yielded/agent/browser-use";
|
|
27
|
-
|
|
28
|
-
import { pageFunction } from "./page-function.ts";
|
|
29
|
-
|
|
30
|
-
/** Isolated-realm Jev observation. The same private refs and native guards own input. */
|
|
31
|
-
export const inspectJevDom = pageFunction(
|
|
32
|
-
(
|
|
33
|
-
selector: string | undefined,
|
|
34
|
-
prefix: string,
|
|
35
|
-
maximum: number,
|
|
36
|
-
optionFilter: string | undefined,
|
|
37
|
-
) => {
|
|
38
|
-
const registry = new Map<string, Element>();
|
|
39
|
-
|
|
40
|
-
const checks = new Map<
|
|
41
|
-
string,
|
|
42
|
-
{ name: string; originalName: string; kind: string; viewport: boolean; verify: () => boolean }
|
|
43
|
-
>();
|
|
44
|
-
|
|
45
|
-
Reflect.set(globalThis, "@effect-agent/native-browser", registry);
|
|
46
|
-
Reflect.set(globalThis, "@effect-agent/native-browser-name-checks", checks);
|
|
47
|
-
|
|
48
|
-
const visible = (node: Element) => {
|
|
49
|
-
let ancestor: Element | null = node;
|
|
50
|
-
|
|
51
|
-
while (ancestor !== null) {
|
|
52
|
-
if (ancestor.matches('[aria-hidden="true"],[inert]')) return false;
|
|
53
|
-
const root = ancestor.getRootNode();
|
|
54
|
-
|
|
55
|
-
ancestor = ancestor.parentElement ?? (root instanceof ShadowRoot ? root.host : null);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return node.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true });
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const inView = (node: Element) => {
|
|
62
|
-
const rect = node.getBoundingClientRect();
|
|
63
|
-
const x = rect.x + rect.width / 2;
|
|
64
|
-
const y = rect.y + rect.height / 2;
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
rect.width > 0 && rect.height > 0 && x >= 0 && y >= 0 && x < innerWidth && y < innerHeight
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const name = (node: Element | null, seen = new Set<Element>()): string => {
|
|
72
|
-
if (node === null || seen.has(node) || seen.size >= 10_000) return "";
|
|
73
|
-
seen.add(node);
|
|
74
|
-
|
|
75
|
-
const referenced = (node.getAttribute("aria-labelledby") ?? "")
|
|
76
|
-
.split(/\s+/)
|
|
77
|
-
.map((id) => name(document.getElementById(id), seen))
|
|
78
|
-
.filter(Boolean)
|
|
79
|
-
.join(" ");
|
|
80
|
-
|
|
81
|
-
const labels =
|
|
82
|
-
node instanceof HTMLInputElement ||
|
|
83
|
-
node instanceof HTMLTextAreaElement ||
|
|
84
|
-
node instanceof HTMLSelectElement
|
|
85
|
-
? node.labels
|
|
86
|
-
: null;
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
referenced ||
|
|
90
|
-
node.getAttribute("aria-label") ||
|
|
91
|
-
Array.from(labels ?? [])
|
|
92
|
-
.map((label) => name(label, seen))
|
|
93
|
-
.filter(Boolean)
|
|
94
|
-
.join(" ") ||
|
|
95
|
-
(node instanceof HTMLInputElement && ["button", "submit", "reset"].includes(node.type)
|
|
96
|
-
? node.value
|
|
97
|
-
: "") ||
|
|
98
|
-
node.getAttribute("alt") ||
|
|
99
|
-
(node.tagName === "INPUT"
|
|
100
|
-
? ""
|
|
101
|
-
: Array.from(node.childNodes)
|
|
102
|
-
.map((child) =>
|
|
103
|
-
child instanceof Text
|
|
104
|
-
? child.textContent
|
|
105
|
-
: child instanceof Element && child.getAttribute("aria-hidden") !== "true"
|
|
106
|
-
? name(child, seen)
|
|
107
|
-
: "",
|
|
108
|
-
)
|
|
109
|
-
.join(" ")
|
|
110
|
-
.trim()) ||
|
|
111
|
-
node.getAttribute("title") ||
|
|
112
|
-
node.getAttribute("placeholder") ||
|
|
113
|
-
""
|
|
114
|
-
).slice(0, 4_096);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const roles = [
|
|
118
|
-
"button",
|
|
119
|
-
"link",
|
|
120
|
-
"checkbox",
|
|
121
|
-
"radio",
|
|
122
|
-
"switch",
|
|
123
|
-
"tab",
|
|
124
|
-
"menuitem",
|
|
125
|
-
"menuitemradio",
|
|
126
|
-
"option",
|
|
127
|
-
"gridcell",
|
|
128
|
-
"combobox",
|
|
129
|
-
"textbox",
|
|
130
|
-
"searchbox",
|
|
131
|
-
"spinbutton",
|
|
132
|
-
];
|
|
133
|
-
|
|
134
|
-
const role = (node: HTMLElement) => {
|
|
135
|
-
const explicit = node.getAttribute("role");
|
|
136
|
-
|
|
137
|
-
if (explicit !== null && roles.includes(explicit)) return explicit;
|
|
138
|
-
if (node.tagName === "BUTTON" || node.tagName === "SUMMARY") return "button";
|
|
139
|
-
if (node.tagName === "A") return "link";
|
|
140
|
-
if (node instanceof HTMLSelectElement) return "combobox";
|
|
141
|
-
if (node instanceof HTMLTextAreaElement || node.isContentEditable) return "textbox";
|
|
142
|
-
if (node instanceof HTMLInputElement) {
|
|
143
|
-
if (["checkbox", "radio"].includes(node.type)) return node.type;
|
|
144
|
-
if (["button", "submit", "reset", "image"].includes(node.type)) return "button";
|
|
145
|
-
if (node.type === "search") return "searchbox";
|
|
146
|
-
if (node.type === "number") return "spinbutton";
|
|
147
|
-
if (["text", "email", "url", "tel"].includes(node.type)) return "textbox";
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return null;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const value = (node: HTMLElement) =>
|
|
154
|
-
("value" in node
|
|
155
|
-
? String(node.value)
|
|
156
|
-
: node.isContentEditable || role(node) === "combobox"
|
|
157
|
-
? node.innerText.trim()
|
|
158
|
-
: ""
|
|
159
|
-
).slice(0, 4_096);
|
|
160
|
-
|
|
161
|
-
const readOnly = (node: HTMLElement) =>
|
|
162
|
-
((node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) &&
|
|
163
|
-
node.readOnly) ||
|
|
164
|
-
node.getAttribute("aria-readonly") === "true";
|
|
165
|
-
|
|
166
|
-
const closedRoots: ReadonlyMap<Element, ShadowRoot> | undefined = Reflect.get(
|
|
167
|
-
globalThis,
|
|
168
|
-
"@effect-agent/native-browser-closed-roots",
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
const candidates = [document, ...(closedRoots?.values() ?? [])].flatMap((root) =>
|
|
172
|
-
Array.from(
|
|
173
|
-
root.querySelectorAll(
|
|
174
|
-
'a[href],button,input,textarea,select,summary,[contenteditable="true"],' +
|
|
175
|
-
roles.map((role) => `[role="${role}"]`).join(","),
|
|
176
|
-
),
|
|
177
|
-
),
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
const controls: Array<typeof Control.Type> = [];
|
|
181
|
-
let truncated = candidates.length > 10_000;
|
|
182
|
-
// A modal dialog blocks background input; offer only its controls, as default observations do.
|
|
183
|
-
const modal = document.querySelector("dialog:modal");
|
|
184
|
-
|
|
185
|
-
for (const node of Array.from(candidates).slice(0, 10_000)) {
|
|
186
|
-
if (!(node instanceof HTMLElement)) continue;
|
|
187
|
-
if (selector !== undefined && !node.matches(selector) && node.closest(selector) === null)
|
|
188
|
-
continue;
|
|
189
|
-
if (node instanceof HTMLInputElement && ["password", "file", "hidden"].includes(node.type))
|
|
190
|
-
continue;
|
|
191
|
-
if (
|
|
192
|
-
!visible(node) ||
|
|
193
|
-
!inView(node) ||
|
|
194
|
-
(modal !== null && !modal.contains(node)) ||
|
|
195
|
-
node.matches(":disabled") ||
|
|
196
|
-
node.closest('[aria-disabled="true"]')
|
|
197
|
-
)
|
|
198
|
-
continue;
|
|
199
|
-
const kind = role(node);
|
|
200
|
-
|
|
201
|
-
if (kind === null || (kind === "gridcell" && node.querySelector('button,[role="button"]')))
|
|
202
|
-
continue;
|
|
203
|
-
if (controls.length >= maximum) {
|
|
204
|
-
truncated = true;
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
const ref = `${prefix}-${controls.length}`;
|
|
208
|
-
const label = name(node) || kind;
|
|
209
|
-
const currentValue = value(node);
|
|
210
|
-
const readonly = readOnly(node);
|
|
211
|
-
const allOptions = node instanceof HTMLSelectElement ? Array.from(node.options) : [];
|
|
212
|
-
|
|
213
|
-
const matching = allOptions.flatMap((option, index) =>
|
|
214
|
-
option.selected ||
|
|
215
|
-
optionFilter === undefined ||
|
|
216
|
-
`${option.label}\n${option.value}`.toLowerCase().includes(optionFilter.toLowerCase())
|
|
217
|
-
? [{ option, index }]
|
|
218
|
-
: [],
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const selected = matching.filter(({ option }) => option.selected);
|
|
222
|
-
|
|
223
|
-
const options = [
|
|
224
|
-
...selected.slice(0, 256),
|
|
225
|
-
...matching
|
|
226
|
-
.filter(({ option }) => !option.selected)
|
|
227
|
-
.slice(0, Math.max(0, 256 - selected.length)),
|
|
228
|
-
];
|
|
229
|
-
|
|
230
|
-
truncated ||= matching.length > options.length;
|
|
231
|
-
registry.set(ref, node);
|
|
232
|
-
checks.set(ref, {
|
|
233
|
-
name: label,
|
|
234
|
-
originalName: node.innerText.replace(/\s+/g, " ").trim().slice(0, 300),
|
|
235
|
-
kind,
|
|
236
|
-
viewport: true,
|
|
237
|
-
verify: () =>
|
|
238
|
-
role(node) === kind &&
|
|
239
|
-
(name(node) || kind) === label &&
|
|
240
|
-
value(node) === currentValue &&
|
|
241
|
-
readOnly(node) === readonly &&
|
|
242
|
-
node.closest('[aria-disabled="true"]') === null &&
|
|
243
|
-
inView(node),
|
|
244
|
-
});
|
|
245
|
-
controls.push({
|
|
246
|
-
ref,
|
|
247
|
-
kind,
|
|
248
|
-
name: label,
|
|
249
|
-
value: currentValue,
|
|
250
|
-
disabled: false,
|
|
251
|
-
editable:
|
|
252
|
-
!readonly &&
|
|
253
|
-
(["textbox", "searchbox", "spinbutton"].includes(kind) ||
|
|
254
|
-
(kind === "combobox" &&
|
|
255
|
-
(node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement))),
|
|
256
|
-
pointerEvents: getComputedStyle(node).pointerEvents.slice(0, 64),
|
|
257
|
-
options: options.map(({ option }) => option.value.slice(0, 4_096)),
|
|
258
|
-
...(node instanceof HTMLSelectElement
|
|
259
|
-
? {
|
|
260
|
-
optionCount: allOptions.length,
|
|
261
|
-
optionDetails: options.map(({ option, index }) => ({
|
|
262
|
-
index,
|
|
263
|
-
value: option.value.slice(0, 4_096),
|
|
264
|
-
label: option.label.slice(0, 300),
|
|
265
|
-
selected: option.selected,
|
|
266
|
-
disabled:
|
|
267
|
-
option.disabled ||
|
|
268
|
-
(option.parentElement instanceof HTMLOptGroupElement &&
|
|
269
|
-
option.parentElement.disabled),
|
|
270
|
-
})),
|
|
271
|
-
}
|
|
272
|
-
: {}),
|
|
273
|
-
...(node instanceof HTMLInputElement && ["checkbox", "radio"].includes(node.type)
|
|
274
|
-
? { checked: node.checked }
|
|
275
|
-
: {}),
|
|
276
|
-
attributes: Object.fromEntries(
|
|
277
|
-
[
|
|
278
|
-
"id",
|
|
279
|
-
"name",
|
|
280
|
-
"type",
|
|
281
|
-
"role",
|
|
282
|
-
"tabindex",
|
|
283
|
-
"placeholder",
|
|
284
|
-
"aria-label",
|
|
285
|
-
"aria-labelledby",
|
|
286
|
-
"aria-expanded",
|
|
287
|
-
"aria-selected",
|
|
288
|
-
"aria-checked",
|
|
289
|
-
"aria-readonly",
|
|
290
|
-
"aria-disabled",
|
|
291
|
-
"aria-controls",
|
|
292
|
-
"href",
|
|
293
|
-
].flatMap((key) => {
|
|
294
|
-
const attribute = node.getAttribute(key);
|
|
295
|
-
|
|
296
|
-
return attribute === null ? [] : [[key, attribute.slice(0, 1_024)]];
|
|
297
|
-
}),
|
|
298
|
-
),
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const scopes =
|
|
303
|
-
selector === undefined ? [document.body] : Array.from(document.querySelectorAll(selector));
|
|
304
|
-
|
|
305
|
-
const visited = new Set<Node>();
|
|
306
|
-
const words: Array<string> = [];
|
|
307
|
-
const range = document.createRange();
|
|
308
|
-
let length = 0;
|
|
309
|
-
let scanned = 0;
|
|
310
|
-
|
|
311
|
-
truncated ||= scopes.length > 256;
|
|
312
|
-
for (const scope of scopes.slice(0, 256)) {
|
|
313
|
-
if (scope === null) continue;
|
|
314
|
-
const walker = document.createTreeWalker(scope, NodeFilter.SHOW_TEXT);
|
|
315
|
-
let node = walker.nextNode();
|
|
316
|
-
|
|
317
|
-
while (node !== null && length < 6_000 && scanned++ < 10_000) {
|
|
318
|
-
const text = node.textContent?.trim() ?? "";
|
|
319
|
-
const parent = node.parentElement;
|
|
320
|
-
|
|
321
|
-
if (
|
|
322
|
-
!visited.has(node) &&
|
|
323
|
-
text &&
|
|
324
|
-
parent &&
|
|
325
|
-
!parent.closest("script,style,noscript,template") &&
|
|
326
|
-
visible(parent)
|
|
327
|
-
) {
|
|
328
|
-
range.selectNodeContents(node);
|
|
329
|
-
const rect = range.getBoundingClientRect();
|
|
330
|
-
|
|
331
|
-
if (
|
|
332
|
-
rect.width > 0 &&
|
|
333
|
-
rect.height > 0 &&
|
|
334
|
-
rect.bottom > 0 &&
|
|
335
|
-
rect.top < innerHeight &&
|
|
336
|
-
rect.right > 0 &&
|
|
337
|
-
rect.left < innerWidth
|
|
338
|
-
) {
|
|
339
|
-
words.push(text);
|
|
340
|
-
length += text.length;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
visited.add(node);
|
|
344
|
-
node = walker.nextNode();
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
const text = words.join("\n");
|
|
348
|
-
|
|
349
|
-
return {
|
|
350
|
-
text: text.slice(0, 6_000),
|
|
351
|
-
controls,
|
|
352
|
-
readyState: document.readyState,
|
|
353
|
-
truncated: truncated || text.length > 6_000 || scanned >= 10_000,
|
|
354
|
-
page: {
|
|
355
|
-
title: document.title,
|
|
356
|
-
scrollY,
|
|
357
|
-
viewportHeight: innerHeight,
|
|
358
|
-
documentHeight: document.documentElement.scrollHeight,
|
|
359
|
-
},
|
|
360
|
-
};
|
|
361
|
-
},
|
|
362
|
-
);
|