Skip to content

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

Open
OhYee wants to merge 4 commits intomainfrom
fix-new-auth
Open

feat(browser-api): enhance WebSocket URL generation with header support#78
OhYee wants to merge 4 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>
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.

2 participants