feat: export build_launch_options helper for composing with existing Playwright instance#255
Conversation
|
Thanks for the PR, @mvanhorn! This addresses #153 nicely. Two things before we can merge:
Let us know if you'd like to update, or we can handle it on our end. |
|
Thanks for the careful review. Both items addressed in 17c85c3:
Let me know if you'd prefer a single |
…Playwright Adds build_launch_options() (re-exported from the package) that performs every step launch() does up to the pw.chromium.launch() call and returns the kwargs dict, so callers can drive their own Playwright instance. launch() and launch_async() both delegate to it so their arg-building can't diverge. Also adds humanize_browser() / humanize_browser_async() for parity with the JS side, applying the same humanize patching to a user-supplied browser. Closes CloakHQ#153.
17c85c3 to
cab003b
Compare
|
Both done, and rebased onto main (force-pushed).
Verified: the build_launch_options + delegation tests pass, including a new one asserting launch_async delegates. The only failing tests locally are the real-browser bot-detection ones that need the licensed binary, and those fail the same way on main. |
Summary
Users who run their own
sync_playwright()context can now pull CloakBrowser's launch args into it with one call instead of copying the body oflaunch()each release.Why this matters
In #153, @chrisemke described maintaining scrapers that share a single Playwright instance across multiple stealth backends, and asked whether
launch()could accept aplaywrightparam or expose a lower-level helper. The maintainer reply asked the same question.This PR takes the lower-level-helper route to keep the existing
launch()signature stable. Adding aplaywright=kwarg can layer on later if preferred - it composes with this helper.Testing
test_build_args,test_config,test_proxy,test_backend,test_geoip,test_extension_loading.py_compileclean acrosscloakbrowser/browser.py,cloakbrowser/__init__.py,examples/external_playwright.py.build_launch_options()returnsexecutable_path,headless,args,ignore_default_args; adds aproxydict only when a proxy URL is passed.launch()is refactored to delegate tobuild_launch_options(), so the existing call path produces identical kwargs forpw.chromium.launch().examples/external_playwright.pyshows thesync_playwright() + build_launch_options()pattern from the maintainer reply.Scope kept to the sync path. Async
launch_async,launch_context,launch_persistent_contextare untouched and can follow as a separate PR if useful.Fixes #153