Skip to content

Commit 868b5c9

Browse files
feat: Allow hot loading profiles into sessions
1 parent 2457c01 commit 868b5c9

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 97
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-7427d4bcaba5cad07910da7a222bdd2650b5280e6b889132ed38d230adafb8a5.yml
3-
openapi_spec_hash: e8e3dc1ae54666d544d1fc848b25e7cf
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-d430a8e3407ceb608d912cabadbcb016b4fcf057ca56b3bbd179ea3b3121b484.yml
3+
openapi_spec_hash: 8adbf013baf77abacaf04ed067749397
44
config_hash: b470456b217bb9502f5212311d395a6f

src/kernel/resources/browsers/browsers.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,28 @@ def update(
270270
self,
271271
id: str,
272272
*,
273+
profile: BrowserProfile | Omit = omit,
273274
proxy_id: Optional[str] | Omit = omit,
275+
viewport: BrowserViewport | Omit = omit,
274276
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
275277
# The extra values given here take precedence over values defined on the client or passed to this method.
276278
extra_headers: Headers | None = None,
277279
extra_query: Query | None = None,
278280
extra_body: Body | None = None,
279281
timeout: float | httpx.Timeout | None | NotGiven = not_given,
280282
) -> BrowserUpdateResponse:
281-
"""Update a browser session.
283+
"""
284+
Update a browser session.
282285
283286
Args:
284-
proxy_id: ID of the proxy to use.
287+
profile: Profile to load into the browser session. Only allowed if the session does not
288+
already have a profile loaded.
285289
286-
Omit to leave unchanged, set to empty string to remove
290+
proxy_id: ID of the proxy to use. Omit to leave unchanged, set to empty string to remove
287291
proxy.
288292
293+
viewport: Viewport configuration to apply to the browser session.
294+
289295
extra_headers: Send extra headers
290296
291297
extra_query: Add additional query parameters to the request
@@ -298,7 +304,14 @@ def update(
298304
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
299305
return self._patch(
300306
f"/browsers/{id}",
301-
body=maybe_transform({"proxy_id": proxy_id}, browser_update_params.BrowserUpdateParams),
307+
body=maybe_transform(
308+
{
309+
"profile": profile,
310+
"proxy_id": proxy_id,
311+
"viewport": viewport,
312+
},
313+
browser_update_params.BrowserUpdateParams,
314+
),
302315
options=make_request_options(
303316
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
304317
),
@@ -668,22 +681,28 @@ async def update(
668681
self,
669682
id: str,
670683
*,
684+
profile: BrowserProfile | Omit = omit,
671685
proxy_id: Optional[str] | Omit = omit,
686+
viewport: BrowserViewport | Omit = omit,
672687
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
673688
# The extra values given here take precedence over values defined on the client or passed to this method.
674689
extra_headers: Headers | None = None,
675690
extra_query: Query | None = None,
676691
extra_body: Body | None = None,
677692
timeout: float | httpx.Timeout | None | NotGiven = not_given,
678693
) -> BrowserUpdateResponse:
679-
"""Update a browser session.
694+
"""
695+
Update a browser session.
680696
681697
Args:
682-
proxy_id: ID of the proxy to use.
698+
profile: Profile to load into the browser session. Only allowed if the session does not
699+
already have a profile loaded.
683700
684-
Omit to leave unchanged, set to empty string to remove
701+
proxy_id: ID of the proxy to use. Omit to leave unchanged, set to empty string to remove
685702
proxy.
686703
704+
viewport: Viewport configuration to apply to the browser session.
705+
687706
extra_headers: Send extra headers
688707
689708
extra_query: Add additional query parameters to the request
@@ -696,7 +715,14 @@ async def update(
696715
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
697716
return await self._patch(
698717
f"/browsers/{id}",
699-
body=await async_maybe_transform({"proxy_id": proxy_id}, browser_update_params.BrowserUpdateParams),
718+
body=await async_maybe_transform(
719+
{
720+
"profile": profile,
721+
"proxy_id": proxy_id,
722+
"viewport": viewport,
723+
},
724+
browser_update_params.BrowserUpdateParams,
725+
),
700726
options=make_request_options(
701727
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
702728
),

src/kernel/types/browser_update_params.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
from typing import Optional
66
from typing_extensions import TypedDict
77

8+
from .shared_params.browser_profile import BrowserProfile
9+
from .shared_params.browser_viewport import BrowserViewport
10+
811
__all__ = ["BrowserUpdateParams"]
912

1013

1114
class BrowserUpdateParams(TypedDict, total=False):
15+
profile: BrowserProfile
16+
"""Profile to load into the browser session.
17+
18+
Only allowed if the session does not already have a profile loaded.
19+
"""
20+
1221
proxy_id: Optional[str]
1322
"""ID of the proxy to use.
1423
1524
Omit to leave unchanged, set to empty string to remove proxy.
1625
"""
26+
27+
viewport: BrowserViewport
28+
"""Viewport configuration to apply to the browser session."""

tests/api_resources/test_browsers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,17 @@ def test_method_update(self, client: Kernel) -> None:
147147
def test_method_update_with_all_params(self, client: Kernel) -> None:
148148
browser = client.browsers.update(
149149
id="htzv5orfit78e1m2biiifpbv",
150+
profile={
151+
"id": "id",
152+
"name": "name",
153+
"save_changes": True,
154+
},
150155
proxy_id="proxy_id",
156+
viewport={
157+
"height": 800,
158+
"width": 1280,
159+
"refresh_rate": 60,
160+
},
151161
)
152162
assert_matches_type(BrowserUpdateResponse, browser, path=["response"])
153163

@@ -498,7 +508,17 @@ async def test_method_update(self, async_client: AsyncKernel) -> None:
498508
async def test_method_update_with_all_params(self, async_client: AsyncKernel) -> None:
499509
browser = await async_client.browsers.update(
500510
id="htzv5orfit78e1m2biiifpbv",
511+
profile={
512+
"id": "id",
513+
"name": "name",
514+
"save_changes": True,
515+
},
501516
proxy_id="proxy_id",
517+
viewport={
518+
"height": 800,
519+
"width": 1280,
520+
"refresh_rate": 60,
521+
},
502522
)
503523
assert_matches_type(BrowserUpdateResponse, browser, path=["response"])
504524

0 commit comments

Comments
 (0)