Skip to content

Commit de0b235

Browse files
feat(api): headless browsers
1 parent d3d4f04 commit de0b235

File tree

7 files changed

+38
-11
lines changed

7 files changed

+38
-11
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: 17
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-0ac9428eb663361184124cdd6a6e80ae8dc72c927626c949f22aacc4f40095de.yml
3-
openapi_spec_hash: 27707667d706ac33f2d9ccb23c0f15c3
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-3ec96d0022acb32aa2676c2e7ae20152b899a776ccd499380c334c955b9ba071.yml
3+
openapi_spec_hash: b64c095d82185c1cd0355abea88b606f
44
config_hash: 00ec9df250b9dc077f8d3b93a442d252

src/kernel/resources/browsers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def with_streaming_response(self) -> BrowsersResourceWithStreamingResponse:
4747
def create(
4848
self,
4949
*,
50+
headless: bool | NotGiven = NOT_GIVEN,
5051
invocation_id: str | NotGiven = NOT_GIVEN,
5152
persistence: BrowserPersistenceParam | NotGiven = NOT_GIVEN,
5253
stealth: bool | NotGiven = NOT_GIVEN,
@@ -61,6 +62,9 @@ def create(
6162
Create a new browser session from within an action.
6263
6364
Args:
65+
headless: If true, launches the browser using a headless image (no VNC/GUI). Defaults to
66+
false.
67+
6468
invocation_id: action invocation ID
6569
6670
persistence: Optional persistence configuration for the browser session.
@@ -80,6 +84,7 @@ def create(
8084
"/browsers",
8185
body=maybe_transform(
8286
{
87+
"headless": headless,
8388
"invocation_id": invocation_id,
8489
"persistence": persistence,
8590
"stealth": stealth,
@@ -240,6 +245,7 @@ def with_streaming_response(self) -> AsyncBrowsersResourceWithStreamingResponse:
240245
async def create(
241246
self,
242247
*,
248+
headless: bool | NotGiven = NOT_GIVEN,
243249
invocation_id: str | NotGiven = NOT_GIVEN,
244250
persistence: BrowserPersistenceParam | NotGiven = NOT_GIVEN,
245251
stealth: bool | NotGiven = NOT_GIVEN,
@@ -254,6 +260,9 @@ async def create(
254260
Create a new browser session from within an action.
255261
256262
Args:
263+
headless: If true, launches the browser using a headless image (no VNC/GUI). Defaults to
264+
false.
265+
257266
invocation_id: action invocation ID
258267
259268
persistence: Optional persistence configuration for the browser session.
@@ -273,6 +282,7 @@ async def create(
273282
"/browsers",
274283
body=await async_maybe_transform(
275284
{
285+
"headless": headless,
276286
"invocation_id": invocation_id,
277287
"persistence": persistence,
278288
"stealth": stealth,

src/kernel/types/browser_create_params.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111

1212
class BrowserCreateParams(TypedDict, total=False):
13+
headless: bool
14+
"""If true, launches the browser using a headless image (no VNC/GUI).
15+
16+
Defaults to false.
17+
"""
18+
1319
invocation_id: str
1420
"""action invocation ID"""
1521

src/kernel/types/browser_create_response.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010

1111
class BrowserCreateResponse(BaseModel):
12-
browser_live_view_url: str
13-
"""Remote URL for live viewing the browser session"""
14-
1512
cdp_ws_url: str
1613
"""Websocket URL for Chrome DevTools Protocol connections to the browser session"""
1714

1815
session_id: str
1916
"""Unique identifier for the browser session"""
2017

18+
browser_live_view_url: Optional[str] = None
19+
"""Remote URL for live viewing the browser session.
20+
21+
Only available for non-headless browsers.
22+
"""
23+
2124
persistence: Optional[BrowserPersistence] = None
2225
"""Optional persistence configuration for the browser session."""

src/kernel/types/browser_list_response.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010

1111

1212
class BrowserListResponseItem(BaseModel):
13-
browser_live_view_url: str
14-
"""Remote URL for live viewing the browser session"""
15-
1613
cdp_ws_url: str
1714
"""Websocket URL for Chrome DevTools Protocol connections to the browser session"""
1815

1916
session_id: str
2017
"""Unique identifier for the browser session"""
2118

19+
browser_live_view_url: Optional[str] = None
20+
"""Remote URL for live viewing the browser session.
21+
22+
Only available for non-headless browsers.
23+
"""
24+
2225
persistence: Optional[BrowserPersistence] = None
2326
"""Optional persistence configuration for the browser session."""
2427

src/kernel/types/browser_retrieve_response.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010

1111
class BrowserRetrieveResponse(BaseModel):
12-
browser_live_view_url: str
13-
"""Remote URL for live viewing the browser session"""
14-
1512
cdp_ws_url: str
1613
"""Websocket URL for Chrome DevTools Protocol connections to the browser session"""
1714

1815
session_id: str
1916
"""Unique identifier for the browser session"""
2017

18+
browser_live_view_url: Optional[str] = None
19+
"""Remote URL for live viewing the browser session.
20+
21+
Only available for non-headless browsers.
22+
"""
23+
2124
persistence: Optional[BrowserPersistence] = None
2225
"""Optional persistence configuration for the browser session."""

tests/api_resources/test_browsers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def test_method_create(self, client: Kernel) -> None:
3131
@parametrize
3232
def test_method_create_with_all_params(self, client: Kernel) -> None:
3333
browser = client.browsers.create(
34+
headless=False,
3435
invocation_id="rr33xuugxj9h0bkf1rdt2bet",
3536
persistence={"id": "my-awesome-browser-for-user-1234"},
3637
stealth=True,
@@ -221,6 +222,7 @@ async def test_method_create(self, async_client: AsyncKernel) -> None:
221222
@parametrize
222223
async def test_method_create_with_all_params(self, async_client: AsyncKernel) -> None:
223224
browser = await async_client.browsers.create(
225+
headless=False,
224226
invocation_id="rr33xuugxj9h0bkf1rdt2bet",
225227
persistence={"id": "my-awesome-browser-for-user-1234"},
226228
stealth=True,

0 commit comments

Comments
 (0)