feat(browser-api): enhance WebSocket URL generation with header support#78
feat(browser-api): enhance WebSocket URL generation with header support#78
Conversation
Add overloads to get_cdp_url and get_vnc_url methods to support returning authentication headers along with URLs. Introduce Config parameter for optional configuration overrides and improve URL assembly logic with proper tenant ID and recording parameters. The changes provide backward compatibility while enabling header-based authentication for WebSocket connections. feat(browser-api): 增强WebSocket URL生成以支持头部信息 为get_cdp_url和get_vnc_url方法添加重载以支持返回认证头部与URL。 引入Config参数用于可选配置覆盖,并改进URL组装逻辑,包含适当的租户ID和录制参数。 这些更改提供向后兼容性,同时启用基于头部的WebSocket连接认证。 Change-Id: Id927aa50801374160670c13b8a4dfab37d302ad9 Signed-off-by: OhYee <oyohyee@oyohyee.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances the Python SDK’s browser-related WebSocket URL helpers to optionally return authentication headers alongside the URL, and refactors URL assembly to consistently include tenantId and optional recording=true query parameters while maintaining backward-compatible return types.
Changes:
- Added
with_headersoverloads toget_cdp_url/get_vnc_urlacross sandbox high-level APIs and data APIs (returning eitherstror(url, headers)). - Refactored WebSocket URL construction into shared helpers and updated Playwright helpers to reuse the header-producing path.
- Updated
CustomSandbox.get_base_url()to return a non--ramendpoint URL and refreshed unit tests accordingly.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| agentrun/sandbox/api/browser_data.py | Refactors WS URL building; adds with_headers overloads returning (url, headers) |
| agentrun/sandbox/api/aio_data.py | Same WS URL/header overload changes for AIO data API |
| agentrun/sandbox/browser_sandbox.py | Adds overloads/params on high-level BrowserSandbox URL helpers |
| agentrun/sandbox/aio_sandbox.py | Adds overloads/params on high-level AioSandbox URL helpers |
| agentrun/sandbox/custom_sandbox.py | Changes custom sandbox base URL generation to use non-RAM data endpoint |
| agentrun/sandbox/api/__browser_data_async_template.py | Codegen template updated to match BrowserDataAPI changes |
| agentrun/sandbox/api/__aio_data_async_template.py | Codegen template updated to match AioDataAPI changes |
| agentrun/sandbox/__browser_sandbox_async_template.py | Codegen template updated for BrowserSandbox overloads |
| agentrun/sandbox/__aio_sandbox_async_template.py | Codegen template updated for AioSandbox overloads |
| tests/unittests/sandbox/api/test_browser_data.py | Updates/extends tests for WS URL generation and header-returning mode |
| tests/unittests/sandbox/api/test_aio_data.py | Updates/extends tests for WS URL generation and header-returning mode |
| tests/unittests/sandbox/test_browser_sandbox.py | Updates mock expectations for new parameters passed through |
| tests/unittests/sandbox/test_custom_sandbox.py | Updates tests to validate new non-RAM base URL behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _auth_side_effect(url="", headers=None, query=None, **kw): | ||
| return ( | ||
| url, | ||
| {"Authorization": "Bearer tok", **(headers or {})}, | ||
| query, | ||
| ) |
There was a problem hiding this comment.
The production DataAPI.auth() returns RAM signature headers like Agentrun-Authorization/x-acs-date, not an Authorization: Bearer ... header. These tests stub auth() to return an Authorization header and then assert on that key, which doesn’t reflect the real contract and may miss regressions. Prefer asserting on the actual signature header keys (or patch get_agentrun_signed_headers for determinism and let auth() run) and use a config with AK/SK to exercise the header-based auth path.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
Add overloads to get_cdp_url and get_vnc_url methods to support returning authentication headers along with URLs. Introduce Config parameter for optional configuration overrides and improve URL assembly logic with proper tenant ID and recording parameters.
The changes provide backward compatibility while enabling header-based authentication for WebSocket connections.
feat(browser-api): 增强WebSocket URL生成以支持头部信息
为get_cdp_url和get_vnc_url方法添加重载以支持返回认证头部与URL。
引入Config参数用于可选配置覆盖,并改进URL组装逻辑,包含适当的租户ID和录制参数。
这些更改提供向后兼容性,同时启用基于头部的WebSocket连接认证。
Change-Id: Id927aa50801374160670c13b8a4dfab37d302ad9
Fix bugs
Bug detail
Pull request tasks
Update docs
Reason for update
Pull request tasks
Add contributor
Contributed content
Content detail
Others
Reason for update