Skip to content

Commit 782a53c

Browse files
feat: [kernel-1116] browser events api integration
1 parent b5449b1 commit 782a53c

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
@@ -61,6 +61,14 @@
6161
AsyncComputerResourceWithStreamingResponse,
6262
)
6363
from ..._compat import cached_property
64+
from .telemetry import (
65+
TelemetryResource,
66+
AsyncTelemetryResource,
67+
TelemetryResourceWithRawResponse,
68+
AsyncTelemetryResourceWithRawResponse,
69+
TelemetryResourceWithStreamingResponse,
70+
AsyncTelemetryResourceWithStreamingResponse,
71+
)
6472
from .playwright import (
6573
PlaywrightResource,
6674
AsyncPlaywrightResource,
@@ -87,13 +95,19 @@
8795
from ...types.shared_params.browser_profile import BrowserProfile
8896
from ...types.shared_params.browser_viewport import BrowserViewport
8997
from ...types.shared_params.browser_extension import BrowserExtension
98+
from ...types.browsers.browser_telemetry_config_param import BrowserTelemetryConfigParam
9099

91100
__all__ = ["BrowsersResource", "AsyncBrowsersResource"]
92101

93102

94103
class BrowsersResource(SyncAPIResource):
95104
"""Create and manage browser sessions."""
96105

106+
@cached_property
107+
def telemetry(self) -> TelemetryResource:
108+
"""Stream live telemetry events from a browser session."""
109+
return TelemetryResource(self._client)
110+
97111
@cached_property
98112
def replays(self) -> ReplaysResource:
99113
"""Record and manage browser session video replays."""
@@ -156,6 +170,7 @@ def create(
156170
proxy_id: str | Omit = omit,
157171
start_url: str | Omit = omit,
158172
stealth: bool | Omit = omit,
173+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
159174
timeout_seconds: int | Omit = omit,
160175
viewport: BrowserViewport | Omit = omit,
161176
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -204,6 +219,10 @@ def create(
204219
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
205220
mechanisms.
206221
222+
telemetry: Telemetry configuration for the browser session. If provided, telemetry capture
223+
starts with the specified category filter when the session is created. If
224+
omitted, no telemetry capture is started.
225+
207226
timeout_seconds: The number of seconds of inactivity before the browser session is terminated.
208227
Activity includes CDP connections and live view connections. Defaults to 60
209228
seconds. Minimum allowed is 10 seconds. Maximum allowed is 259200 (72 hours). We
@@ -246,6 +265,7 @@ def create(
246265
"proxy_id": proxy_id,
247266
"start_url": start_url,
248267
"stealth": stealth,
268+
"telemetry": telemetry,
249269
"timeout_seconds": timeout_seconds,
250270
"viewport": viewport,
251271
},
@@ -306,6 +326,7 @@ def update(
306326
disable_default_proxy: bool | Omit = omit,
307327
profile: BrowserProfile | Omit = omit,
308328
proxy_id: Optional[str] | Omit = omit,
329+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
309330
viewport: browser_update_params.Viewport | Omit = omit,
310331
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
311332
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -327,6 +348,11 @@ def update(
327348
proxy_id: ID of the proxy to use. Omit to leave unchanged, set to empty string to remove
328349
proxy.
329350
351+
telemetry: Telemetry configuration. Omit, set to null, or set to an empty object ({}) to
352+
leave the existing configuration unchanged (no-op). To enable capture for all
353+
categories using VM defaults, set browser to an empty object ({"browser": {}}).
354+
To stop capture, set every category's enabled to false.
355+
330356
viewport: Viewport configuration to apply to the browser session.
331357
332358
extra_headers: Send extra headers
@@ -346,6 +372,7 @@ def update(
346372
"disable_default_proxy": disable_default_proxy,
347373
"profile": profile,
348374
"proxy_id": proxy_id,
375+
"telemetry": telemetry,
349376
"viewport": viewport,
350377
},
351378
browser_update_params.BrowserUpdateParams,
@@ -608,6 +635,11 @@ def load_extensions(
608635
class AsyncBrowsersResource(AsyncAPIResource):
609636
"""Create and manage browser sessions."""
610637

638+
@cached_property
639+
def telemetry(self) -> AsyncTelemetryResource:
640+
"""Stream live telemetry events from a browser session."""
641+
return AsyncTelemetryResource(self._client)
642+
611643
@cached_property
612644
def replays(self) -> AsyncReplaysResource:
613645
"""Record and manage browser session video replays."""
@@ -670,6 +702,7 @@ async def create(
670702
proxy_id: str | Omit = omit,
671703
start_url: str | Omit = omit,
672704
stealth: bool | Omit = omit,
705+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
673706
timeout_seconds: int | Omit = omit,
674707
viewport: BrowserViewport | Omit = omit,
675708
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -718,6 +751,10 @@ async def create(
718751
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
719752
mechanisms.
720753
754+
telemetry: Telemetry configuration for the browser session. If provided, telemetry capture
755+
starts with the specified category filter when the session is created. If
756+
omitted, no telemetry capture is started.
757+
721758
timeout_seconds: The number of seconds of inactivity before the browser session is terminated.
722759
Activity includes CDP connections and live view connections. Defaults to 60
723760
seconds. Minimum allowed is 10 seconds. Maximum allowed is 259200 (72 hours). We
@@ -760,6 +797,7 @@ async def create(
760797
"proxy_id": proxy_id,
761798
"start_url": start_url,
762799
"stealth": stealth,
800+
"telemetry": telemetry,
763801
"timeout_seconds": timeout_seconds,
764802
"viewport": viewport,
765803
},
@@ -820,6 +858,7 @@ async def update(
820858
disable_default_proxy: bool | Omit = omit,
821859
profile: BrowserProfile | Omit = omit,
822860
proxy_id: Optional[str] | Omit = omit,
861+
telemetry: Optional[BrowserTelemetryConfigParam] | Omit = omit,
823862
viewport: browser_update_params.Viewport | Omit = omit,
824863
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
825864
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -841,6 +880,11 @@ async def update(
841880
proxy_id: ID of the proxy to use. Omit to leave unchanged, set to empty string to remove
842881
proxy.
843882
883+
telemetry: Telemetry configuration. Omit, set to null, or set to an empty object ({}) to
884+
leave the existing configuration unchanged (no-op). To enable capture for all
885+
categories using VM defaults, set browser to an empty object ({"browser": {}}).
886+
To stop capture, set every category's enabled to false.
887+
844888
viewport: Viewport configuration to apply to the browser session.
845889
846890
extra_headers: Send extra headers
@@ -860,6 +904,7 @@ async def update(
860904
"disable_default_proxy": disable_default_proxy,
861905
"profile": profile,
862906
"proxy_id": proxy_id,
907+
"telemetry": telemetry,
863908
"viewport": viewport,
864909
},
865910
browser_update_params.BrowserUpdateParams,
@@ -1152,6 +1197,11 @@ def __init__(self, browsers: BrowsersResource) -> None:
11521197
browsers.load_extensions,
11531198
)
11541199

1200+
@cached_property
1201+
def telemetry(self) -> TelemetryResourceWithRawResponse:
1202+
"""Stream live telemetry events from a browser session."""
1203+
return TelemetryResourceWithRawResponse(self._browsers.telemetry)
1204+
11551205
@cached_property
11561206
def replays(self) -> ReplaysResourceWithRawResponse:
11571207
"""Record and manage browser session video replays."""
@@ -1213,6 +1263,11 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None:
12131263
browsers.load_extensions,
12141264
)
12151265

1266+
@cached_property
1267+
def telemetry(self) -> AsyncTelemetryResourceWithRawResponse:
1268+
"""Stream live telemetry events from a browser session."""
1269+
return AsyncTelemetryResourceWithRawResponse(self._browsers.telemetry)
1270+
12161271
@cached_property
12171272
def replays(self) -> AsyncReplaysResourceWithRawResponse:
12181273
"""Record and manage browser session video replays."""
@@ -1274,6 +1329,11 @@ def __init__(self, browsers: BrowsersResource) -> None:
12741329
browsers.load_extensions,
12751330
)
12761331

1332+
@cached_property
1333+
def telemetry(self) -> TelemetryResourceWithStreamingResponse:
1334+
"""Stream live telemetry events from a browser session."""
1335+
return TelemetryResourceWithStreamingResponse(self._browsers.telemetry)
1336+
12771337
@cached_property
12781338
def replays(self) -> ReplaysResourceWithStreamingResponse:
12791339
"""Record and manage browser session video replays."""
@@ -1335,6 +1395,11 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None:
13351395
browsers.load_extensions,
13361396
)
13371397

1398+
@cached_property
1399+
def telemetry(self) -> AsyncTelemetryResourceWithStreamingResponse:
1400+
"""Stream live telemetry events from a browser session."""
1401+
return AsyncTelemetryResourceWithStreamingResponse(self._browsers.telemetry)
1402+
13381403
@cached_property
13391404
def replays(self) -> AsyncReplaysResourceWithStreamingResponse:
13401405
"""Record and manage browser session video replays."""

0 commit comments

Comments
 (0)