Skip to content

Commit b1db99f

Browse files
committed
Made frameId optional
1 parent 8c3a33b commit b1db99f

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ async def main() -> None:
7373
# Navigate to a webpage
7474
await session.navigate(
7575
url="https://news.ycombinator.com",
76-
frame_id="", # empty string for the main frame
7776
)
7877
print("Navigated to Hacker News")
7978

examples/act_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async def main() -> None:
3838
# Navigate to example.com
3939
await session.navigate(
4040
url="https://www.example.com",
41-
frame_id="", # Empty string for main frame
4241
)
4342
print("Navigated to example.com")
4443

examples/full_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ async def main() -> None:
4040
# Navigate to Hacker News
4141
await session.navigate(
4242
url="https://news.ycombinator.com",
43-
frame_id="", # Empty string for main frame
4443
)
4544
print("Navigated to Hacker News")
4645

examples/local_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def main() -> None:
5252
client.sessions.navigate(
5353
id=session_id,
5454
url="https://www.example.com",
55-
frame_id="",
5655
)
5756
print("✅ Navigation complete")
5857

src/stagehand/session.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING, Union
5+
from typing import TYPE_CHECKING, Any, Union, Mapping, TypeVar, cast
66
from datetime import datetime
77
from typing_extensions import Unpack, Literal
88

@@ -23,6 +23,15 @@
2323
from .types.session_observe_response import SessionObserveResponse
2424
from .types.session_navigate_response import SessionNavigateResponse
2525

26+
TSessionParams = TypeVar("TSessionParams", bound=Mapping[str, Any])
27+
28+
29+
def _with_default_frame_id(params: TSessionParams) -> TSessionParams:
30+
prepared = dict(params)
31+
if "frame_id" not in prepared:
32+
prepared["frame_id"] = ""
33+
return cast(TSessionParams, prepared)
34+
2635
if TYPE_CHECKING:
2736
from ._client import Stagehand, AsyncStagehand
2837

@@ -49,7 +58,7 @@ def navigate(
4958
extra_query=extra_query,
5059
extra_body=extra_body,
5160
timeout=timeout,
52-
**params,
61+
**_with_default_frame_id(params),
5362
)
5463

5564
def act(
@@ -67,7 +76,7 @@ def act(
6776
extra_query=extra_query,
6877
extra_body=extra_body,
6978
timeout=timeout,
70-
**params,
79+
**_with_default_frame_id(params),
7180
)
7281

7382
def observe(
@@ -85,7 +94,7 @@ def observe(
8594
extra_query=extra_query,
8695
extra_body=extra_body,
8796
timeout=timeout,
88-
**params,
97+
**_with_default_frame_id(params),
8998
)
9099

91100
def extract(
@@ -103,7 +112,7 @@ def extract(
103112
extra_query=extra_query,
104113
extra_body=extra_body,
105114
timeout=timeout,
106-
**params,
115+
**_with_default_frame_id(params),
107116
)
108117

109118
def execute(
@@ -121,7 +130,7 @@ def execute(
121130
extra_query=extra_query,
122131
extra_body=extra_body,
123132
timeout=timeout,
124-
**params,
133+
**_with_default_frame_id(params),
125134
)
126135

127136
def end(
@@ -171,7 +180,7 @@ async def navigate(
171180
extra_query=extra_query,
172181
extra_body=extra_body,
173182
timeout=timeout,
174-
**params,
183+
**_with_default_frame_id(params),
175184
)
176185

177186
async def act(
@@ -189,7 +198,7 @@ async def act(
189198
extra_query=extra_query,
190199
extra_body=extra_body,
191200
timeout=timeout,
192-
**params,
201+
**_with_default_frame_id(params),
193202
)
194203

195204
async def observe(
@@ -207,7 +216,7 @@ async def observe(
207216
extra_query=extra_query,
208217
extra_body=extra_body,
209218
timeout=timeout,
210-
**params,
219+
**_with_default_frame_id(params),
211220
)
212221

213222
async def extract(
@@ -225,7 +234,7 @@ async def extract(
225234
extra_query=extra_query,
226235
extra_body=extra_body,
227236
timeout=timeout,
228-
**params,
237+
**_with_default_frame_id(params),
229238
)
230239

231240
async def execute(
@@ -243,7 +252,7 @@ async def execute(
243252
extra_query=extra_query,
244253
extra_body=extra_body,
245254
timeout=timeout,
246-
**params,
255+
**_with_default_frame_id(params),
247256
)
248257

249258
async def end(

tests/test_sessions_create_helper.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
from __future__ import annotations
44

55
import os
6+
import json
7+
from typing import cast
68

79
import httpx
810
import pytest
911
from respx import MockRouter
12+
from respx.models import Call
1013

1114
from stagehand import Stagehand, AsyncStagehand
1215

@@ -37,8 +40,11 @@ def test_sessions_create_returns_bound_session(respx_mock: MockRouter, client: S
3740
session = client.sessions.create(model_name="openai/gpt-5-nano")
3841
assert session.id == session_id
3942

40-
session.navigate(url="https://example.com", frame_id="")
43+
session.navigate(url="https://example.com")
4144
assert navigate_route.called is True
45+
first_call = cast(Call, navigate_route.calls[0])
46+
request_body = json.loads(first_call.request.content)
47+
assert request_body["frameId"] == ""
4248

4349

4450
@pytest.mark.respx(base_url=base_url)
@@ -67,5 +73,8 @@ async def test_async_sessions_create_returns_bound_session(
6773
session = await async_client.sessions.create(model_name="openai/gpt-5-nano")
6874
assert session.id == session_id
6975

70-
await session.navigate(url="https://example.com", frame_id="")
76+
await session.navigate(url="https://example.com")
7177
assert navigate_route.called is True
78+
first_call = cast(Call, navigate_route.calls[0])
79+
request_body = json.loads(first_call.request.content)
80+
assert request_body["frameId"] == ""

0 commit comments

Comments
 (0)