Skip to content

Commit ad95f5f

Browse files
feat(api): add browser ttls
1 parent 4279b99 commit ad95f5f

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
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: 31
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-e907afeabfeea49dedd783112ac3fd29267bc86f3d594f89ba9a2abf2bcbc9d8.yml
3-
openapi_spec_hash: 060ca6288c1a09b6d1bdf207a0011165
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-6f4aab5f0db80d6ce30ef40274eee347cce0a9465e7f1e5077f8f4a085251ddf.yml
3+
openapi_spec_hash: 8e83254243d1620b80a0dc8aa212ee0d
44
config_hash: f67e4b33b2fb30c1405ee2fff8096320

src/kernel/resources/browsers/browsers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def create(
7575
invocation_id: str | NotGiven = NOT_GIVEN,
7676
persistence: BrowserPersistenceParam | NotGiven = NOT_GIVEN,
7777
stealth: bool | NotGiven = NOT_GIVEN,
78+
timeout_seconds: int | NotGiven = NOT_GIVEN,
7879
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
7980
# The extra values given here take precedence over values defined on the client or passed to this method.
8081
extra_headers: Headers | None = None,
@@ -96,6 +97,10 @@ def create(
9697
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
9798
mechanisms.
9899
100+
timeout_seconds: The number of seconds of inactivity before the browser session is terminated.
101+
Only applicable to non-persistent browsers. Activity includes CDP connections
102+
and live view connections. Defaults to 60 seconds.
103+
99104
extra_headers: Send extra headers
100105
101106
extra_query: Add additional query parameters to the request
@@ -112,6 +117,7 @@ def create(
112117
"invocation_id": invocation_id,
113118
"persistence": persistence,
114119
"stealth": stealth,
120+
"timeout_seconds": timeout_seconds,
115121
},
116122
browser_create_params.BrowserCreateParams,
117123
),
@@ -281,6 +287,7 @@ async def create(
281287
invocation_id: str | NotGiven = NOT_GIVEN,
282288
persistence: BrowserPersistenceParam | NotGiven = NOT_GIVEN,
283289
stealth: bool | NotGiven = NOT_GIVEN,
290+
timeout_seconds: int | NotGiven = NOT_GIVEN,
284291
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
285292
# The extra values given here take precedence over values defined on the client or passed to this method.
286293
extra_headers: Headers | None = None,
@@ -302,6 +309,10 @@ async def create(
302309
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
303310
mechanisms.
304311
312+
timeout_seconds: The number of seconds of inactivity before the browser session is terminated.
313+
Only applicable to non-persistent browsers. Activity includes CDP connections
314+
and live view connections. Defaults to 60 seconds.
315+
305316
extra_headers: Send extra headers
306317
307318
extra_query: Add additional query parameters to the request
@@ -318,6 +329,7 @@ async def create(
318329
"invocation_id": invocation_id,
319330
"persistence": persistence,
320331
"stealth": stealth,
332+
"timeout_seconds": timeout_seconds,
321333
},
322334
browser_create_params.BrowserCreateParams,
323335
),

src/kernel/types/browser_create_params.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ class BrowserCreateParams(TypedDict, total=False):
2727
If true, launches the browser in stealth mode to reduce detection by anti-bot
2828
mechanisms.
2929
"""
30+
31+
timeout_seconds: int
32+
"""The number of seconds of inactivity before the browser session is terminated.
33+
34+
Only applicable to non-persistent browsers. Activity includes CDP connections
35+
and live view connections. Defaults to 60 seconds.
36+
"""

src/kernel/types/browser_create_response.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ class BrowserCreateResponse(BaseModel):
1212
cdp_ws_url: str
1313
"""Websocket URL for Chrome DevTools Protocol connections to the browser session"""
1414

15+
headless: bool
16+
"""Indicates whether the browser session is headless."""
17+
1518
session_id: str
1619
"""Unique identifier for the browser session"""
1720

21+
stealth: bool
22+
"""Indicates whether the browser session is stealth."""
23+
24+
timeout_seconds: int
25+
"""The number of seconds of inactivity before the browser session is terminated."""
26+
1827
browser_live_view_url: Optional[str] = None
1928
"""Remote URL for live viewing the browser session.
2029

src/kernel/types/browser_list_response.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ class BrowserListResponseItem(BaseModel):
1313
cdp_ws_url: str
1414
"""Websocket URL for Chrome DevTools Protocol connections to the browser session"""
1515

16+
headless: bool
17+
"""Indicates whether the browser session is headless."""
18+
1619
session_id: str
1720
"""Unique identifier for the browser session"""
1821

22+
stealth: bool
23+
"""Indicates whether the browser session is stealth."""
24+
25+
timeout_seconds: int
26+
"""The number of seconds of inactivity before the browser session is terminated."""
27+
1928
browser_live_view_url: Optional[str] = None
2029
"""Remote URL for live viewing the browser session.
2130

src/kernel/types/browser_retrieve_response.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ class BrowserRetrieveResponse(BaseModel):
1212
cdp_ws_url: str
1313
"""Websocket URL for Chrome DevTools Protocol connections to the browser session"""
1414

15+
headless: bool
16+
"""Indicates whether the browser session is headless."""
17+
1518
session_id: str
1619
"""Unique identifier for the browser session"""
1720

21+
stealth: bool
22+
"""Indicates whether the browser session is stealth."""
23+
24+
timeout_seconds: int
25+
"""The number of seconds of inactivity before the browser session is terminated."""
26+
1827
browser_live_view_url: Optional[str] = None
1928
"""Remote URL for live viewing the browser session.
2029

tests/api_resources/test_browsers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_method_create_with_all_params(self, client: Kernel) -> None:
3535
invocation_id="rr33xuugxj9h0bkf1rdt2bet",
3636
persistence={"id": "my-awesome-browser-for-user-1234"},
3737
stealth=True,
38+
timeout_seconds=0,
3839
)
3940
assert_matches_type(BrowserCreateResponse, browser, path=["response"])
4041

@@ -226,6 +227,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncKernel) ->
226227
invocation_id="rr33xuugxj9h0bkf1rdt2bet",
227228
persistence={"id": "my-awesome-browser-for-user-1234"},
228229
stealth=True,
230+
timeout_seconds=0,
229231
)
230232
assert_matches_type(BrowserCreateResponse, browser, path=["response"])
231233

0 commit comments

Comments
 (0)