Skip to content

Commit f5c540c

Browse files
feat: Add profiles to browser pool acquire
Stainless-Generated-From: 5176ec1d8f90acc70434a055166d8e9366218443
1 parent 1fdfce2 commit f5c540c

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎src/kernel/resources/browser_pools.py‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ..types.browser_pool import BrowserPool
3232
from ..types.browser_network_config_param import BrowserNetworkConfigParam
3333
from ..types.browser_pool_acquire_response import BrowserPoolAcquireResponse
34+
from ..types.shared_params.browser_profile import BrowserProfile
3435
from ..types.shared_params.browser_viewport import BrowserViewport
3536
from ..types.shared_params.browser_extension import BrowserExtension
3637

@@ -509,6 +510,7 @@ def acquire(
509510
*,
510511
acquire_timeout_seconds: int | Omit = omit,
511512
name: str | Omit = omit,
513+
profile: BrowserProfile | Omit = omit,
512514
start_url: str | Omit = omit,
513515
tags: TagsParam | Omit = omit,
514516
telemetry: Optional[browser_pool_acquire_params.Telemetry] | Omit = omit,
@@ -536,6 +538,10 @@ def acquire(
536538
project. Applies to this lease only and is cleared when the browser is released
537539
back to the pool.
538540
541+
profile: Profile selection for the browser session. Provide either id or name. If
542+
specified, the matching profile will be loaded into the browser session.
543+
Profiles must be created beforehand.
544+
539545
start_url: Optional URL to navigate the acquired browser to. Overrides the pool's start_url
540546
for this acquire only. Best-effort: failures to navigate do not fail the
541547
acquire.
@@ -569,6 +575,7 @@ def acquire(
569575
{
570576
"acquire_timeout_seconds": acquire_timeout_seconds,
571577
"name": name,
578+
"profile": profile,
572579
"start_url": start_url,
573580
"tags": tags,
574581
"telemetry": telemetry,
@@ -638,7 +645,8 @@ def release(
638645
Defaults to true. A reused browser keeps the configuration it was created with,
639646
so it does not pick up pool configuration changes made while it was in use.
640647
Release with `reuse: false`, or flush the pool afterward, to rebuild it with the
641-
current configuration.
648+
current configuration. Browsers loaded with an acquire-time profile are always
649+
destroyed and replaced, even when reuse is true.
642650
643651
extra_headers: Send extra headers
644652
@@ -1139,6 +1147,7 @@ async def acquire(
11391147
*,
11401148
acquire_timeout_seconds: int | Omit = omit,
11411149
name: str | Omit = omit,
1150+
profile: BrowserProfile | Omit = omit,
11421151
start_url: str | Omit = omit,
11431152
tags: TagsParam | Omit = omit,
11441153
telemetry: Optional[browser_pool_acquire_params.Telemetry] | Omit = omit,
@@ -1166,6 +1175,10 @@ async def acquire(
11661175
project. Applies to this lease only and is cleared when the browser is released
11671176
back to the pool.
11681177
1178+
profile: Profile selection for the browser session. Provide either id or name. If
1179+
specified, the matching profile will be loaded into the browser session.
1180+
Profiles must be created beforehand.
1181+
11691182
start_url: Optional URL to navigate the acquired browser to. Overrides the pool's start_url
11701183
for this acquire only. Best-effort: failures to navigate do not fail the
11711184
acquire.
@@ -1199,6 +1212,7 @@ async def acquire(
11991212
{
12001213
"acquire_timeout_seconds": acquire_timeout_seconds,
12011214
"name": name,
1215+
"profile": profile,
12021216
"start_url": start_url,
12031217
"tags": tags,
12041218
"telemetry": telemetry,
@@ -1268,7 +1282,8 @@ async def release(
12681282
Defaults to true. A reused browser keeps the configuration it was created with,
12691283
so it does not pick up pool configuration changes made while it was in use.
12701284
Release with `reuse: false`, or flush the pool afterward, to rebuild it with the
1271-
current configuration.
1285+
current configuration. Browsers loaded with an acquire-time profile are always
1286+
destroyed and replaced, even when reuse is true.
12721287
12731288
extra_headers: Send extra headers
12741289

‎src/kernel/types/browser_pool_acquire_params.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing_extensions import TypedDict
77

88
from .tags_param import TagsParam
9+
from .shared_params.browser_profile import BrowserProfile
910
from .browsers.browser_telemetry_categories_config_param import BrowserTelemetryCategoriesConfigParam
1011

1112
__all__ = [
@@ -33,6 +34,13 @@ class BrowserPoolAcquireParams(TypedDict, total=False):
3334
back to the pool.
3435
"""
3536

37+
profile: BrowserProfile
38+
"""Profile selection for the browser session.
39+
40+
Provide either id or name. If specified, the matching profile will be loaded
41+
into the browser session. Profiles must be created beforehand.
42+
"""
43+
3644
start_url: str
3745
"""Optional URL to navigate the acquired browser to.
3846

‎src/kernel/types/browser_pool_release_params.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ class BrowserPoolReleaseParams(TypedDict, total=False):
1717
Defaults to true. A reused browser keeps the configuration it was created with,
1818
so it does not pick up pool configuration changes made while it was in use.
1919
Release with `reuse: false`, or flush the pool afterward, to rebuild it with the
20-
current configuration.
20+
current configuration. Browsers loaded with an acquire-time profile are always
21+
destroyed and replaced, even when reuse is true.
2122
"""

‎tests/api_resources/test_browser_pools.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ def test_method_acquire_with_all_params(self, client: Kernel) -> None:
370370
id_or_name="id_or_name",
371371
acquire_timeout_seconds=0,
372372
name="checkout-flow-1",
373+
profile={
374+
"id": "id",
375+
"name": "name",
376+
"save_changes": True,
377+
},
373378
start_url="https://example.com",
374379
tags={
375380
"team": "backend",
@@ -892,6 +897,11 @@ async def test_method_acquire_with_all_params(self, async_client: AsyncKernel) -
892897
id_or_name="id_or_name",
893898
acquire_timeout_seconds=0,
894899
name="checkout-flow-1",
900+
profile={
901+
"id": "id",
902+
"name": "name",
903+
"save_changes": True,
904+
},
895905
start_url="https://example.com",
896906
tags={
897907
"team": "backend",

0 commit comments

Comments
 (0)