Skip to content

feat: pass connection requests to context admission policies - #5657

Merged
ahmedAmien merged 2 commits into
mainfrom
feat/request-aware-context-policy
Nov 4, 2026
Merged

ahmedAmien merged 2 commits into
mainfrom
feat/request-aware-context-policy

Conversation

@artiom

@artiom artiom commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Pass the connection's Request to the optional Config context-policy hooks in the CDP browser/page bridges and the Playwright bridge. Existing overrides can continue to omit the new optional parameter, and the default hooks retain their behavior.

Add coverage for request forwarding and isolation between connections through Playwright newContext, newContextForReuse, and CDP session messages.

Validation

  • Clean npm ci --ignore-scripts, TypeScript build, ESLint, and formatting checks passed on Node 26.13.0.
  • Targeted CDP, Playwright, and Config tests: 154 passing, zero pending or failing with native Chromium.
  • FFmpeg installer tests: 9 passing.
  • Independent review reproduced 154 passing / zero pending using Chrome 156 instead of the pinned Chromium build, and passed clean install, TypeScript, and ESLint checks.

The full test suite was not rerun on this candidate. The local dependency installation did not run lifecycle scripts. Validation covers SDK hooks and browser bridges, not downstream application integration.

Summary by CodeRabbit

  • New Features
    • Browser WebSocket configuration hooks can now receive the incoming request, allowing context options and CDP policies to vary by request.
    • WebSocket connections can be admitted or denied based on request details, including the request URL and origin.
  • Bug Fixes
    • Client origin headers are no longer forwarded to upstream WebSocket connections.

Devin Review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The configuration hooks now accept an optional Request. The CDP and Playwright WebSocket proxies pass the incoming request to the hooks. Tests check request-specific policy inputs, admission outcomes, and upstream Origin headers.

Changes

Request context in browser bridges

Layer / File(s) Summary
Request-aware hook signatures
src/config.ts
preparePlaywrightContextOptions and getCDPContextPolicy now accept an optional Request. Their default behavior remains unchanged.
Proxy request forwarding and admission checks
src/browsers/browsers.cdp.ts, src/browsers/browsers.cdp.spec.ts, src/browsers/browsers.playwright.ts, src/browsers/browsers.playwright.spec.ts
The CDP and Playwright proxies pass the incoming request to the configuration hooks. Context-policy paths retain the request URL and Origin for policy checks. Tests check connection-specific policy inputs, denied connections closing with code 1008, allowed messages reaching upstream, and upstream connections receiving no Origin header.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant BrowserProxy
  participant ConfigHooks
  participant UpstreamWebSocket
  Client->>BrowserProxy: WebSocket request with URL and Origin
  BrowserProxy->>ConfigHooks: pass request to policy hooks
  ConfigHooks-->>BrowserProxy: return policy result
  BrowserProxy->>UpstreamWebSocket: connect without forwarding client headers
Loading

Possibly related PRs

  • browserless/browserless#5635: Introduces the configuration hooks and their browser-bridge call sites, which this change updates to accept and pass the request.

Suggested reviewers: xrazik1, adriansillo

Merge Risk: Moderate · up to 5eef1

CDP admission policies may evaluate an altered URL for authenticated connections; preserve the client request metadata before applying authentication normalization.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat: pass connection requests to context admission policies" matches the main change. The raw summary shows that the Config hooks preparePlaywrightContextOptions and `getCDPContextPolicy…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat: pass connection requests to context admission policies" matches the main change. The raw summary shows that the Config hooks preparePlaywrightContextOptions and getCDPContextPolicy now receive an optional Request, and the CDP and Playwright bridges forward the incoming request to them. The title is specific, uses conventional commit form, and is 60 characters long. The summary also mentions removing Origin header handling, which the title does not cover, but that is secondary to the main change.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 5 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each socket's path,
And keeps the Origin in its grasp.
A policy sees the request arrive,
Denied links close; allowed ones thrive.
Upstream gets no Origin to pass,
The rabbit hops through fields of grass.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: af7086e5-5777-4ba4-bf1e-8ba1be11c681
Commits

Reviewing files that changed from the base of the PR and between 42b77ec and 5eef1b0.

Files selected for processing: 4
  • src/browsers/browsers.cdp.spec.ts
  • src/browsers/browsers.cdp.ts
  • src/browsers/browsers.playwright.spec.ts
  • src/browsers/browsers.playwright.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

coderabbitai[bot]

This comment was marked as resolved.

@artiom
artiom marked this pull request as ready for review November 3, 2026 21:32

artiom commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Ready for human review at 5eef1b0. Both URL/Origin findings are fixed and their review threads are resolved; CodeRabbit reports no new actionable comments for this head. All applicable current-head checks passed, including Chrome, Chromium, Firefox, WebKit, Edge, multi-browser, leak-check, lint, formatting and CodeQL. The optional Dependabot automerge job was skipped. GitHub reports no merge conflict; human approval remains outstanding.

Regression evidence: the nine affected transport cases failed before the fix and passed afterward. The targeted native suite passed 154 tests with zero pending; independent review reproduced that result using Chrome 156 in place of the pinned Chromium build. Separate browser/page legacy-proxy controls passed locally. The full suite was not rerun locally, and downstream application integration is not claimed. No findings were rejected.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@ahmedAmien
ahmedAmien merged commit 087373b into main Nov 4, 2026
17 checks passed
@ahmedAmien
ahmedAmien deleted the feat/request-aware-context-policy branch November 4, 2026 08:57
artiom pushed a commit that referenced this pull request Nov 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.59.0](v2.58.3...v2.59.0)
(2026-11-04)


### Features

* pass connection requests to context admission policies
([#5657](#5657))
([087373b](087373b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: browserless-actions-bot[bot] <186328842+browserless-actions-bot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.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.

3 participants