3636 BrowserMemoryRequest ,
3737 browser_curl_params ,
3838 browser_list_params ,
39+ browser_repl_params ,
3940 browser_create_params ,
4041 browser_update_params ,
4142 browser_retrieve_params ,
9596from ...pagination import SyncOffsetPagination , AsyncOffsetPagination
9697from ..._base_client import AsyncPaginator , make_request_options
9798from ...types .tags_param import TagsParam
99+ from ...types .browser_repl_result import BrowserReplResult
98100from ...types .browser_curl_response import BrowserCurlResponse
99101from ...types .browser_list_response import BrowserListResponse
100102from ...types .vault_reference_param import VaultReferenceParam
118120
119121
120122class BrowsersResource (SyncAPIResource ):
121- """Create and manage browser sessions."""
122-
123123 @cached_property
124124 def telemetry (self ) -> TelemetryResource :
125125 """
@@ -753,10 +753,75 @@ def load_extensions(
753753 cast_to = NoneType ,
754754 )
755755
756+ def repl (
757+ self ,
758+ id_or_name : str ,
759+ * ,
760+ code : str ,
761+ reset : bool | Omit = omit ,
762+ timeout_sec : int | Omit = omit ,
763+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
764+ # The extra values given here take precedence over values defined on the client or passed to this method.
765+ extra_headers : Headers | None = None ,
766+ extra_query : Query | None = None ,
767+ extra_body : Body | None = None ,
768+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
769+ ) -> BrowserReplResult :
770+ """
771+ Execute JavaScript in a persistent Node.js runtime inside the browser VM.
772+ Top-level bindings, closures, mutations, and dynamically imported modules
773+ persist across calls until the REPL is reset or replaced. Start with
774+ `repl.help()` to list available methods, or call `repl.help("click")` for
775+ detailed help.
776+
777+ Expression values are ignored. Emit ordered text or image output with
778+ `repl.write(...)`, console methods, or `repl.emitImage(...)`. The runtime also
779+ exposes browser-control helpers, WebMCP, Patchright, Playwright, and raw CDP.
780+
781+ Executions are serialized. A timeout, crash, OOM, or protocol failure terminates
782+ the REPL and changes its `repl_id`. This is unrestricted code execution inside
783+ the browser VM and is not sandboxed.
784+
785+ Args:
786+ code: JavaScript evaluated in a persistent Node.js runtime. Top-level bindings persist
787+ until the browser VM's API process exits, the REPL is reset, or the REPL is
788+ terminated after a crash or timeout. Static top-level imports are unsupported;
789+ use dynamic `import()`. Expression values are ignored; emit output with
790+ `repl.write(...)`, console methods, or `repl.emitImage(...)`. May be empty only
791+ when `reset` is true.
792+
793+ reset: Terminate the current REPL, start a fresh one, and then evaluate code.
794+
795+ timeout_sec: Maximum execution time in seconds. Default is 60.
796+
797+ extra_headers: Send extra headers
798+
799+ extra_query: Add additional query parameters to the request
800+
801+ extra_body: Add additional JSON properties to the request
802+
803+ timeout: Override the client-level default timeout for this request, in seconds
804+ """
805+ if not id_or_name :
806+ raise ValueError (f"Expected a non-empty value for `id_or_name` but received { id_or_name !r} " )
807+ return self ._post (
808+ path_template ("/browsers/{id_or_name}/repl" , id_or_name = id_or_name ),
809+ body = maybe_transform (
810+ {
811+ "code" : code ,
812+ "reset" : reset ,
813+ "timeout_sec" : timeout_sec ,
814+ },
815+ browser_repl_params .BrowserReplParams ,
816+ ),
817+ options = make_request_options (
818+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
819+ ),
820+ cast_to = BrowserReplResult ,
821+ )
756822
757- class AsyncBrowsersResource (AsyncAPIResource ):
758- """Create and manage browser sessions."""
759823
824+ class AsyncBrowsersResource (AsyncAPIResource ):
760825 @cached_property
761826 def telemetry (self ) -> AsyncTelemetryResource :
762827 """
@@ -1390,6 +1455,73 @@ async def load_extensions(
13901455 cast_to = NoneType ,
13911456 )
13921457
1458+ async def repl (
1459+ self ,
1460+ id_or_name : str ,
1461+ * ,
1462+ code : str ,
1463+ reset : bool | Omit = omit ,
1464+ timeout_sec : int | Omit = omit ,
1465+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
1466+ # The extra values given here take precedence over values defined on the client or passed to this method.
1467+ extra_headers : Headers | None = None ,
1468+ extra_query : Query | None = None ,
1469+ extra_body : Body | None = None ,
1470+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
1471+ ) -> BrowserReplResult :
1472+ """
1473+ Execute JavaScript in a persistent Node.js runtime inside the browser VM.
1474+ Top-level bindings, closures, mutations, and dynamically imported modules
1475+ persist across calls until the REPL is reset or replaced. Start with
1476+ `repl.help()` to list available methods, or call `repl.help("click")` for
1477+ detailed help.
1478+
1479+ Expression values are ignored. Emit ordered text or image output with
1480+ `repl.write(...)`, console methods, or `repl.emitImage(...)`. The runtime also
1481+ exposes browser-control helpers, WebMCP, Patchright, Playwright, and raw CDP.
1482+
1483+ Executions are serialized. A timeout, crash, OOM, or protocol failure terminates
1484+ the REPL and changes its `repl_id`. This is unrestricted code execution inside
1485+ the browser VM and is not sandboxed.
1486+
1487+ Args:
1488+ code: JavaScript evaluated in a persistent Node.js runtime. Top-level bindings persist
1489+ until the browser VM's API process exits, the REPL is reset, or the REPL is
1490+ terminated after a crash or timeout. Static top-level imports are unsupported;
1491+ use dynamic `import()`. Expression values are ignored; emit output with
1492+ `repl.write(...)`, console methods, or `repl.emitImage(...)`. May be empty only
1493+ when `reset` is true.
1494+
1495+ reset: Terminate the current REPL, start a fresh one, and then evaluate code.
1496+
1497+ timeout_sec: Maximum execution time in seconds. Default is 60.
1498+
1499+ extra_headers: Send extra headers
1500+
1501+ extra_query: Add additional query parameters to the request
1502+
1503+ extra_body: Add additional JSON properties to the request
1504+
1505+ timeout: Override the client-level default timeout for this request, in seconds
1506+ """
1507+ if not id_or_name :
1508+ raise ValueError (f"Expected a non-empty value for `id_or_name` but received { id_or_name !r} " )
1509+ return await self ._post (
1510+ path_template ("/browsers/{id_or_name}/repl" , id_or_name = id_or_name ),
1511+ body = await async_maybe_transform (
1512+ {
1513+ "code" : code ,
1514+ "reset" : reset ,
1515+ "timeout_sec" : timeout_sec ,
1516+ },
1517+ browser_repl_params .BrowserReplParams ,
1518+ ),
1519+ options = make_request_options (
1520+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
1521+ ),
1522+ cast_to = BrowserReplResult ,
1523+ )
1524+
13931525
13941526class BrowsersResourceWithRawResponse :
13951527 def __init__ (self , browsers : BrowsersResource ) -> None :
@@ -1416,6 +1548,9 @@ def __init__(self, browsers: BrowsersResource) -> None:
14161548 self .load_extensions = to_raw_response_wrapper (
14171549 browsers .load_extensions ,
14181550 )
1551+ self .repl = to_raw_response_wrapper (
1552+ browsers .repl ,
1553+ )
14191554
14201555 @cached_property
14211556 def telemetry (self ) -> TelemetryResourceWithRawResponse :
@@ -1485,6 +1620,9 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None:
14851620 self .load_extensions = async_to_raw_response_wrapper (
14861621 browsers .load_extensions ,
14871622 )
1623+ self .repl = async_to_raw_response_wrapper (
1624+ browsers .repl ,
1625+ )
14881626
14891627 @cached_property
14901628 def telemetry (self ) -> AsyncTelemetryResourceWithRawResponse :
@@ -1554,6 +1692,9 @@ def __init__(self, browsers: BrowsersResource) -> None:
15541692 self .load_extensions = to_streamed_response_wrapper (
15551693 browsers .load_extensions ,
15561694 )
1695+ self .repl = to_streamed_response_wrapper (
1696+ browsers .repl ,
1697+ )
15571698
15581699 @cached_property
15591700 def telemetry (self ) -> TelemetryResourceWithStreamingResponse :
@@ -1623,6 +1764,9 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None:
16231764 self .load_extensions = async_to_streamed_response_wrapper (
16241765 browsers .load_extensions ,
16251766 )
1767+ self .repl = async_to_streamed_response_wrapper (
1768+ browsers .repl ,
1769+ )
16261770
16271771 @cached_property
16281772 def telemetry (self ) -> AsyncTelemetryResourceWithStreamingResponse :
0 commit comments