Skip to content

browser: pass _default_context_options into new_context#455

Open
SAY-5 wants to merge 1 commit intostrands-agents:mainfrom
SAY-5:fix-browser-context-options-414
Open

browser: pass _default_context_options into new_context#455
SAY-5 wants to merge 1 commit intostrands-agents:mainfrom
SAY-5:fix-browser-context-options-414

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 17, 2026

Fixes #414.

Problem

LocalChromiumBrowser accepts a context_options kwarg in its constructor, merges it into self._default_context_options, and stores it correctly. But the base class Browser._setup_session_from_browser ignores the dict and calls new_context() with no arguments:

if isinstance(browser_or_context, PlaywrightBrowser):
    session_browser = browser_or_context
    session_context = await session_browser.new_context()   # ← drops options
    session_page = await session_context.new_page()

Result: viewport, user_agent, storage_state, locale, timezone_id, geolocation, permissions, color_scheme, …all silently ignored. The reporter's proof script shows viewport = 1280x720 (Playwright default) instead of the requested 1920x1080.

Particularly impactful for storage_state, the standard Playwright mechanism for reusing authentication across browser contexts. There is no public-API workaround; users today have to subclass and override _setup_session_from_browser.

Fix

  • Initialize _default_context_options: Dict[str, Any] = {} on the base Browser.__init__ (empty default → no behaviour change for subclasses that don't populate it).
  • Pass **self._default_context_options into session_browser.new_context(...) in the non-persistent branch of _setup_session_from_browser.

LocalChromiumBrowser already populates the dict during start_platform(), so users who passed context_options to its constructor now actually see those options applied.

Back-compat

  • The persistent-context branch is untouched (it receives an already-constructed context from the caller).
  • Subclasses that don't set _default_context_options get the empty-dict default, so new_context(**{}) is a no-op equivalent to today's new_context().

Signed off per DCO.

Reported as strands-agents#414. LocalChromiumBrowser accepts a
context_options kwarg in its constructor, merges it into
self._default_context_options, and stores it correctly. But the base
Browser._setup_session_from_browser calls session_browser.new_context()
with no arguments, so the stored options never make it to Playwright.
Viewport, user_agent, storage_state, locale, timezone_id, geolocation,
permissions, color_scheme... all silently ignored.

Initialise _default_context_options on the base Browser class (empty
dict, no behaviour change for subclasses that don't set it) and unpack
it when creating the non-persistent context. LocalChromiumBrowser
already populates the dict, so users who passed context_options to its
constructor now actually see those options applied.

Persistent-context branch is left alone because it receives a
user-supplied context object instead of creating one.

Fixes strands-agents#414

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5 SAY-5 requested a deployment to manual-approval April 17, 2026 19:45 — with GitHub Actions Waiting
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.

[BUG] Browser tool context_options silently ignored during session creation

1 participant