Repository navigation
Expand file tree
/
Copy pathbrowsers.ts
More file actions
2846 lines (2502 loc) · 90.3 KB
/
Copy pathbrowsers.ts
File metadata and controls
2846 lines (2502 loc) · 90.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import type { RequestInfo } from '../../internal/builtin-types';
import { APIResource } from '../../core/resource';
import * as Shared from '../shared';
import * as ComputerAPI from './computer';
import {
Computer,
ComputerBatchParams,
ComputerCaptureScreenshotParams,
ComputerClickMouseParams,
ComputerDragMouseParams,
ComputerGetMousePositionResponse,
ComputerMoveMouseParams,
ComputerPressKeyParams,
ComputerReadClipboardResponse,
ComputerScrollParams,
ComputerSetCursorVisibilityParams,
ComputerSetCursorVisibilityResponse,
ComputerTypeTextParams,
ComputerWriteClipboardParams,
} from './computer';
import * as LiveViewAPI from './live-view';
import {
BrowserLiveView,
BrowserLiveViewRequest,
BrowserLiveViewScope,
LiveView,
LiveViewCreateParams,
} from './live-view';
import * as LogsAPI from './logs';
import { LogStreamParams, Logs } from './logs';
import * as ProcessAPI from './process';
import {
Process,
ProcessExecParams,
ProcessExecResponse,
ProcessKillParams,
ProcessKillResponse,
ProcessResizeParams,
ProcessResizeResponse,
ProcessSpawnParams,
ProcessSpawnResponse,
ProcessStatusParams,
ProcessStatusResponse,
ProcessStdinParams,
ProcessStdinResponse,
ProcessStdoutStreamParams,
ProcessStdoutStreamResponse,
} from './process';
import * as ReplaysAPI from './replays';
import {
ReplayDownloadParams,
ReplayListResponse,
ReplayStartParams,
ReplayStartResponse,
ReplayStopParams,
Replays,
} from './replays';
import * as TelemetryAPI from './telemetry';
import {
BrowserAPICallEvent,
BrowserCallStack,
BrowserCaptchaChallengeResultEvent,
BrowserCaptchaSolveResultEvent,
BrowserCaptchaSolveStartedEvent,
BrowserCdpCommandEvent,
BrowserCdpCommandMethod,
BrowserCdpConnectEvent,
BrowserCdpDisconnectEvent,
BrowserConsoleErrorEvent,
BrowserConsoleLogEvent,
BrowserEventContext,
BrowserEventSource,
BrowserHTTPHeaders,
BrowserInteractionClickEvent,
BrowserInteractionKeyEvent,
BrowserInteractionScrollSettledEvent,
BrowserLiveViewConnectEvent,
BrowserLiveViewDisconnectEvent,
BrowserMonitorDisconnectedEvent,
BrowserMonitorInitFailedEvent,
BrowserMonitorReconnectFailedEvent,
BrowserMonitorReconnectedEvent,
BrowserMonitorScreenshotEvent,
BrowserNetworkIdleEvent,
BrowserNetworkLoadingFailedEvent,
BrowserNetworkRequestEvent,
BrowserNetworkResponseEvent,
BrowserPageCrashedEvent,
BrowserPageDomContentLoadedEvent,
BrowserPageLayoutSettledEvent,
BrowserPageLayoutShiftEvent,
BrowserPageLcpEvent,
BrowserPageLoadEvent,
BrowserPageNavigationEvent,
BrowserPageNavigationSettledEvent,
BrowserPageTabOpenedEvent,
BrowserPlatformAPICallEvent,
BrowserProxyErrorEvent,
BrowserServiceCrashedEvent,
BrowserSystemOomKillEvent,
BrowserTelemetryCategoriesConfig,
BrowserTelemetryCategoryConfig,
BrowserTelemetryCdpControlConfig,
BrowserTelemetryConfig,
BrowserTelemetryControlConfig,
BrowserTelemetryEvent,
BrowserTelemetryExportConfig,
BrowserTelemetryOtlpExportConfig,
BrowserTelemetryStorageConfig,
Telemetry as TelemetryAPITelemetry,
TelemetryEventsParams,
TelemetryEventsResponse,
TelemetryEventsResponsesOffsetPagination,
TelemetryStreamParams,
TelemetryStreamResponse,
} from './telemetry';
import * as FsAPI from './fs/fs';
import {
FCreateDirectoryParams,
FDeleteDirectoryParams,
FDeleteFileParams,
FDownloadDirZipParams,
FFileInfoParams,
FFileInfoResponse,
FListFilesParams,
FListFilesResponse,
FMoveParams,
FReadFileParams,
FSetFilePermissionsParams,
FUploadParams,
FUploadZipParams,
FWriteFileParams,
Fs,
} from './fs/fs';
import * as PlaywrightAPI from './playwright/playwright';
import {
ExecutorLimitError,
Playwright,
PlaywrightExecuteParams,
PlaywrightExecuteResponse,
Tab,
} from './playwright/playwright';
import * as WebmcpAPI from './webmcp/webmcp';
import {
CustomToolSource,
InvocationFailure,
InvocationResult,
InvokeRequest,
Tool,
ToolAnnotations,
ToolFrame,
ToolMetadata,
ToolSource,
ToolsResponse,
Webmcp,
WebmcpInvokeToolParams,
WebmcpListToolsParams,
} from './webmcp/webmcp';
import { APIPromise } from '../../core/api-promise';
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../../core/pagination';
import { type Uploadable } from '../../core/uploads';
import { buildHeaders } from '../../internal/headers';
import { RequestOptions } from '../../internal/request-options';
import { multipartFormRequestOptions } from '../../internal/uploads';
import { path } from '../../internal/utils/path';
import { browserFetch, type BrowserFetchInit } from '../../lib/browser-fetch';
export class Browsers extends APIResource {
telemetry: TelemetryAPI.Telemetry = new TelemetryAPI.Telemetry(this._client);
liveView: LiveViewAPI.LiveView = new LiveViewAPI.LiveView(this._client);
replays: ReplaysAPI.Replays = new ReplaysAPI.Replays(this._client);
fs: FsAPI.Fs = new FsAPI.Fs(this._client);
process: ProcessAPI.Process = new ProcessAPI.Process(this._client);
logs: LogsAPI.Logs = new LogsAPI.Logs(this._client);
computer: ComputerAPI.Computer = new ComputerAPI.Computer(this._client);
playwright: PlaywrightAPI.Playwright = new PlaywrightAPI.Playwright(this._client);
webmcp: WebmcpAPI.Webmcp = new WebmcpAPI.Webmcp(this._client);
/**
* Create a new browser session from within an action.
*
* @example
* ```ts
* const browser = await client.browsers.create();
* ```
*/
create(
body: BrowserCreateParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<BrowserCreateResponse> {
return this._client.post('/browsers', { body, ...options });
}
/**
* Get information about a browser session.
*
* @example
* ```ts
* const browser = await client.browsers.retrieve(
* 'htzv5orfit78e1m2biiifpbv',
* );
* ```
*/
retrieve(
idOrName: string,
query: BrowserRetrieveParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<BrowserRetrieveResponse> {
return this._client.get(path`/browsers/${idOrName}`, { query, ...options });
}
/**
* Update a browser session.
*
* @example
* ```ts
* const browser = await client.browsers.update(
* 'htzv5orfit78e1m2biiifpbv',
* );
* ```
*/
update(
idOrName: string,
body: BrowserUpdateParams,
options?: RequestOptions,
): APIPromise<BrowserUpdateResponse> {
return this._client.patch(path`/browsers/${idOrName}`, { body, ...options });
}
/**
* List all browser sessions with pagination support. Use status parameter to
* filter by session state.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const browserListResponse of client.browsers.list()) {
* // ...
* }
* ```
*/
list(
query: BrowserListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<BrowserListResponsesOffsetPagination, BrowserListResponse> {
return this._client.getAPIList('/browsers', OffsetPagination<BrowserListResponse>, { query, ...options });
}
/**
* Sends an HTTP request through Chrome's HTTP request stack, inheriting the
* browser's TLS fingerprint, cookies, proxy configuration, and headers. Returns a
* structured JSON response with status, headers, body, and timing.
*
* @example
* ```ts
* const response = await client.browsers.curl(
* 'htzv5orfit78e1m2biiifpbv',
* { url: 'url' },
* );
* ```
*/
curl(idOrName: string, body: BrowserCurlParams, options?: RequestOptions): APIPromise<BrowserCurlResponse> {
return this._client.post(path`/browsers/${idOrName}/curl`, { body, ...options });
}
/**
* Issues an HTTP request through the browser VM network stack, routing directly
* to the browser's `base_url` using the shared browser route cache.
*/
fetch(id: string, input: RequestInfo | URL, init?: BrowserFetchInit): Promise<Response> {
return browserFetch(this._client, id, input, init);
}
/**
* Delete a browser session by ID or name
*
* @example
* ```ts
* await client.browsers.deleteByID(
* 'htzv5orfit78e1m2biiifpbv',
* );
* ```
*/
deleteByID(idOrName: string, options?: RequestOptions): APIPromise<void> {
return this._client.delete(path`/browsers/${idOrName}`, {
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* Loads one or more unpacked extensions using live CDP activation when eligible.
* Chromium restarts when enterprise policy requires it or live activation fails.
*
* @example
* ```ts
* await client.browsers.loadExtensions(
* 'htzv5orfit78e1m2biiifpbv',
* {
* extensions: [
* {
* name: 'name',
* zip_file: fs.createReadStream('path/to/file'),
* },
* ],
* },
* );
* ```
*/
loadExtensions(
idOrName: string,
body: BrowserLoadExtensionsParams,
options?: RequestOptions,
): APIPromise<void> {
return this._client.post(
path`/browsers/${idOrName}/extensions`,
multipartFormRequestOptions(
{ body, ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]) },
this._client,
),
);
}
/**
* Execute JavaScript in a persistent Node.js runtime inside the browser VM.
* Top-level bindings, closures, mutations, and dynamically imported modules
* persist across calls until the REPL is reset or replaced. Start with
* `repl.help()` to list available methods, or call `repl.help("click")` for
* detailed help.
*
* Expression values are ignored. Emit ordered text or image output with
* `repl.write(...)`, console methods, or `repl.emitImage(...)`. The runtime also
* exposes browser-control helpers, WebMCP, Patchright, Playwright, and raw CDP.
*
* Executions are serialized. A timeout, crash, OOM, or protocol failure terminates
* the REPL and changes its `repl_id`. This is unrestricted code execution inside
* the browser VM and is not sandboxed.
*
* @example
* ```ts
* const browserReplResult = await client.browsers.repl(
* 'htzv5orfit78e1m2biiifpbv',
* { code: 'code' },
* );
* ```
*/
repl(idOrName: string, body: BrowserReplParams, options?: RequestOptions): APIPromise<BrowserReplResult> {
return this._client.post(path`/browsers/${idOrName}/repl`, { body, ...options });
}
/**
* Saves the running browser's current user-data state to an existing or new
* profile without ending the browser session.
*
* Saving restarts the browser. Active CDP and WebDriver connections are closed and
* must reconnect, and WebDriver clients must create a new session. Open tabs are
* restored, but pages reload and in-memory page state is lost. The browser is
* stopped only while its user data is copied; this request returns once the
* restarted browser accepts CDP connections again and the profile has been
* uploaded. Caches, Service Worker storage and Google Drive IndexedDB data are
* left out of the saved profile but kept in the running browser.
*
* This does not attach the destination profile to the browser or change its
* save_changes setting. Active browsers that already loaded the destination
* profile keep their in-memory state. Pools with refresh_on_profile_update enabled
* flush idle sessions and replenish them from the new snapshot; other browsers
* receive it the next time they load the profile. When saves made with this
* endpoint to the same profile overlap, the save that started most recently wins,
* even if an earlier one finishes later. The automatic save at the end of a
* session whose profile has save_changes enabled is ordered against these saves by
* when each finishes.
*
* A successful save restarts the browser's inactivity timeout (timeout_seconds). A
* failed save leaves it unchanged.
*
* Returns 409 when the browser is no longer active, when a pooled browser was
* released or reacquired after the request was made (browser_lease_changed), or
* when the browser is briefly unable to accept a save (browser_busy), in which
* case the request can be retried.
*
* @example
* ```ts
* const profile = await client.browsers.saveProfile(
* 'htzv5orfit78e1m2biiifpbv',
* );
* ```
*/
saveProfile(
idOrName: string,
body: BrowserSaveProfileParams,
options?: RequestOptions,
): APIPromise<Profile> {
return this._client.post(path`/browsers/${idOrName}/profiles`, { body, ...options });
}
}
export type BrowserListResponsesOffsetPagination = OffsetPagination<BrowserListResponse>;
export type ProfilesOffsetPagination = OffsetPagination<Profile>;
export interface BrowserAllowlistState {
/**
* Opaque revision to pass as network.expected_allowlist_revision on an update.
*/
revision: string;
/**
* Revision against which that mutation was accepted; reuse it when retrying the
* mutation.
*/
base_revision?: string;
/**
* ID of the last conditional allowlist update saved on this browser.
*/
mutation_id?: string;
}
/**
* Automatic CAPTCHA solving configuration.
*/
export interface BrowserCaptchaSolver {
/**
* Whether the browser automatically solves CAPTCHAs.
*/
enabled: boolean;
}
export interface BrowserCost {
/**
* Pending means the billing checkpoint or rate calculation is not ready;
* unavailable means the session cannot currently be priced safely.
*/
status: 'provisional' | 'pending' | 'unavailable';
/**
* Time of the live uptime read or durable billing checkpoint. A running or
* recently deleted session may accrue additional usage.
*/
as_of?: string;
/**
* Gross provisional USD browser-meter cost before credits, subscriptions, tax, and
* adjustments. Present only with provisional status, including zero for a
* completed zero-uptime session. Not an invoice total.
*/
estimated_usage_spend_usd?: string;
}
/**
* Overrides for browser attributes presented to websites.
*/
export interface BrowserFingerprint {
/**
* Operating system the browser reports to websites.
*/
os: 'linux' | 'macos';
}
export interface BrowserLocation {
/**
* Effective canonical BCP 47 formatting locale selected for the browser session.
*/
locale: string;
/**
* Where one effective browser location field came from. `override` is set
* explicitly on the session; `default` comes from the browser's region.
*/
locale_source: BrowserLocationSource;
/**
* Effective IANA timezone selected for the browser session.
*/
timezone: string;
/**
* Where one effective browser location field came from. `override` is set
* explicitly on the session; `default` comes from the browser's region.
*/
timezone_source: BrowserLocationSource;
}
export interface BrowserLocationRequest {
/**
* Session-only supported canonical BCP 47 locale override. Omit to use the default
* for the browser's region.
*/
locale?: string;
/**
* Session-only IANA timezone override. Omit to use the default for the browser's
* region.
*/
timezone?: string;
}
/**
* Where one effective browser location field came from. `override` is set
* explicitly on the session; `default` comes from the browser's region.
*/
export type BrowserLocationSource = 'override' | 'default';
/**
* Omit a field to leave it unchanged, set a string override, or set null to clear
* the override and use the default for the browser's region.
*/
export interface BrowserLocationUpdateRequest {
/**
* Session-only supported canonical BCP 47 locale override. Null clears the
* override and uses the browser region's default.
*/
locale?: string | null;
/**
* Session-only IANA timezone override. Null clears the override and uses the
* browser region's default.
*/
timezone?: string | null;
}
/**
* Memory allocated to the browser session.
*/
export type BrowserMemory = '1GiB' | '2GiB' | '4GiB' | '6GiB' | '8GiB' | '12GiB' | '16GiB';
/**
* Memory requested for a non-GPU browser. Headless browsers support 1GiB
* (default), 2GiB, or 4GiB; headful browsers support 8GiB (default) or 16GiB.
*/
export type BrowserMemoryRequest = '1GiB' | '2GiB' | '4GiB' | '8GiB' | '16GiB';
/**
* Network configuration for a browser session or browser pool.
*/
export interface BrowserNetworkConfig {
/**
* Egress allowlist for a browser session: the only destinations the browser may
* reach through Kernel-managed egress. Any other destination is refused with a 403
* whose X-Kernel-Proxy-Error header is network_policy_denied, so pages cannot load
* or send data to unlisted hosts, including with fetch() and WebSockets. Omit the
* field for unfiltered egress; an empty list is invalid. The allowlist applies
* from the browser's first request, and start_url must be allowed by it. Entries
* are exact hostnames ("example.com"), one leading "_." wildcard that matches
* subdomains at any depth but not the domain itself ("_.example.com" matches
* api.example.com, not example.com), public IPv4 addresses ("8.8.8.8"), bracketed
* public IPv6 addresses ("[2001:4860:4860::8888]"), or public CIDR ranges in
* canonical form ("8.8.4.0/24", "2001:4860::/32"). IP and CIDR entries only match
* destinations written as an IP address, never hostnames that resolve into the
* range. Entries cannot include ports, paths, or schemes, and match every port on
* their host. Wildcards over a public suffix ("_.com", "_.github.io") and private
* or reserved IP ranges are rejected, as are entries that overlap private_hosts.
* Enforced at Kernel's egress proxy only: destinations in private_hosts, and
* processes in the browser VM that do not use the browser's proxy, are not
* filtered, and Kernel's own control traffic is always allowed. Can be replaced or
* removed while the session runs with PATCH /browsers/{id_or_name}, but not added
* to a browser created without one. Supported on browser pools and their leased
* browsers. Per-lease changes are reset to the pool's allowlist on release. If a
* lessee removes the allowlist and the pool still requires one, the browser is
* replaced on release rather than given an allowlist again. Requires proxy v3.
*/
allowed_hosts?: Array<string>;
/**
* Concurrency metadata for a browser's saved allowlist configuration. Browser
* pools omit it. This remains present after removal so an uncertain removal can be
* retried. It does not prove proxy or VM application completed. Do not include it
* in creation or pool updates.
*/
allowlist_state?: BrowserAllowlistState;
/**
* Destinations the browser reaches directly through the session's own network
* instead of through Kernel-managed egress — for private hosts reachable over a
* VPN or tunnel the session has joined (e.g. a Tailscale tailnet). By default,
* private IP ranges already route directly: RFC1918 (10.0.0.0/8, 172.16.0.0/12,
* 192.168.0.0/16), CGNAT/Tailscale (100.64.0.0/10), and IPv6 ULA (fc00::/7). An
* explicitly supplied list replaces those defaults with exactly the entries given,
* and an empty list ([]) disables them so all traffic uses Kernel-managed egress;
* omit private_hosts to keep the defaults. Entries are hostname patterns
* ("_.example.ts.net", "preview.internal") or IP/CIDR literals ("100.64.0.0/10",
* "10.1.30.63"). IP and CIDR entries only match URLs written with a literal IP
* address; they never match hostnames that resolve into the range, so private DNS
* names need a hostname entry even when they resolve inside the default ranges.
* CIDRs must be in canonical masked form (host bits zero), and only the private
* ranges listed above are accepted; public, loopback, link-local, and unspecified
* ranges are rejected. Exact IPv6 addresses must be bracketed ("[fd00::1]"); IPv6
* CIDR ranges are unbracketed ("fd00::/8"). Wildcards are limited to one leading
* "_." over a suffix with at least two labels that is not a public suffix (so
* "_.co.uk" or "_.ts.net" are rejected, while "\*.example.ts.net" is accepted).
* Hostname and IP entries may carry a port; CIDR ranges may not. Hostname entries
* are not resolved during validation, so callers must ensure they identify private
* destinations. Not related to a proxy's bypass_hosts, which selects between
* upstream-proxy and Kernel-managed direct egress and cannot reach into a VPN.
*/
private_hosts?: Array<string>;
/**
* Per-destination proxy routes for a browser session. A destination hostname is
* matched against every route's hosts, regardless of port; route order does not
* matter. An exact hostname beats a wildcard, and a longer wildcard suffix beats a
* shorter one (for a.b.example.com: "a.b.example.com" > "_.b.example.com" >
* "_.example.com"). A host pattern may appear in only one route. "\*.example.com"
* matches subdomains only, not example.com. A matched request selects the route's
* proxy instead of the session's top-level proxy (including mode: direct); the
* route proxy's own bypass_hosts still apply. If the route proxy becomes
* unavailable, matched requests fail closed without falling back. Requests that
* match no route use the session's default egress from the top-level proxy field
* (or the browser default when proxy is omitted: stealth proxy or direct egress).
* Routes apply from the start of the session, including to start_url and other
* traffic during browser setup. Setting routes requires proxy v3. Browser pools
* also support these routes.
*/
proxy_routes?: Array<BrowserNetworkConfig.ProxyRoute>;
}
export namespace BrowserNetworkConfig {
export interface ProxyRoute {
/**
* Exact hostnames or leading \*. wildcard patterns (subdomains only); patterns
* cannot include ports, and matching ignores the destination port. Hosts not
* matched by any route use the session's top-level proxy (or the browser default
* when proxy is omitted).
*/
hosts: Array<string>;
/**
* Select an active non-direct proxy by ID or name. Responses always use ID.
*/
proxy: ProxyRoute.Proxy;
}
export namespace ProxyRoute {
/**
* Select an active non-direct proxy by ID or name. Responses always use ID.
*/
export interface Proxy {
id?: string;
name?: string;
}
}
}
/**
* Network configuration changes for a running browser session. Other network
* settings can only be set at creation.
*/
export interface BrowserNetworkUpdate {
/**
* Replaces the session's egress allowlist, using the same entry rules as
* network.allowed_hosts on create. Only an allowlist the browser was created with
* can be changed: a browser created without one can't be given one, and an
* allowlist removed with null can't be added back. Omit to leave the allowlist
* unchanged, or set to null to remove it and return to unfiltered egress; an empty
* list is invalid. The new list applies without restarting the browser: new
* requests to destinations it no longer allows are refused within a few seconds,
* and open connections to them are closed within about 30 seconds, or up to 10
* minutes during a Kernel deploy. Connections to destinations it still allows,
* such as WebSockets, stay open. A start_url in the same request must be allowed
* by the updated list, and is loaded only after the list takes effect. Requires a
* browser created with proxy v3. Supported on leased pooled browsers; the pool's
* allowlist is restored before reuse, or the browser is destroyed if it cannot be
* safely restored. If the request fails, retry it: the new list may already apply
* to some requests.
*/
allowed_hosts?: Array<string> | null;
/**
* The network.allowlist_state.revision from the browser's last saved snapshot.
* Supply together with mutation_id to opt into conditional allowlist updates. The
* revision is checked atomically with the configuration write. A stale request
* returns 409 stale_network without changing the allowlist. A GET alone does not
* fence an earlier unfinished PATCH.
*/
expected_allowlist_revision?: string;
/**
* A unique ID for this allowlist update, supplied together with
* expected_allowlist_revision. Reuse both values and the identical allowed_hosts
* payload when retrying an uncertain update. If it is still the current mutation,
* the retry finishes proxy and VM application without creating another revision. A
* superseded mutation returns 409 stale_network. These fields guard only
* network.allowed_hosts, not other browser update fields.
*/
mutation_id?: string;
}
/**
* Operating system of the browser's host.
*/
export type BrowserOs = 'linux' | 'macos';
/**
* Host platform settings for the browser session.
*/
export interface BrowserPlatform {
/**
* Operating system of the browser's host.
*/
os: BrowserOs;
}
/**
* Browser pool this session was acquired from, if any.
*/
export interface BrowserPoolRef {
/**
* Browser pool ID
*/
id: string;
/**
* Browser pool name, if set
*/
name?: string;
}
/**
* Resolved proxy configuration for a browser session. Selected proxies are
* returned by stable ID.
*/
export interface BrowserProxy {
/**
* Selected proxy ID.
*/
id?: string;
/**
* Proxy egress mode. direct forces no proxy. default uses Kernel's default stealth
* proxy for browsers with CAPTCHA solving enabled, including stealth browsers, or
* direct egress otherwise. default is primarily useful on browser update to
* restore the browser default after selected-proxy egress.
*/
mode?: BrowserProxyMode;
/**
* Selected proxy name.
*/
name?: string;
}
/**
* Browser proxy configuration. Provide exactly one of mode, id, or name; an empty
* object is invalid. Set mode to direct for no proxy. Set mode to default to use
* Kernel's default stealth proxy for browsers with CAPTCHA solving enabled,
* including stealth browsers, or direct egress otherwise. Select id or name to use
* that proxy. The selected proxy must be in the same project as the browser. Names
* must match exactly one active proxy; use id for stable references. Proxy
* configuration changes only egress and does not change CAPTCHA solver behavior. A
* browser using mode=direct keeps the CAPTCHA solver if it was enabled. When proxy
* is omitted on browser creation, stealth browsers use Kernel's default stealth
* proxy and other browsers use direct egress. When omitted on update, the current
* configuration is unchanged.
*/
export interface BrowserProxyConfig {
/**
* Proxy ID.
*/
id?: string;
/**
* Proxy egress mode. direct forces no proxy. default uses Kernel's default stealth
* proxy for browsers with CAPTCHA solving enabled, including stealth browsers, or
* direct egress otherwise. default is primarily useful on browser update to
* restore the browser default after selected-proxy egress.
*/
mode?: BrowserProxyMode;
/**
* Proxy name. Must match exactly one active proxy in the project.
*/
name?: string;
}
/**
* Proxy egress mode. direct forces no proxy. default uses Kernel's default stealth
* proxy for browsers with CAPTCHA solving enabled, including stealth browsers, or
* direct egress otherwise. default is primarily useful on browser update to
* restore the browser default after selected-proxy egress.
*/
export type BrowserProxyMode = 'direct' | 'default';
/**
* Ordered discriminated union of Browser REPL output items.
*/
export type BrowserReplContent = BrowserReplTextContent | BrowserReplImageContent;
export interface BrowserReplImageContent {
data_b64: string;
mime_type: string;
type: 'image';
}
/**
* Request to execute code in the persistent Browser REPL.
*/
export interface BrowserReplRequest {
/**
* JavaScript evaluated in a persistent Node.js runtime. Top-level bindings persist
* until the browser VM's API process exits, the REPL is reset, or the REPL is
* terminated after a crash or timeout. Static top-level imports are unsupported;
* use dynamic `import()`. Expression values are ignored; emit output with
* `repl.write(...)`, console methods, or `repl.emitImage(...)`. May be empty only
* when `reset` is true.
*/
code: string;
/**
* Terminate the current REPL, start a fresh one, and then evaluate code.
*/
reset?: boolean;
/**
* Maximum execution time in seconds. Default is 60.
*/
timeout_sec?: number;
}
/**
* Result of Browser REPL code execution.
*/
export interface BrowserReplResult {
/**
* CUID2 identifying the exact state-holding REPL process used for this execution.
* Stable across calls and Chromium reconnects; changes after an API restart,
* explicit reset, execution timeout, or REPL crash.
*/
repl_id: string;
/**
* Whether the code executed successfully.
*/
success: boolean;
/**
* Optional ordered text/image output produced by the execution.
*/
content?: Array<BrowserReplContent>;
/**
* True if text or image output was dropped or truncated due to response limits.
*/
content_truncated?: boolean;
/**
* Wall-clock execution time in milliseconds.
*/
duration_ms?: number;
/**
* Error message if execution failed.
*/
error?: string;
/**
* True if the REPL identified by `repl_id` was terminated by this request. The
* next request lazily starts a fresh REPL with a new `repl_id`.
*/
repl_terminated?: boolean;
/**
* Stack trace if execution failed.
*/
stack?: string;
}
export interface BrowserReplTextContent {
/**
* `write` is emitted by `repl.write`; `stdout` and `stderr` are emitted by console
* methods.
*/
channel: 'write' | 'stdout' | 'stderr';
text: string;
type: 'text';
}
/**
* Session usage metrics.
*/
export interface BrowserUsage {
/**
* Time in milliseconds the session was actively running.
*/
uptime_ms: number;
}
/**
* Video memory (VRAM) of a GPU browser session. 3GiB sessions have 4 vCPU and 6GiB
* memory. 6GiB sessions have 8 vCPU and 12GiB memory. 2GiB and 4GiB are deprecated
* aliases for 3GiB and 6GiB: they are accepted on create and never returned.
*/
export type BrowserVideoMemory = '3GiB' | '6GiB' | '2GiB' | '4GiB';
/**
* Browser profile metadata.
*/
export interface Profile {
/**
* Unique identifier for the profile
*/
id: string;
/**
* Timestamp when the profile was created
*/
created_at: string;
/**
* Timestamp when the profile was last used
*/
last_used_at?: string;
/**
* Optional, easier-to-reference name for the profile
*/
name?: string | null;
/**
* Timestamp when the profile was last updated
*/
updated_at?: string;
}
/**
* Destination profile for a snapshot of the running browser. Provide either id or
* name. An id must identify an existing profile. A name overwrites the matching
* profile in the browser's project, or creates it when no matching profile exists.
*/
export interface SaveProfileRequest {
/**
* Existing profile ID to overwrite.
*/
id?: string;
/**
* Profile name to overwrite or create.
*/
name?: string;
}
/**
* User-defined key-value tags.
*/
export type Tags = { [key: string]: string };
/**
* Reference to a project-scoped vault. Provide exactly one of id or name.
*/
export interface VaultReference {
id?: string;
name?: string;
}
export interface BrowserCreateResponse {
/**
* Automatic CAPTCHA solving configuration.
*/
captcha_solver: BrowserCaptchaSolver;
/**
* Websocket URL for Chrome DevTools Protocol connections to the browser session
*/
cdp_ws_url: string;
/**
* When the browser session was created.
*/
created_at: string;
/**
* Whether the browser session is running in headless mode.
*/
headless: boolean;
/**
* Memory allocated to the browser session.
*/
memory: BrowserMemory;
/**
* Geographic region of the browser session. Fixed once the session is created.
*/
region: 'us-east' | 'us-west' | 'eu-west' | 'ap-southeast';
/**
* Unique identifier for the browser session
*/
session_id: string;
/**
* @deprecated Whether the browser session has CAPTCHA solving enabled, in which
* case proxy.mode=default uses Kernel's default stealth proxy. A browser created