Skip to content

Commit bfd4043

Browse files
feat: [kernel-1116] browser events api integration
1 parent b1807a2 commit bfd4043

57 files changed

Lines changed: 2123 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 112
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-e564e74a7aae1744d4aa070a63c387f456c4719a48747dc6229b58a986255b65.yml
3-
openapi_spec_hash: 62beb1f20708652aaee31bbffb6cfbe9
4-
config_hash: 08d55086449943a8fec212b870061a3f
1+
configured_endpoints: 113
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-a9c7e806132001dbfbd4e8ae6c7d0935e503f457d63385fc800c862e3d064375.yml
3+
openapi_spec_hash: b048dcb0c5401bc0a301c3d30cb8ecba
4+
config_hash: 37661d89120558d34b6cc184292632f2

api.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,50 @@ Methods:
103103
- <code title="delete /browsers/{id}">client.browsers.<a href="./src/kernel/resources/browsers/browsers.py">delete_by_id</a>(id) -> None</code>
104104
- <code title="post /browsers/{id}/extensions">client.browsers.<a href="./src/kernel/resources/browsers/browsers.py">load_extensions</a>(id, \*\*<a href="src/kernel/types/browser_load_extensions_params.py">params</a>) -> None</code>
105105

106+
## Telemetry
107+
108+
Types:
109+
110+
```python
111+
from kernel.types.browsers import (
112+
BrowserCallStack,
113+
BrowserConsoleErrorEvent,
114+
BrowserConsoleLogEvent,
115+
BrowserEventContext,
116+
BrowserEventSource,
117+
BrowserHTTPHeaders,
118+
BrowserInteractionClickEvent,
119+
BrowserInteractionKeyEvent,
120+
BrowserInteractionScrollSettledEvent,
121+
BrowserMonitorDisconnectedEvent,
122+
BrowserMonitorInitFailedEvent,
123+
BrowserMonitorReconnectFailedEvent,
124+
BrowserMonitorReconnectedEvent,
125+
BrowserMonitorScreenshotEvent,
126+
BrowserNetworkIdleEvent,
127+
BrowserNetworkLoadingFailedEvent,
128+
BrowserNetworkRequestEvent,
129+
BrowserNetworkResponseEvent,
130+
BrowserPageDomContentLoadedEvent,
131+
BrowserPageLayoutSettledEvent,
132+
BrowserPageLayoutShiftEvent,
133+
BrowserPageLcpEvent,
134+
BrowserPageLoadEvent,
135+
BrowserPageNavigationEvent,
136+
BrowserPageNavigationSettledEvent,
137+
BrowserPageTabOpenedEvent,
138+
BrowserTelemetryCategoriesConfig,
139+
BrowserTelemetryCategoryConfig,
140+
BrowserTelemetryConfig,
141+
BrowserTelemetryEvent,
142+
TelemetryStreamResponse,
143+
)
144+
```
145+
146+
Methods:
147+
148+
- <code title="get /browsers/{id}/telemetry">client.browsers.telemetry.<a href="./src/kernel/resources/browsers/telemetry.py">stream</a>(id) -> <a href="./src/kernel/types/browsers/telemetry_stream_response.py">TelemetryStreamResponse</a></code>
149+
106150
## Replays
107151

108152
Types:

src/kernel/resources/browser_pools.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ def create(
110110
proxy_id: Optional proxy to associate to the browser session. Must reference a proxy
111111
belonging to the caller's org.
112112
113-
start_url: Optional URL to open when a browser is created for the pool. Navigation is
114-
best-effort, so navigation failures do not prevent the pool from filling. Reused
115-
browsers keep the page left by the previous lease.
113+
start_url: Optional URL to navigate to when a new browser is warmed into the pool.
114+
Best-effort: failures to navigate do not fail pool fill. Only applied to
115+
newly-warmed browsers; browsers reused via release/acquire keep whatever URL the
116+
previous lease left them on. Accepts any URL Chromium can resolve, including
117+
chrome:// pages.
116118
117119
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
118120
mechanisms.
@@ -259,9 +261,11 @@ def update(
259261
proxy_id: Optional proxy to associate to the browser session. Must reference a proxy
260262
belonging to the caller's org.
261263
262-
start_url: Optional URL to open when a browser is created for the pool. Navigation is
263-
best-effort, so navigation failures do not prevent the pool from filling. Reused
264-
browsers keep the page left by the previous lease.
264+
start_url: Optional URL to navigate to when a new browser is warmed into the pool.
265+
Best-effort: failures to navigate do not fail pool fill. Only applied to
266+
newly-warmed browsers; browsers reused via release/acquire keep whatever URL the
267+
previous lease left them on. Accepts any URL Chromium can resolve, including
268+
chrome:// pages.
265269
266270
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
267271
mechanisms.
@@ -584,9 +588,11 @@ async def create(
584588
proxy_id: Optional proxy to associate to the browser session. Must reference a proxy
585589
belonging to the caller's org.
586590
587-
start_url: Optional URL to open when a browser is created for the pool. Navigation is
588-
best-effort, so navigation failures do not prevent the pool from filling. Reused
589-
browsers keep the page left by the previous lease.
591+
start_url: Optional URL to navigate to when a new browser is warmed into the pool.
592+
Best-effort: failures to navigate do not fail pool fill. Only applied to
593+
newly-warmed browsers; browsers reused via release/acquire keep whatever URL the
594+
previous lease left them on. Accepts any URL Chromium can resolve, including
595+
chrome:// pages.
590596
591597
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
592598
mechanisms.
@@ -733,9 +739,11 @@ async def update(
733739
proxy_id: Optional proxy to associate to the browser session. Must reference a proxy
734740
belonging to the caller's org.
735741
736-
start_url: Optional URL to open when a browser is created for the pool. Navigation is
737-
best-effort, so navigation failures do not prevent the pool from filling. Reused
738-
browsers keep the page left by the previous lease.
742+
start_url: Optional URL to navigate to when a new browser is warmed into the pool.
743+
Best-effort: failures to navigate do not fail pool fill. Only applied to
744+
newly-warmed browsers; browsers reused via release/acquire keep whatever URL the
745+
previous lease left them on. Accepts any URL Chromium can resolve, including
746+
chrome:// pages.
739747
740748
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
741749
mechanisms.

src/kernel/resources/browsers/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
ComputerResourceWithStreamingResponse,
4949
AsyncComputerResourceWithStreamingResponse,
5050
)
51+
from .telemetry import (
52+
TelemetryResource,
53+
AsyncTelemetryResource,
54+
TelemetryResourceWithRawResponse,
55+
AsyncTelemetryResourceWithRawResponse,
56+
TelemetryResourceWithStreamingResponse,
57+
AsyncTelemetryResourceWithStreamingResponse,
58+
)
5159
from .playwright import (
5260
PlaywrightResource,
5361
AsyncPlaywrightResource,
@@ -58,6 +66,12 @@
5866
)
5967

6068
__all__ = [
69+
"TelemetryResource",
70+
"AsyncTelemetryResource",
71+
"TelemetryResourceWithRawResponse",
72+
"AsyncTelemetryResourceWithRawResponse",
73+
"TelemetryResourceWithStreamingResponse",
74+
"AsyncTelemetryResourceWithStreamingResponse",
6175
"ReplaysResource",
6276
"AsyncReplaysResource",
6377
"ReplaysResourceWithRawResponse",

src/kernel/resources/browsers/browsers.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
AsyncComputerResourceWithStreamingResponse,
6363
)
6464
from ..._compat import cached_property
65+
from .telemetry import (
66+
TelemetryResource,
67+
AsyncTelemetryResource,
68+
TelemetryResourceWithRawResponse,
69+
AsyncTelemetryResourceWithRawResponse,
70+
TelemetryResourceWithStreamingResponse,
71+
AsyncTelemetryResourceWithStreamingResponse,
72+
)
6573
from .playwright import (
6674
PlaywrightResource,
6775
AsyncPlaywrightResource,
@@ -94,13 +102,19 @@
94102
from ...types.shared_params.browser_profile import BrowserProfile
95103
from ...types.shared_params.browser_viewport import BrowserViewport
96104
from ...types.shared_params.browser_extension import BrowserExtension
105+
from ...types.browsers.browser_telemetry_config_param import BrowserTelemetryConfigParam
97106

98107
__all__ = ["BrowsersResource", "AsyncBrowsersResource"]
99108

100109

101110
class BrowsersResource(SyncAPIResource):
102111
"""Create and manage browser sessions."""
103112

113+
@cached_property
114+
def telemetry(self) -> TelemetryResource:
115+
"""Stream live telemetry events from a browser session."""
116+
return TelemetryResource(self._client)
117+
104118
@cached_property
105119
def replays(self) -> ReplaysResource:
106120
"""Record and manage browser session video replays."""
@@ -163,6 +177,7 @@ def create(
163177
proxy_id: str | Omit = omit,
164178
start_url: str | Omit = omit,
165179
stealth: bool | Omit = omit,
180+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
166181
timeout_seconds: int | Omit = omit,
167182
viewport: BrowserViewport | Omit = omit,
168183
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -211,6 +226,10 @@ def create(
211226
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
212227
mechanisms.
213228
229+
telemetry: Telemetry configuration for the browser session. If provided, telemetry capture
230+
starts with the specified category filter when the session is created. If
231+
omitted, no telemetry capture is started.
232+
214233
timeout_seconds: The number of seconds of inactivity before the browser session is terminated.
215234
Activity includes CDP connections and live view connections. Defaults to 60
216235
seconds. Minimum allowed is 10 seconds. Maximum allowed is 259200 (72 hours). We
@@ -253,6 +272,7 @@ def create(
253272
"proxy_id": proxy_id,
254273
"start_url": start_url,
255274
"stealth": stealth,
275+
"telemetry": telemetry,
256276
"timeout_seconds": timeout_seconds,
257277
"viewport": viewport,
258278
},
@@ -313,6 +333,7 @@ def update(
313333
disable_default_proxy: bool | Omit = omit,
314334
profile: BrowserProfile | Omit = omit,
315335
proxy_id: Optional[str] | Omit = omit,
336+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
316337
viewport: browser_update_params.Viewport | Omit = omit,
317338
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
318339
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -334,6 +355,11 @@ def update(
334355
proxy_id: ID of the proxy to use. Omit to leave unchanged, set to empty string to remove
335356
proxy.
336357
358+
telemetry: Telemetry configuration. Omit, set to null, or set to an empty object ({}) to
359+
leave the existing configuration unchanged (no-op). To enable capture for all
360+
categories using VM defaults, set browser to an empty object ({"browser": {}}).
361+
To stop capture, set every category's enabled to false.
362+
337363
viewport: Viewport configuration to apply to the browser session.
338364
339365
extra_headers: Send extra headers
@@ -353,6 +379,7 @@ def update(
353379
"disable_default_proxy": disable_default_proxy,
354380
"profile": profile,
355381
"proxy_id": proxy_id,
382+
"telemetry": telemetry,
356383
"viewport": viewport,
357384
},
358385
browser_update_params.BrowserUpdateParams,
@@ -673,6 +700,11 @@ def load_extensions(
673700
class AsyncBrowsersResource(AsyncAPIResource):
674701
"""Create and manage browser sessions."""
675702

703+
@cached_property
704+
def telemetry(self) -> AsyncTelemetryResource:
705+
"""Stream live telemetry events from a browser session."""
706+
return AsyncTelemetryResource(self._client)
707+
676708
@cached_property
677709
def replays(self) -> AsyncReplaysResource:
678710
"""Record and manage browser session video replays."""
@@ -735,6 +767,7 @@ async def create(
735767
proxy_id: str | Omit = omit,
736768
start_url: str | Omit = omit,
737769
stealth: bool | Omit = omit,
770+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
738771
timeout_seconds: int | Omit = omit,
739772
viewport: BrowserViewport | Omit = omit,
740773
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -783,6 +816,10 @@ async def create(
783816
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
784817
mechanisms.
785818
819+
telemetry: Telemetry configuration for the browser session. If provided, telemetry capture
820+
starts with the specified category filter when the session is created. If
821+
omitted, no telemetry capture is started.
822+
786823
timeout_seconds: The number of seconds of inactivity before the browser session is terminated.
787824
Activity includes CDP connections and live view connections. Defaults to 60
788825
seconds. Minimum allowed is 10 seconds. Maximum allowed is 259200 (72 hours). We
@@ -825,6 +862,7 @@ async def create(
825862
"proxy_id": proxy_id,
826863
"start_url": start_url,
827864
"stealth": stealth,
865+
"telemetry": telemetry,
828866
"timeout_seconds": timeout_seconds,
829867
"viewport": viewport,
830868
},
@@ -885,6 +923,7 @@ async def update(
885923
disable_default_proxy: bool | Omit = omit,
886924
profile: BrowserProfile | Omit = omit,
887925
proxy_id: Optional[str] | Omit = omit,
926+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
888927
viewport: browser_update_params.Viewport | Omit = omit,
889928
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
890929
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -906,6 +945,11 @@ async def update(
906945
proxy_id: ID of the proxy to use. Omit to leave unchanged, set to empty string to remove
907946
proxy.
908947
948+
telemetry: Telemetry configuration. Omit, set to null, or set to an empty object ({}) to
949+
leave the existing configuration unchanged (no-op). To enable capture for all
950+
categories using VM defaults, set browser to an empty object ({"browser": {}}).
951+
To stop capture, set every category's enabled to false.
952+
909953
viewport: Viewport configuration to apply to the browser session.
910954
911955
extra_headers: Send extra headers
@@ -925,6 +969,7 @@ async def update(
925969
"disable_default_proxy": disable_default_proxy,
926970
"profile": profile,
927971
"proxy_id": proxy_id,
972+
"telemetry": telemetry,
928973
"viewport": viewport,
929974
},
930975
browser_update_params.BrowserUpdateParams,
@@ -1275,6 +1320,11 @@ def __init__(self, browsers: BrowsersResource) -> None:
12751320
browsers.load_extensions,
12761321
)
12771322

1323+
@cached_property
1324+
def telemetry(self) -> TelemetryResourceWithRawResponse:
1325+
"""Stream live telemetry events from a browser session."""
1326+
return TelemetryResourceWithRawResponse(self._browsers.telemetry)
1327+
12781328
@cached_property
12791329
def replays(self) -> ReplaysResourceWithRawResponse:
12801330
"""Record and manage browser session video replays."""
@@ -1336,6 +1386,11 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None:
13361386
browsers.load_extensions,
13371387
)
13381388

1389+
@cached_property
1390+
def telemetry(self) -> AsyncTelemetryResourceWithRawResponse:
1391+
"""Stream live telemetry events from a browser session."""
1392+
return AsyncTelemetryResourceWithRawResponse(self._browsers.telemetry)
1393+
13391394
@cached_property
13401395
def replays(self) -> AsyncReplaysResourceWithRawResponse:
13411396
"""Record and manage browser session video replays."""
@@ -1397,6 +1452,11 @@ def __init__(self, browsers: BrowsersResource) -> None:
13971452
browsers.load_extensions,
13981453
)
13991454

1455+
@cached_property
1456+
def telemetry(self) -> TelemetryResourceWithStreamingResponse:
1457+
"""Stream live telemetry events from a browser session."""
1458+
return TelemetryResourceWithStreamingResponse(self._browsers.telemetry)
1459+
14001460
@cached_property
14011461
def replays(self) -> ReplaysResourceWithStreamingResponse:
14021462
"""Record and manage browser session video replays."""
@@ -1458,6 +1518,11 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None:
14581518
browsers.load_extensions,
14591519
)
14601520

1521+
@cached_property
1522+
def telemetry(self) -> AsyncTelemetryResourceWithStreamingResponse:
1523+
"""Stream live telemetry events from a browser session."""
1524+
return AsyncTelemetryResourceWithStreamingResponse(self._browsers.telemetry)
1525+
14611526
@cached_property
14621527
def replays(self) -> AsyncReplaysResourceWithStreamingResponse:
14631528
"""Record and manage browser session video replays."""

0 commit comments

Comments
 (0)