Skip to content

Enhance User-Agent header handling in BrowserSession#4431

Merged
reformedot merged 3 commits into
mainfrom
feat/add-custom-ua
Mar 20, 2026
Merged

Enhance User-Agent header handling in BrowserSession#4431
reformedot merged 3 commits into
mainfrom
feat/add-custom-ua

Conversation

@reformedot
Copy link
Copy Markdown
Collaborator

@reformedot reformedot commented Mar 20, 2026

  • Updated the BrowserSession class to ensure the User-Agent header is set correctly for both local and remote connections.
  • Introduced a utility function to retrieve the browser-use version and incorporated it into the User-Agent string.
  • Ensured headers are consistently handled as dictionaries to avoid potential issues with None values.

This change improves the reliability of the CDP client communication by providing a proper User-Agent, which can be crucial for certain web interactions.


Summary by cubic

Ensure BrowserSession always sends a proper User-Agent and preserves user headers. Injects default browser-use/<version> for remote CDP and /json/version requests to improve version discovery and WebSocket stability.

  • Bug Fixes
    • Inject default browser-use/<version> for /json/version and remote CDP; preserve all user headers and any existing User-Agent.
    • Normalize headers to dicts; pass None only for local when empty; always include User-Agent for remote, even with no user headers.
    • Apply in both connect and reconnect; tests tightened to verify these cases and updated with a clearer User-Agent assertion.

Written for commit ad41865. Summary will update on new commits.

- Updated the BrowserSession class to ensure the User-Agent header is set correctly for both local and remote connections.
- Introduced a utility function to retrieve the browser-use version and incorporated it into the User-Agent string.
- Ensured headers are consistently handled as dictionaries to avoid potential issues with None values.

This change improves the reliability of the CDP client communication by providing a proper User-Agent, which can be crucial for certain web interactions.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 20, 2026

Agent Task Evaluation Results: 2/2 (100%)

View detailed results
Task Result Reason
amazon_laptop ✅ Pass Skipped - API key not available (fork PR or missing secret)
browser_use_pip ✅ Pass Skipped - API key not available (fork PR or missing secret)

Check the evaluate-tasks job for detailed task execution logs.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

- Improved assertions in tests to ensure all user-provided headers are present in the additional_headers.
- Added checks to confirm that the User-Agent header is injected for remote connections, ensuring consistent behavior across tests.
- Updated the test for the /json/version endpoint to validate the presence and format of the User-Agent header.

These changes enhance the reliability of header handling in the CDP client tests.
- Updated the assertion for the User-Agent header in the /json/version endpoint test to improve readability by using a multi-line format.
- This change enhances the clarity of the test's intent while maintaining the existing validation logic.

These modifications contribute to better maintainability of the test code.
@reformedot reformedot merged commit 51ac1fb into main Mar 20, 2026
82 checks passed
@reformedot reformedot deleted the feat/add-custom-ua branch March 20, 2026 07:52
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.

1 participant