tuna-agent 0.1.1 → 0.1.2
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/browser/actions/download.d.ts +16 -0
- package/dist/browser/actions/download.js +39 -0
- package/dist/browser/actions/emulation.d.ts +53 -0
- package/dist/browser/actions/emulation.js +103 -0
- package/dist/browser/actions/evaluate.d.ts +29 -0
- package/dist/browser/actions/evaluate.js +92 -0
- package/dist/browser/actions/interaction.d.ts +79 -0
- package/dist/browser/actions/interaction.js +210 -0
- package/dist/browser/actions/keyboard.d.ts +6 -0
- package/dist/browser/actions/keyboard.js +9 -0
- package/dist/browser/actions/navigation.d.ts +40 -0
- package/dist/browser/actions/navigation.js +92 -0
- package/dist/browser/actions/wait.d.ts +12 -0
- package/dist/browser/actions/wait.js +33 -0
- package/dist/browser/browser.d.ts +722 -0
- package/dist/browser/browser.js +1066 -0
- package/dist/browser/capture/activity.d.ts +22 -0
- package/dist/browser/capture/activity.js +39 -0
- package/dist/browser/capture/pdf.d.ts +6 -0
- package/dist/browser/capture/pdf.js +6 -0
- package/dist/browser/capture/response.d.ts +8 -0
- package/dist/browser/capture/response.js +28 -0
- package/dist/browser/capture/screenshot.d.ts +30 -0
- package/dist/browser/capture/screenshot.js +72 -0
- package/dist/browser/capture/trace.d.ts +13 -0
- package/dist/browser/capture/trace.js +19 -0
- package/dist/browser/chrome-launcher.d.ts +8 -0
- package/dist/browser/chrome-launcher.js +543 -0
- package/dist/browser/connection.d.ts +42 -0
- package/dist/browser/connection.js +359 -0
- package/dist/browser/index.d.ts +6 -0
- package/dist/browser/index.js +3 -0
- package/dist/browser/security.d.ts +51 -0
- package/dist/browser/security.js +357 -0
- package/dist/browser/snapshot/ai-snapshot.d.ts +12 -0
- package/dist/browser/snapshot/ai-snapshot.js +47 -0
- package/dist/browser/snapshot/aria-snapshot.d.ts +26 -0
- package/dist/browser/snapshot/aria-snapshot.js +121 -0
- package/dist/browser/snapshot/ref-map.d.ts +31 -0
- package/dist/browser/snapshot/ref-map.js +250 -0
- package/dist/browser/storage/index.d.ts +36 -0
- package/dist/browser/storage/index.js +65 -0
- package/dist/browser/types.d.ts +429 -0
- package/dist/browser/types.js +2 -0
- package/dist/daemon/extension-handlers.d.ts +63 -0
- package/dist/daemon/extension-handlers.js +630 -0
- package/dist/daemon/index.js +78 -19
- package/dist/daemon/ws-client.d.ts +16 -0
- package/dist/daemon/ws-client.js +45 -0
- package/dist/mcp/browser-server.d.ts +11 -0
- package/dist/mcp/browser-server.js +467 -0
- package/dist/mcp/knowledge-server.js +43 -18
- package/dist/mcp/setup.js +10 -0
- package/dist/utils/claude-cli.js +18 -9
- package/package.json +2 -1
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
import { type FrameEvalResult } from './actions/evaluate.js';
|
|
2
|
+
import type { LaunchOptions, ConnectOptions, SnapshotResult, SnapshotOptions, AriaSnapshotResult, BrowserTab, FormField, ClickOptions, TypeOptions, WaitOptions, ScreenshotOptions, ConsoleMessage, PageError, NetworkRequest, CookieData, StorageKind, SsrfPolicy, DownloadResult, DialogOptions, ResponseBodyResult, TraceStartOptions, ColorScheme, GeolocationOptions, HttpCredentials } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a single browser page/tab with ref-based automation.
|
|
5
|
+
*
|
|
6
|
+
* The workflow is: **snapshot → read refs → act on refs**.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const page = await browser.open('https://example.com');
|
|
11
|
+
*
|
|
12
|
+
* // 1. Take a snapshot to get refs
|
|
13
|
+
* const { snapshot, refs } = await page.snapshot();
|
|
14
|
+
* // snapshot: AI-readable text tree
|
|
15
|
+
* // refs: { "e1": { role: "link", name: "More info" }, ... }
|
|
16
|
+
*
|
|
17
|
+
* // 2. Act on refs
|
|
18
|
+
* await page.click('e1');
|
|
19
|
+
* await page.type('e3', 'hello');
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class CrawlPage {
|
|
23
|
+
private readonly cdpUrl;
|
|
24
|
+
private readonly targetId;
|
|
25
|
+
private readonly ssrfPolicy;
|
|
26
|
+
/** @internal */
|
|
27
|
+
constructor(cdpUrl: string, targetId: string, ssrfPolicy?: SsrfPolicy);
|
|
28
|
+
/** The CDP target ID for this page. Use this to identify the page in multi-tab scenarios. */
|
|
29
|
+
get id(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Take an AI-readable snapshot of the page.
|
|
32
|
+
*
|
|
33
|
+
* Returns a text tree with numbered refs (`e1`, `e2`, ...) that map to
|
|
34
|
+
* interactive elements. Use these refs with actions like `click()` and `type()`.
|
|
35
|
+
*
|
|
36
|
+
* @param opts - Snapshot options (mode, filtering, depth limits)
|
|
37
|
+
* @returns Snapshot text, ref map, and statistics
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // Default snapshot (aria mode)
|
|
42
|
+
* const { snapshot, refs } = await page.snapshot();
|
|
43
|
+
*
|
|
44
|
+
* // Interactive elements only, compact
|
|
45
|
+
* const result = await page.snapshot({ interactive: true, compact: true });
|
|
46
|
+
*
|
|
47
|
+
* // Role-based mode (uses getByRole resolution)
|
|
48
|
+
* const result = await page.snapshot({ mode: 'role' });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
snapshot(opts?: SnapshotOptions): Promise<SnapshotResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Take a raw ARIA accessibility tree snapshot via CDP.
|
|
54
|
+
*
|
|
55
|
+
* Unlike `snapshot()`, this returns structured node data rather than
|
|
56
|
+
* an AI-readable text tree. Useful for programmatic accessibility analysis.
|
|
57
|
+
*
|
|
58
|
+
* @param opts - Options (limit: max nodes to return, default 500)
|
|
59
|
+
* @returns Array of accessibility tree nodes
|
|
60
|
+
*/
|
|
61
|
+
ariaSnapshot(opts?: {
|
|
62
|
+
limit?: number;
|
|
63
|
+
}): Promise<AriaSnapshotResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Click an element by ref.
|
|
66
|
+
*
|
|
67
|
+
* @param ref - Ref ID from a snapshot (e.g. `'e1'`)
|
|
68
|
+
* @param opts - Click options (double-click, button, modifiers)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* await page.click('e1');
|
|
73
|
+
* await page.click('e2', { doubleClick: true });
|
|
74
|
+
* await page.click('e3', { button: 'right' });
|
|
75
|
+
* await page.click('e4', { modifiers: ['Control'] });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
click(ref: string, opts?: ClickOptions): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Type text into an input element by ref.
|
|
81
|
+
*
|
|
82
|
+
* By default, uses Playwright's `fill()` for instant input. Use `slowly: true`
|
|
83
|
+
* to simulate real keystroke typing with a 75ms delay per character.
|
|
84
|
+
*
|
|
85
|
+
* @param ref - Ref ID of the input element (e.g. `'e3'`)
|
|
86
|
+
* @param text - Text to type
|
|
87
|
+
* @param opts - Type options (submit, slowly)
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* await page.type('e3', 'hello world');
|
|
92
|
+
* await page.type('e3', 'slow typing', { slowly: true });
|
|
93
|
+
* await page.type('e3', 'search query', { submit: true }); // press Enter after
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
type(ref: string, text: string, opts?: TypeOptions): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Hover over an element by ref.
|
|
99
|
+
*
|
|
100
|
+
* @param ref - Ref ID from a snapshot
|
|
101
|
+
* @param opts - Timeout options
|
|
102
|
+
*/
|
|
103
|
+
hover(ref: string, opts?: {
|
|
104
|
+
timeoutMs?: number;
|
|
105
|
+
}): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Select option(s) in a `<select>` dropdown by ref.
|
|
108
|
+
*
|
|
109
|
+
* @param ref - Ref ID of the select element
|
|
110
|
+
* @param values - One or more option labels/values to select
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* await page.select('e5', 'Option A');
|
|
115
|
+
* await page.select('e5', 'Option A', 'Option B'); // multi-select
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
select(ref: string, ...values: string[]): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Drag one element to another.
|
|
121
|
+
*
|
|
122
|
+
* @param startRef - Ref ID of the element to drag
|
|
123
|
+
* @param endRef - Ref ID of the drop target
|
|
124
|
+
* @param opts - Timeout options
|
|
125
|
+
*/
|
|
126
|
+
drag(startRef: string, endRef: string, opts?: {
|
|
127
|
+
timeoutMs?: number;
|
|
128
|
+
}): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Fill multiple form fields at once.
|
|
131
|
+
*
|
|
132
|
+
* Supports text inputs, checkboxes, and radio buttons.
|
|
133
|
+
*
|
|
134
|
+
* @param fields - Array of form fields to fill
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* await page.fill([
|
|
139
|
+
* { ref: 'e2', type: 'text', value: 'Jane Doe' },
|
|
140
|
+
* { ref: 'e4', type: 'text', value: 'jane@example.com' },
|
|
141
|
+
* { ref: 'e6', type: 'checkbox', value: true },
|
|
142
|
+
* ]);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
fill(fields: FormField[]): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Scroll an element into the visible viewport.
|
|
148
|
+
*
|
|
149
|
+
* @param ref - Ref ID of the element to scroll to
|
|
150
|
+
* @param opts - Timeout options
|
|
151
|
+
*/
|
|
152
|
+
scrollIntoView(ref: string, opts?: {
|
|
153
|
+
timeoutMs?: number;
|
|
154
|
+
}): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Highlight an element in the browser (Playwright built-in highlight).
|
|
157
|
+
*
|
|
158
|
+
* @param ref - Ref ID of the element to highlight
|
|
159
|
+
*/
|
|
160
|
+
highlight(ref: string): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Set files on an `<input type="file">` element.
|
|
163
|
+
*
|
|
164
|
+
* @param ref - Ref ID of the file input element
|
|
165
|
+
* @param paths - Array of file paths to upload
|
|
166
|
+
*/
|
|
167
|
+
uploadFile(ref: string, paths: string[]): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Arm a one-shot dialog handler (alert, confirm, prompt).
|
|
170
|
+
*
|
|
171
|
+
* Returns a promise — store it (don't await), trigger the dialog, then await it.
|
|
172
|
+
*
|
|
173
|
+
* @param opts - Dialog options (accept/dismiss, prompt text, timeout)
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const dialogDone = page.armDialog({ accept: true }); // don't await here
|
|
178
|
+
* await page.click('e5'); // triggers confirm()
|
|
179
|
+
* await dialogDone; // wait for dialog to be handled
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
armDialog(opts: DialogOptions): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Arm a one-shot file chooser handler.
|
|
185
|
+
*
|
|
186
|
+
* Returns a promise — store it (don't await), trigger the file picker, then await it.
|
|
187
|
+
*
|
|
188
|
+
* @param paths - File paths to set when the chooser appears (empty to clear)
|
|
189
|
+
* @param opts - Timeout options
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* const uploadDone = page.armFileUpload(['/path/to/file.pdf']); // don't await here
|
|
194
|
+
* await page.click('e3'); // triggers file picker
|
|
195
|
+
* await uploadDone; // wait for files to be set
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
armFileUpload(paths?: string[], opts?: {
|
|
199
|
+
timeoutMs?: number;
|
|
200
|
+
}): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Press a keyboard key or key combination.
|
|
203
|
+
*
|
|
204
|
+
* Uses Playwright's key names. Supports combinations with `+`.
|
|
205
|
+
*
|
|
206
|
+
* @param key - Key to press (e.g. `'Enter'`, `'Tab'`, `'Control+a'`, `'Meta+c'`)
|
|
207
|
+
* @param opts - Options (delayMs: hold time between keydown and keyup)
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* await page.press('Enter');
|
|
212
|
+
* await page.press('Control+a');
|
|
213
|
+
* await page.press('Meta+Shift+p');
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
press(key: string, opts?: {
|
|
217
|
+
delayMs?: number;
|
|
218
|
+
}): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Get the current URL of the page.
|
|
221
|
+
*/
|
|
222
|
+
url(): Promise<string>;
|
|
223
|
+
/**
|
|
224
|
+
* Get the page title.
|
|
225
|
+
*/
|
|
226
|
+
title(): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* Navigate to a URL.
|
|
229
|
+
*
|
|
230
|
+
* @param url - The URL to navigate to
|
|
231
|
+
* @param opts - Timeout options
|
|
232
|
+
* @returns The final URL after navigation (may differ due to redirects)
|
|
233
|
+
*/
|
|
234
|
+
goto(url: string, opts?: {
|
|
235
|
+
timeoutMs?: number;
|
|
236
|
+
}): Promise<{
|
|
237
|
+
url: string;
|
|
238
|
+
}>;
|
|
239
|
+
/**
|
|
240
|
+
* Reload the current page.
|
|
241
|
+
*
|
|
242
|
+
* @param opts - Timeout options
|
|
243
|
+
*/
|
|
244
|
+
reload(opts?: {
|
|
245
|
+
timeoutMs?: number;
|
|
246
|
+
}): Promise<void>;
|
|
247
|
+
/**
|
|
248
|
+
* Navigate back in browser history.
|
|
249
|
+
*
|
|
250
|
+
* @param opts - Timeout options
|
|
251
|
+
*/
|
|
252
|
+
goBack(opts?: {
|
|
253
|
+
timeoutMs?: number;
|
|
254
|
+
}): Promise<void>;
|
|
255
|
+
/**
|
|
256
|
+
* Navigate forward in browser history.
|
|
257
|
+
*
|
|
258
|
+
* @param opts - Timeout options
|
|
259
|
+
*/
|
|
260
|
+
goForward(opts?: {
|
|
261
|
+
timeoutMs?: number;
|
|
262
|
+
}): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Wait for various conditions on the page.
|
|
265
|
+
*
|
|
266
|
+
* Multiple conditions can be specified — they are checked in order.
|
|
267
|
+
*
|
|
268
|
+
* @param opts - Wait conditions (text, URL, load state, selector, etc.)
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* await page.waitFor({ loadState: 'networkidle' });
|
|
273
|
+
* await page.waitFor({ text: 'Welcome back' });
|
|
274
|
+
* await page.waitFor({ url: '**\/dashboard' });
|
|
275
|
+
* await page.waitFor({ timeMs: 1000 }); // sleep
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
waitFor(opts: WaitOptions): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Run JavaScript in the browser page context.
|
|
281
|
+
*
|
|
282
|
+
* The function string is evaluated in the browser's sandbox, not in Node.js.
|
|
283
|
+
* Pass a `ref` to receive the element as the first argument.
|
|
284
|
+
*
|
|
285
|
+
* @param fn - JavaScript function body as a string
|
|
286
|
+
* @param opts - Options (ref: scope evaluation to a specific element)
|
|
287
|
+
* @returns The return value of the evaluated function
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* const title = await page.evaluate('() => document.title');
|
|
292
|
+
* const text = await page.evaluate('(el) => el.textContent', { ref: 'e1' });
|
|
293
|
+
* const count = await page.evaluate('() => document.querySelectorAll("img").length');
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
evaluate(fn: string, opts?: {
|
|
297
|
+
ref?: string;
|
|
298
|
+
timeoutMs?: number;
|
|
299
|
+
signal?: AbortSignal;
|
|
300
|
+
}): Promise<unknown>;
|
|
301
|
+
/**
|
|
302
|
+
* Run JavaScript in ALL frames on the page (including cross-origin iframes).
|
|
303
|
+
*
|
|
304
|
+
* Playwright can access cross-origin frames via CDP, bypassing the same-origin policy.
|
|
305
|
+
* This is essential for filling payment iframes (Stripe, etc.).
|
|
306
|
+
*
|
|
307
|
+
* @param fn - JavaScript function body as a string
|
|
308
|
+
* @returns Array of results from each frame where evaluation succeeded
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const results = await page.evaluateInAllFrames(`() => {
|
|
313
|
+
* const el = document.querySelector('input[name="cardnumber"]');
|
|
314
|
+
* return el ? 'found' : null;
|
|
315
|
+
* }`);
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
evaluateInAllFrames(fn: string): Promise<FrameEvalResult[]>;
|
|
319
|
+
/**
|
|
320
|
+
* Take a screenshot of the page or a specific element.
|
|
321
|
+
*
|
|
322
|
+
* @param opts - Screenshot options (fullPage, ref, element, type)
|
|
323
|
+
* @returns PNG or JPEG image as a Buffer
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* const screenshot = await page.screenshot();
|
|
328
|
+
* const fullPage = await page.screenshot({ fullPage: true });
|
|
329
|
+
* const element = await page.screenshot({ ref: 'e1' });
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
screenshot(opts?: ScreenshotOptions): Promise<Buffer>;
|
|
333
|
+
/**
|
|
334
|
+
* Export the page as a PDF.
|
|
335
|
+
*
|
|
336
|
+
* Only works in headless mode.
|
|
337
|
+
*
|
|
338
|
+
* @returns PDF document as a Buffer
|
|
339
|
+
*/
|
|
340
|
+
pdf(): Promise<Buffer>;
|
|
341
|
+
/**
|
|
342
|
+
* Take a screenshot with numbered labels overlaid on referenced elements.
|
|
343
|
+
*
|
|
344
|
+
* Useful for visual debugging — each ref gets a numbered badge and border.
|
|
345
|
+
*
|
|
346
|
+
* @param refs - Array of ref IDs to label
|
|
347
|
+
* @param opts - Options (maxLabels: limit, type: image format)
|
|
348
|
+
* @returns Screenshot buffer, label positions, and any skipped refs
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* const { buffer, labels, skipped } = await page.screenshotWithLabels(['e1', 'e2', 'e3']);
|
|
353
|
+
* fs.writeFileSync('labeled.png', buffer);
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
screenshotWithLabels(refs: string[], opts?: {
|
|
357
|
+
maxLabels?: number;
|
|
358
|
+
type?: 'png' | 'jpeg';
|
|
359
|
+
}): Promise<{
|
|
360
|
+
buffer: Buffer;
|
|
361
|
+
labels: Array<{
|
|
362
|
+
ref: string;
|
|
363
|
+
index: number;
|
|
364
|
+
box: {
|
|
365
|
+
x: number;
|
|
366
|
+
y: number;
|
|
367
|
+
width: number;
|
|
368
|
+
height: number;
|
|
369
|
+
};
|
|
370
|
+
}>;
|
|
371
|
+
skipped: string[];
|
|
372
|
+
}>;
|
|
373
|
+
/**
|
|
374
|
+
* Start recording a Playwright trace.
|
|
375
|
+
*
|
|
376
|
+
* Traces capture screenshots, DOM snapshots, and network activity.
|
|
377
|
+
* Stop with `traceStop()` to save the trace file.
|
|
378
|
+
*
|
|
379
|
+
* @param opts - Trace options (screenshots, snapshots, sources)
|
|
380
|
+
*/
|
|
381
|
+
traceStart(opts?: TraceStartOptions): Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Stop recording a trace and save it to a file.
|
|
384
|
+
*
|
|
385
|
+
* @param path - File path to save the trace (e.g. `'trace.zip'`)
|
|
386
|
+
* @param opts - Options (allowedOutputRoots: constrain output to specific directories)
|
|
387
|
+
*/
|
|
388
|
+
traceStop(path: string, opts?: {
|
|
389
|
+
allowedOutputRoots?: string[];
|
|
390
|
+
}): Promise<void>;
|
|
391
|
+
/**
|
|
392
|
+
* Wait for a network response matching a URL pattern and return its body.
|
|
393
|
+
*
|
|
394
|
+
* @param url - URL string or pattern to match
|
|
395
|
+
* @param opts - Options (timeoutMs, maxChars)
|
|
396
|
+
* @returns Response body, status, headers, and truncation info
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* ```ts
|
|
400
|
+
* const resp = await page.responseBody('/api/data');
|
|
401
|
+
* console.log(resp.status, resp.body);
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
responseBody(url: string, opts?: {
|
|
405
|
+
timeoutMs?: number;
|
|
406
|
+
maxChars?: number;
|
|
407
|
+
}): Promise<ResponseBodyResult>;
|
|
408
|
+
/**
|
|
409
|
+
* Get console messages captured from the page.
|
|
410
|
+
*
|
|
411
|
+
* Messages are buffered automatically. Use `level` to filter by minimum severity.
|
|
412
|
+
*
|
|
413
|
+
* @param opts - Filter options (level, clear)
|
|
414
|
+
* @returns Array of captured console messages
|
|
415
|
+
*/
|
|
416
|
+
consoleLogs(opts?: {
|
|
417
|
+
level?: string;
|
|
418
|
+
clear?: boolean;
|
|
419
|
+
}): Promise<ConsoleMessage[]>;
|
|
420
|
+
/**
|
|
421
|
+
* Get uncaught errors from the page.
|
|
422
|
+
*
|
|
423
|
+
* @param opts - Options (clear: reset the error buffer after reading)
|
|
424
|
+
* @returns Array of captured page errors
|
|
425
|
+
*/
|
|
426
|
+
pageErrors(opts?: {
|
|
427
|
+
clear?: boolean;
|
|
428
|
+
}): Promise<PageError[]>;
|
|
429
|
+
/**
|
|
430
|
+
* Get network requests captured from the page.
|
|
431
|
+
*
|
|
432
|
+
* @param opts - Options (filter: URL substring match, clear: reset the buffer)
|
|
433
|
+
* @returns Array of captured network requests
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```ts
|
|
437
|
+
* const all = await page.networkRequests();
|
|
438
|
+
* const apiCalls = await page.networkRequests({ filter: '/api/' });
|
|
439
|
+
* const fresh = await page.networkRequests({ clear: true }); // read and clear
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
networkRequests(opts?: {
|
|
443
|
+
filter?: string;
|
|
444
|
+
clear?: boolean;
|
|
445
|
+
}): Promise<NetworkRequest[]>;
|
|
446
|
+
/**
|
|
447
|
+
* Resize the browser viewport.
|
|
448
|
+
*
|
|
449
|
+
* @param width - Viewport width in pixels
|
|
450
|
+
* @param height - Viewport height in pixels
|
|
451
|
+
*/
|
|
452
|
+
resize(width: number, height: number): Promise<void>;
|
|
453
|
+
/**
|
|
454
|
+
* Get all cookies for the current browser context.
|
|
455
|
+
*
|
|
456
|
+
* @returns Array of cookie objects
|
|
457
|
+
*/
|
|
458
|
+
cookies(): Promise<Awaited<ReturnType<import('playwright-core').BrowserContext['cookies']>>>;
|
|
459
|
+
/**
|
|
460
|
+
* Set a cookie in the browser context.
|
|
461
|
+
*
|
|
462
|
+
* @param cookie - Cookie data (must include `name`, `value`, and either `url` or `domain`+`path`)
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* await page.setCookie({
|
|
467
|
+
* name: 'token',
|
|
468
|
+
* value: 'abc123',
|
|
469
|
+
* url: 'https://example.com',
|
|
470
|
+
* });
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
setCookie(cookie: CookieData): Promise<void>;
|
|
474
|
+
/** Clear all cookies in the browser context. */
|
|
475
|
+
clearCookies(): Promise<void>;
|
|
476
|
+
/**
|
|
477
|
+
* Get values from localStorage or sessionStorage.
|
|
478
|
+
*
|
|
479
|
+
* @param kind - `'local'` for localStorage, `'session'` for sessionStorage
|
|
480
|
+
* @param key - Optional specific key to retrieve (returns all if omitted)
|
|
481
|
+
* @returns Key-value map of storage entries
|
|
482
|
+
*/
|
|
483
|
+
storageGet(kind: StorageKind, key?: string): Promise<Record<string, string>>;
|
|
484
|
+
/**
|
|
485
|
+
* Set a value in localStorage or sessionStorage.
|
|
486
|
+
*
|
|
487
|
+
* @param kind - `'local'` for localStorage, `'session'` for sessionStorage
|
|
488
|
+
* @param key - Storage key
|
|
489
|
+
* @param value - Storage value
|
|
490
|
+
*/
|
|
491
|
+
storageSet(kind: StorageKind, key: string, value: string): Promise<void>;
|
|
492
|
+
/**
|
|
493
|
+
* Clear all entries in localStorage or sessionStorage.
|
|
494
|
+
*
|
|
495
|
+
* @param kind - `'local'` for localStorage, `'session'` for sessionStorage
|
|
496
|
+
*/
|
|
497
|
+
storageClear(kind: StorageKind): Promise<void>;
|
|
498
|
+
/**
|
|
499
|
+
* Click a ref and save the resulting file download.
|
|
500
|
+
*
|
|
501
|
+
* @param ref - Ref ID of the element that triggers the download
|
|
502
|
+
* @param path - Local file path to save the download to
|
|
503
|
+
* @param opts - Timeout options
|
|
504
|
+
* @returns Download result with URL, suggested filename, and saved path
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* const result = await page.download('e7', '/tmp/report.pdf');
|
|
509
|
+
* console.log(result.suggestedFilename); // 'report.pdf'
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
download(ref: string, path: string, opts?: {
|
|
513
|
+
timeoutMs?: number;
|
|
514
|
+
allowedOutputRoots?: string[];
|
|
515
|
+
}): Promise<DownloadResult>;
|
|
516
|
+
/**
|
|
517
|
+
* Wait for the next download event (without clicking).
|
|
518
|
+
*
|
|
519
|
+
* Returns a promise — store it (don't await), trigger the download, then await it.
|
|
520
|
+
*
|
|
521
|
+
* @param opts - Options (path: save location, timeoutMs)
|
|
522
|
+
* @returns Download result with URL, suggested filename, and saved path
|
|
523
|
+
*/
|
|
524
|
+
waitForDownload(opts?: {
|
|
525
|
+
path?: string;
|
|
526
|
+
timeoutMs?: number;
|
|
527
|
+
allowedOutputRoots?: string[];
|
|
528
|
+
}): Promise<DownloadResult>;
|
|
529
|
+
/**
|
|
530
|
+
* Set the browser to offline or online mode.
|
|
531
|
+
*
|
|
532
|
+
* @param offline - `true` to go offline, `false` to go online
|
|
533
|
+
*/
|
|
534
|
+
setOffline(offline: boolean): Promise<void>;
|
|
535
|
+
/**
|
|
536
|
+
* Set extra HTTP headers for all requests.
|
|
537
|
+
*
|
|
538
|
+
* @param headers - Headers to add to every request
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```ts
|
|
542
|
+
* await page.setExtraHeaders({ 'X-Custom': 'value' });
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
setExtraHeaders(headers: Record<string, string>): Promise<void>;
|
|
546
|
+
/**
|
|
547
|
+
* Set HTTP authentication credentials.
|
|
548
|
+
*
|
|
549
|
+
* @param opts - Credentials (username, password) or `{ clear: true }` to remove
|
|
550
|
+
*/
|
|
551
|
+
setHttpCredentials(opts: HttpCredentials): Promise<void>;
|
|
552
|
+
/**
|
|
553
|
+
* Emulate a geolocation.
|
|
554
|
+
*
|
|
555
|
+
* @param opts - Geolocation coordinates or `{ clear: true }` to clear
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```ts
|
|
559
|
+
* await page.setGeolocation({ latitude: 48.8566, longitude: 2.3522 }); // Paris
|
|
560
|
+
* await page.setGeolocation({ clear: true }); // reset
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
setGeolocation(opts: GeolocationOptions): Promise<void>;
|
|
564
|
+
/**
|
|
565
|
+
* Emulate a preferred color scheme.
|
|
566
|
+
*
|
|
567
|
+
* @param opts - Color scheme options
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* ```ts
|
|
571
|
+
* await page.emulateMedia({ colorScheme: 'dark' });
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
emulateMedia(opts: {
|
|
575
|
+
colorScheme: ColorScheme;
|
|
576
|
+
}): Promise<void>;
|
|
577
|
+
/**
|
|
578
|
+
* Override the browser locale.
|
|
579
|
+
*
|
|
580
|
+
* @param locale - BCP-47 locale string (e.g. `'fr-FR'`, `'ja-JP'`)
|
|
581
|
+
*/
|
|
582
|
+
setLocale(locale: string): Promise<void>;
|
|
583
|
+
/**
|
|
584
|
+
* Override the browser timezone.
|
|
585
|
+
*
|
|
586
|
+
* @param timezoneId - IANA timezone ID (e.g. `'America/New_York'`, `'Asia/Tokyo'`)
|
|
587
|
+
*/
|
|
588
|
+
setTimezone(timezoneId: string): Promise<void>;
|
|
589
|
+
/**
|
|
590
|
+
* Emulate a specific device (viewport + user agent).
|
|
591
|
+
*
|
|
592
|
+
* @param name - Playwright device name (e.g. `'iPhone 13'`, `'Pixel 5'`)
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* ```ts
|
|
596
|
+
* await page.setDevice('iPhone 13');
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
setDevice(name: string): Promise<void>;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Main entry point for browserclaw.
|
|
603
|
+
*
|
|
604
|
+
* Launch or connect to a browser, then open pages and automate them
|
|
605
|
+
* using the snapshot + ref pattern.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```ts
|
|
609
|
+
* import { BrowserClaw } from 'browserclaw';
|
|
610
|
+
*
|
|
611
|
+
* const browser = await BrowserClaw.launch({ headless: false });
|
|
612
|
+
* const page = await browser.open('https://example.com');
|
|
613
|
+
*
|
|
614
|
+
* const { snapshot, refs } = await page.snapshot();
|
|
615
|
+
* console.log(snapshot); // AI-readable page tree
|
|
616
|
+
* console.log(refs); // { "e1": { role: "link", name: "More info" }, ... }
|
|
617
|
+
*
|
|
618
|
+
* await page.click('e1');
|
|
619
|
+
* await browser.stop();
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
622
|
+
export declare class BrowserClaw {
|
|
623
|
+
private readonly cdpUrl;
|
|
624
|
+
private readonly ssrfPolicy;
|
|
625
|
+
private chrome;
|
|
626
|
+
private constructor();
|
|
627
|
+
/**
|
|
628
|
+
* Launch a new Chrome instance and connect to it.
|
|
629
|
+
*
|
|
630
|
+
* Automatically detects Chrome, Brave, Edge, or Chromium on the system.
|
|
631
|
+
* Creates a dedicated browser profile to avoid conflicts with your daily browser.
|
|
632
|
+
*
|
|
633
|
+
* @param opts - Launch options (headless, executablePath, cdpPort, etc.)
|
|
634
|
+
* @returns A connected BrowserClaw instance
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```ts
|
|
638
|
+
* // Default: visible Chrome window
|
|
639
|
+
* const browser = await BrowserClaw.launch();
|
|
640
|
+
*
|
|
641
|
+
* // Headless mode
|
|
642
|
+
* const browser = await BrowserClaw.launch({ headless: true });
|
|
643
|
+
*
|
|
644
|
+
* // Specific browser
|
|
645
|
+
* const browser = await BrowserClaw.launch({
|
|
646
|
+
* executablePath: '/usr/bin/google-chrome',
|
|
647
|
+
* });
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
static launch(opts?: LaunchOptions): Promise<BrowserClaw>;
|
|
651
|
+
/**
|
|
652
|
+
* Connect to an already-running Chrome instance via its CDP endpoint.
|
|
653
|
+
*
|
|
654
|
+
* The Chrome instance must have been started with `--remote-debugging-port`.
|
|
655
|
+
*
|
|
656
|
+
* @param cdpUrl - CDP endpoint URL (e.g. `'http://localhost:9222'`)
|
|
657
|
+
* @returns A connected BrowserClaw instance
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* // Chrome started with: chrome --remote-debugging-port=9222
|
|
662
|
+
* const browser = await BrowserClaw.connect('http://localhost:9222');
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
static connect(cdpUrl: string, opts?: ConnectOptions): Promise<BrowserClaw>;
|
|
666
|
+
/**
|
|
667
|
+
* Open a URL in a new tab and return the page handle.
|
|
668
|
+
*
|
|
669
|
+
* @param url - URL to navigate to
|
|
670
|
+
* @returns A CrawlPage for the new tab
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* ```ts
|
|
674
|
+
* const page = await browser.open('https://example.com');
|
|
675
|
+
* const { snapshot, refs } = await page.snapshot();
|
|
676
|
+
* ```
|
|
677
|
+
*/
|
|
678
|
+
open(url: string): Promise<CrawlPage>;
|
|
679
|
+
/**
|
|
680
|
+
* Get a CrawlPage handle for the currently active tab.
|
|
681
|
+
*
|
|
682
|
+
* @returns CrawlPage for the first/active page
|
|
683
|
+
*/
|
|
684
|
+
currentPage(): Promise<CrawlPage>;
|
|
685
|
+
/**
|
|
686
|
+
* List all open tabs.
|
|
687
|
+
*
|
|
688
|
+
* @returns Array of tab information objects
|
|
689
|
+
*/
|
|
690
|
+
tabs(): Promise<BrowserTab[]>;
|
|
691
|
+
/**
|
|
692
|
+
* Bring a tab to the foreground.
|
|
693
|
+
*
|
|
694
|
+
* @param targetId - CDP target ID of the tab (from `tabs()` or `page.id`)
|
|
695
|
+
*/
|
|
696
|
+
focus(targetId: string): Promise<void>;
|
|
697
|
+
/**
|
|
698
|
+
* Close a tab.
|
|
699
|
+
*
|
|
700
|
+
* @param targetId - CDP target ID of the tab to close
|
|
701
|
+
*/
|
|
702
|
+
close(targetId: string): Promise<void>;
|
|
703
|
+
/**
|
|
704
|
+
* Get a CrawlPage handle for a specific tab by its target ID.
|
|
705
|
+
*
|
|
706
|
+
* Unlike `open()`, this doesn't create a new tab — it wraps an existing one.
|
|
707
|
+
*
|
|
708
|
+
* @param targetId - CDP target ID of the tab
|
|
709
|
+
* @returns CrawlPage for the specified tab
|
|
710
|
+
*/
|
|
711
|
+
page(targetId: string): CrawlPage;
|
|
712
|
+
/** The CDP endpoint URL for this browser connection. */
|
|
713
|
+
get url(): string;
|
|
714
|
+
/**
|
|
715
|
+
* Stop the browser and clean up all resources.
|
|
716
|
+
*
|
|
717
|
+
* If the browser was launched by `BrowserClaw.launch()`, the Chrome process
|
|
718
|
+
* will be terminated. If connected via `BrowserClaw.connect()`, only the
|
|
719
|
+
* Playwright connection is closed.
|
|
720
|
+
*/
|
|
721
|
+
stop(): Promise<void>;
|
|
722
|
+
}
|