Skip to content

fix(playwright): filter unsupported context options in persistent browser#1796

Merged
vdusek merged 7 commits intoapify:masterfrom
sushant-mutnale:fix/playwright-context-options
Mar 27, 2026
Merged

fix(playwright): filter unsupported context options in persistent browser#1796
vdusek merged 7 commits intoapify:masterfrom
sushant-mutnale:fix/playwright-context-options

Conversation

@sushant-mutnale
Copy link
Contributor

This PR fixes issue #1784, where PlaywrightCrawler would crash when passing context options (like storage_state) that are unsupported by Playwright's launch_persistent_context method.

Changes:

Implemented dynamic argument filtering in PlaywrightPersistentBrowser.new_context using inspect. signature.
Added a warning log to guide users when options are filtered out, suggesting the use of incognito pages as an alternative.
Added a unit test in

tests/unit/browsers/test_playwright_browser.py
to verify the fix and prevent regressions.
Fixes #1784

…wser

This addresses issue apify#1784 by dynamically filtering options passed to launch_persistent_context and providing a warning log for ignored options like storage_state.
@janbuchar janbuchar requested a review from Pijukatel March 16, 2026 09:11
Copy link
Collaborator

@Pijukatel Pijukatel left a comment

Choose a reason for hiding this comment

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

Hello, thanks for the PR. Please see my comments; maybe we can use this approach on a different level.

…owserController

Moving the validation logic from the browser instance to its controller as suggested by the reviewer. This improves user experience by raising TypeError for typos and nonsensical arguments while still providing helpful warnings for valid but incompatible cross-mode options like storage_state in persistent contexts. Also fixed dependency management in pyproject.toml.
@sushant-mutnale
Copy link
Contributor Author

Hello! Thank you for the detailed feedback. I've refactored the validation logic into

PlaywrightBrowserController using the suggested three-set approach with cached signatures. I also moved the dependencies back to the optional group in
pyproject.toml.

New unit tests cover both the warning and error scenarios. Ready for another look!

Removed browserforge and playwright from core dependencies in pyproject.toml as they belong in optional dependencies. Refactored Playwright signature cache in _playwright_browser_controller.py to load lazily via lru_cache rather than at module import time, preventing overhead when Playwright is not used.
Copy link
Collaborator

@Pijukatel Pijukatel left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, and apologies for the delayed review. Just a few small comments, and I think it will be ready.

Copy link
Collaborator

@vdusek vdusek left a comment

Choose a reason for hiding this comment

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

LGTM

@vdusek vdusek requested a review from Pijukatel March 26, 2026 17:01
@vdusek vdusek merged commit 69ad22e into apify:master Mar 27, 2026
30 checks passed
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.

PlaywrightCrawler __init__ method browser_new_context_options argument does not function

5 participants