Centralize session-scoped CDP settings to prevent drift across contexts#1181
Open
Centralize session-scoped CDP settings to prevent drift across contexts#1181
Conversation
This PR fixes an issue where session-scoped CDP settings configured at browser launch were not being re-applied to new CDP sessions/contexts, causing silent failures when users expected consistent behavior. ## Problem Settings like `--user-agent`, `--color-scheme`, `--ignore-https-errors`, and download behavior were applied during initial browser launch but not propagated to new contexts created by `record start`, `tab new`, or `window new` operations. This meant recordings and new tabs would silently lose these configured behaviors. ## Changes - **Centralized settings application**: Created `BrowserManager::apply_session_settings()` method that applies all session-scoped CDP commands in one place - **Extended state storage**: Added `user_agent` and `color_scheme` fields to `BrowserManager` to persist launch-time configuration - **Consistent application**: Updated all session creation code paths to call `apply_session_settings()` after attaching to new sessions - **Eliminated duplication**: Replaced inline CDP calls in `launch()` and `handle_recording_start()` with centralized method ## Implementation Details The new `apply_session_settings()` method handles the context-specific requirements of different CDP commands (e.g., `Browser.setDownloadBehavior` requires `browserContextId` parameter) and ensures all current and future session-scoped settings are automatically applied to every new session. Fixes #1180
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where session-scoped CDP settings configured at browser launch were not being re-applied to new CDP sessions/contexts, causing silent failures when users expected consistent behavior.
Problem
Settings like
--user-agent,--color-scheme,--ignore-https-errors, and download behavior were applied during initial browser launch but not propagated to new contexts created byrecord start,tab new, orwindow newoperations. This meant recordings and new tabs would silently lose these configured behaviors.Changes
BrowserManager::apply_session_settings()method that applies all session-scoped CDP commands in one placeuser_agentandcolor_schemefields toBrowserManagerto persist launch-time configurationapply_session_settings()after attaching to new sessionslaunch()andhandle_recording_start()with centralized methodImplementation Details
The new
apply_session_settings()method handles the context-specific requirements of different CDP commands (e.g.,Browser.setDownloadBehaviorrequiresbrowserContextIdparameter) and ensures all current and future session-scoped settings are automatically applied to every new session.Fixes #1180