Skip to content
22 changes: 14 additions & 8 deletions agentrun/integration/builtin/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,20 +751,26 @@ def _get_playwright(self, sb: BrowserSandbox) -> "BrowserPlaywrightSync":
Automatically recreates the connection when the thread that created it has exited,
because Playwright's internal greenlet is bound to the thread that created it.
"""
if self._playwright_sync is not None and self._playwright_thread is not None:
if (
self._playwright_sync is not None
and self._playwright_thread is not None
):
current_thread = threading.current_thread()
creator_thread = self._playwright_thread
if not creator_thread.is_alive() or current_thread is not creator_thread:
if (
not creator_thread.is_alive()
or current_thread is not creator_thread
):
if not creator_thread.is_alive():
logger.debug(
"Playwright creating thread (id=%s) has exited, recreating"
" connection",
"Playwright creating thread (id=%s) has exited,"
" recreating connection",
creator_thread.ident,
)
else:
logger.debug(
"Playwright creating thread (id=%s) differs from current"
" thread (id=%s), recreating connection",
"Playwright creating thread (id=%s) differs from"
" current thread (id=%s), recreating connection",
creator_thread.ident,
current_thread.ident,
)
Expand Down Expand Up @@ -970,7 +976,7 @@ def goto(self, url: str) -> Dict[str, Any]:
)
def browser_navigate_back(
self,
wait_until: str = "load",
wait_until: str = "domcontentloaded",
timeout: Optional[float] = None,
Comment on lines +979 to 980
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description references fixing issue #66, but the code change here only updates the default wait_until value for back/forward navigation. Please either update the PR description/issue reference to match the actual change, or include the missing code changes intended to address #66.

Copilot uses AI. Check for mistakes.
) -> Dict[str, Any]:
"""返回上一页 / Go back to previous page"""
Expand All @@ -996,7 +1002,7 @@ def inner(sb: Sandbox):
)
def browser_go_forward(
self,
wait_until: str = "load",
wait_until: str = "domcontentloaded",
timeout: Optional[float] = None,
Comment on lines 1004 to 1006
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes behavior by altering the default wait_until for browser_navigate_back/browser_go_forward, but there are no unit tests asserting the new defaults. Consider adding a small test (e.g., via inspect.signature) to lock in the new default and prevent accidental regressions.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

) -> Dict[str, Any]:
"""前进到下一页 / Go forward to next page"""
Expand Down
24 changes: 24 additions & 0 deletions tests/unittests/integration/test_browser_toolset_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,27 @@ def callback(sb):
assert "error" in result
toolset._reset_playwright.assert_not_called()
assert toolset.sandbox is original_sandbox


class TestBrowserNavigationDefaults:
"""测试导航方法的默认参数 / Tests for default parameters of navigation methods"""

def test_browser_navigate_back_default_wait_until(self):
"""browser_navigate_back 的默认 wait_until 为 domcontentloaded"""
fields = BrowserToolSet.browser_navigate_back.args_schema.model_fields
assert fields["wait_until"].default == "domcontentloaded"

def test_browser_go_forward_default_wait_until(self):
"""browser_go_forward 的默认 wait_until 为 domcontentloaded"""
fields = BrowserToolSet.browser_go_forward.args_schema.model_fields
assert fields["wait_until"].default == "domcontentloaded"

def test_browser_navigate_back_default_timeout_is_none(self):
"""browser_navigate_back 的默认 timeout 为 None"""
fields = BrowserToolSet.browser_navigate_back.args_schema.model_fields
assert fields["timeout"].default is None

def test_browser_go_forward_default_timeout_is_none(self):
"""browser_go_forward 的默认 timeout 为 None"""
fields = BrowserToolSet.browser_go_forward.args_schema.model_fields
assert fields["timeout"].default is None
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ async def invoke_agent(request: AgentRequest):
tools=tools,
)

input_data = {
input_data: Any = {
"messages": [{
"role": "user",
"content": (
Expand Down
Loading