Skip to content

Centralize session-scoped CDP settings to prevent drift across contexts #1180

@ctate

Description

@ctate

Problem

Session-scoped CDP settings are applied individually at browser launch and must be manually re-applied whenever a new CDP session is created (e.g., record start). This is error-prone — each new session-scoped setting requires a matching re-application in every code path that creates a new session, and omissions cause silent failures.

#1178 fixed this for Security.setIgnoreCertificateErrors, matching the earlier fix for Browser.setDownloadBehavior. But two other launch-time settings have the same gap today:

Setting Applied at launch Re-applied to recording context
Emulation.setUserAgentOverride (--user-agent) Yes (browser.rs:302) No
Emulation.setEmulatedMedia (--color-scheme) Yes (browser.rs:313) No

Any future session-scoped setting added to launch() will silently break in recording contexts unless someone remembers to add the corresponding re-application in handle_recording_start.

Proposed fix

Extract a single apply_session_settings(&self, session_id) method on BrowserManager that applies all session-scoped settings (ignore_https_errors, user_agent, color_scheme, and any future additions). Call it from both:

  1. launch() — after initial target discovery
  2. handle_recording_start() — after attaching to the new recording session

This eliminates the duplication and ensures new settings are automatically covered in all contexts.

Scope

  • Store user_agent: Option<String> and color_scheme: Option<String> on BrowserManager (same pattern as ignore_https_errors and download_path)
  • Create apply_session_settings that applies all session-scoped CDP commands
  • Replace the inline calls in launch() and handle_recording_start() with a single call to the new method
  • Add a code comment on the method noting that any new session-scoped CDP setting should be added here

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions