Skip to content

Conversation

Sharpie
Copy link

@Sharpie Sharpie commented Sep 27, 2025

This commit adds a browser_opts keyword argument to Playwright.connect_to_browser_server that accepts a hash of launch options. This is useful for launching browsers in headful mode, or adjusting command line arguments.

See: https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-args

Copy link

vercel bot commented Sep 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
playwright-ruby-client Ignored Ignored Preview Sep 27, 2025 8:41pm

This commit adds a `browser_opts` keyword argument to
`Playwright.connect_to_browser_server` that accepts
a hash of launch options. This is useful for launching
browsers in headful mode, or adjusting command line
arguments.

See: https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-args
@YusukeIwaki
Copy link
Owner

@Sharpie Thank you for your good proposal.

It seems original Playwright implementation accepts headers param simply.
https://github.com/microsoft/playwright/blob/2c95eb1e60e2d1f458bc123ec0a11a575a93ea59/packages/playwright-core/src/client/browserType.ts#L136

We'd like to port feature from the original Playwright instead of adding ruby-specific feature.
How about adding headers instead of browser_opts ?

  module_function def connect_to_browser_server(ws_endpoint, browser_type: 'chromium', headers: {}, &block)
    known_browser_types = ['chromium', 'firefox', 'webkit']
    unless known_browser_types.include?(browser_type)
      raise ArgumentError, "Unknown browser type: #{browser_type}. Known types are: #{known_browser_types.join(', ')}"
      ws_endpoint: ws_endpoint,
      headers: { 'x-playwright-browser' => browser_type }.merge(headers),

@Sharpie
Copy link
Author

Sharpie commented Oct 7, 2025

I took a look at switching the interface to headers and there were a couple of negatives around it:

  • The list of accepted headers and their formats isn't documented anywhere that I could find. I had to grep around in the Playwright source code a bit to find x-playwright-launch-options and then guess about how to use it.

  • Using headers as the interface pushes all sorts of implementation details back to the callers of connect_to_browser_server. The headers hash must use string keys, not symbols. The value of x-playwright-launch-options needs to be a JSON string, etc.

Some of this could be handled in the function body its self, but it is a bit messy. Hashes in ruby 2.4 don't have a transform_keys method.

I can give it a shot, but so far the ergonomics feel worse.

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.

2 participants