Skip to content

Feature: Add launch_persistent_context/2 and connect_over_cdp/2 to BrowserType#41

Open
joshuambg wants to merge 1 commit intoftes:mainfrom
joshuambg:main
Open

Feature: Add launch_persistent_context/2 and connect_over_cdp/2 to BrowserType#41
joshuambg wants to merge 1 commit intoftes:mainfrom
joshuambg:main

Conversation

@joshuambg
Copy link
Copy Markdown

This PR implements two new channel functions in BrowserType to support Playwright's alternative browser launch methods, expanding the client's capabilities to handle persistent user sessions and external CDP connections.

It also adds top-level helper functions to the main PlaywrightEx module to ensure API parity with the existing launch_browser/2 flow.

All code unapologetically generated by AI (Gemini Pro).

Changes

  • Added PlaywrightEx.BrowserType.launch_persistent_context/2:
    • Implemented to map to Playwright's browserType.launchPersistentContext().
    • Returns a BrowserContext (with an embedded tracing resource) directly, rather than a Browser.
    • Requires a user_data_dir parameter for storing cookies/local storage across sessions.
  • Added PlaywrightEx.BrowserType.connect_over_cdp/2:
    • Implemented to map to Playwright's browserType.connectOverCDP().
    • Returns a connected Browser resource.
    • Requires an endpoint_url parameter.
  • Added top-level helpers in PlaywrightEx:
    • Added PlaywrightEx.launch_persistent_context/2 and PlaywrightEx.connect_over_cdp/2.
    • Both helpers extract the browser type GUID from the Playwright initializer and route the call to the corresponding BrowserType module correctly.
  • Protocol Parameter Overrides & Casing Fixes:
    • Explicitly mapped the internal method name :connectOverCDP to prevent Macro.camelize/1 from generating connectOverCdp (lowercase dp), which causes Playwright's schema validator to reject the request with Unknown scheme for Params: BrowserType.connectOverCdp.
    • Manually mapped endpoint_url to endpointURL in the parameters map for the same reason.
  • Documentation:
    • Added corresponding @doc strings, schemas, and typespecs to match the existing library pattern.
    • Updated README.md to include examples of these alternative launch methods.

Testing

Tests for both features have been successfully run in test/browser_type_test.exs.

  • launch_persistent_context/2 verifies that a BrowserContext structure is correctly returned and functioning, and asserts that the user_data_dir directory is populated.
  • connect_over_cdp/2 confirms that the Playwright connection correctly attempts to connect using the exact connectOverCDP schema syntax, resulting in the expected ECONNREFUSED error during test validation.

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.

1 participant