Skip to content

feat(browser-api): enhance WebSocket URL generation with header support#78

Merged
OhYee merged 7 commits intomainfrom
fix-new-auth
Apr 3, 2026
Merged

feat(browser-api): enhance WebSocket URL generation with header support#78
OhYee merged 7 commits intomainfrom
fix-new-auth

Conversation

@OhYee
Copy link
Copy Markdown
Member

@OhYee OhYee commented Apr 1, 2026

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

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

The specific manifestation of the bug or the associated issue.

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_headers overloads to get_cdp_url / get_vnc_url across sandbox high-level APIs and data APIs (returning either str or (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--ram endpoint 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.

Comment on lines +32 to +37
def _auth_side_effect(url="", headers=None, query=None, **kw):
return (
url,
{"Authorization": "Bearer tok", **(headers or {})},
query,
)
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
OhYee and others added 3 commits April 1, 2026 18:11
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>
@OhYee
Copy link
Copy Markdown
Member Author

OhYee commented Apr 3, 2026

@copilot
=========================== short test summary info ============================
FAILED tests/unittests/sandbox/api/test_aio_data.py::TestAioCdpUrl::test_get_cdp_url_no_record - TypeError: AioDataAPI._build_ws_url() got an unexpected keyword argument 'config'
FAILED tests/unittests/sandbox/api/test_aio_data.py::TestAioCdpUrl::test_get_cdp_url_with_record - TypeError: AioDataAPI._build_ws_url() got an unexpected keyword argument 'config'
FAILED tests/unittests/sandbox/api/test_aio_data.py::TestAioVncUrl::test_get_vnc_url_no_record - TypeError: AioDataAPI._build_ws_url() got an unexpected keyword argument 'config'
FAILED tests/unittests/sandbox/api/test_aio_data.py::TestAioVncUrl::test_get_vnc_url_with_record - TypeError: AioDataAPI._build_ws_url() got an unexpected keyword argument 'config'
FAILED tests/unittests/sandbox/api/test_browser_data.py::TestVncUrl::test_get_vnc_url_no_record - TypeError: BrowserDataAPI._build_ws_url() got an unexpected keyword argument 'config'
FAILED tests/unittests/sandbox/api/test_browser_data.py::TestVncUrl::test_get_vnc_url_with_record - TypeError: BrowserDataAPI._build_ws_url() got an unexpected keyword argument 'config'
======= 6 failed, 2775 passed, 4 skipped, 9 warnings in 63.70s (0:01:03) =======

OhYee and others added 3 commits April 3, 2026 18:30
Updated the query parameter handling in get_agentrun_signed_headers to decode both keys and values using unquote. This ensures that the headers are correctly signed when special characters are present in the query string.

修复(ram_signature):在签名头中解码查询参数
更新 get_agentrun_signed_headers 中的查询参数处理,以使用 unquote 解码键和值。这确保在查询字符串中存在特殊字符时,头部能够正确签名。

Change-Id: If1ca01053877ec382044ffc84b4db0e81ecf0610
Signed-off-by: OhYee <oyohyee@oyohyee.com>
…ket URL methods

Removed the config parameter from the _build_ws_url method calls in both AioDataAPI and BrowserDataAPI classes. This simplifies the method signature and improves code clarity by eliminating unnecessary arguments.
---
修复(aio_data, browser_data): 移除 WebSocket URL 方法中未使用的 config 参数
在 AioDataAPI 和 BrowserDataAPI 类中移除了 _build_ws_url 方法调用中的 config 参数。这简化了方法签名,并通过消除不必要的参数提高了代码清晰度。

Change-Id: I657c950ed45ff35e830ad7601008cb05dad7ac38
Signed-off-by: OhYee <oyohyee@oyohyee.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

@copilot
=========================== short test summary info ============================
FAILED tests/unittests/sandbox/api/test_aio_data.py::TestAioCdpUrl::test_get_cdp_url_no_record - TypeError:...

Fixed in b49ff60. The root cause was that previous review suggestions passed config=config to _build_ws_url(), but that method didn't accept a config parameter. Updated _build_ws_url in both browser_data.py and aio_data.py (and their templates) to accept config: Optional[Config] = None and use Config.with_configs(self.config, config).get_data_endpoint() for the URL base — so the config override is now properly applied in the non-headers path too.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of OhYee April 3, 2026 10:34
@OhYee OhYee merged commit 3c54da1 into main Apr 3, 2026
1 of 2 checks passed
@OhYee OhYee deleted the fix-new-auth branch April 3, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants