Skip to content

Add browser_launch_opts config option#149

Merged
ftes merged 11 commits intoftes:mainfrom
srcrip:add-browser-launch-opts
Mar 3, 2026
Merged

Add browser_launch_opts config option#149
ftes merged 11 commits intoftes:mainfrom
srcrip:add-browser-launch-opts

Conversation

@srcrip
Copy link
Contributor

@srcrip srcrip commented Mar 2, 2026

This adds a new browser_launch_opts configuration option that allows passing additional arguments to Playwright's browserType.launch().

Example usage:

config :phoenix_test,
  playwright: [
    browser_launch_opts: [
      args: [
        "--use-fake-ui-for-media-stream",
        "--use-fake-device-for-media-stream"
      ]
    ]
  ]

There are existing options for messing with the Page Context and Browser Context, I'm not a playwright expert so I'm not even 100% on how these things differ, and the playwright API is quite complex, but basically although there's a lot of overlap here, you can't use those configs to edit what is actually sent to playwright when you start the browser process--which is what you need to do if you want to pass cli level flags to the browser.

The background on this is at Jump, where we use your library quite a bit, we have a react powered audio recorder interface that does not load properly in our playwright tests. I realized we could actually get it to initialize properly if we pass the --use-fake-ui-for-media-stream and -use-fake-device-for-media-stream flags to the browser when playwright initializes it.

Obviously every playwright API is a little different, and in this library we have this pattern of configuring a lot of stuff in the global config + the overrides in exunit tags, so that seemed like a good way to go about it.

This kinda page is the closest to some kind of official documentation on this on the playwright docs site, but its also not very well documented even in playwright itself that you can do this. In fact they kind of discourage you from doing it almost, but it does in fact work: https://playwright.dev/docs/api/class-browsertype#browser-type-launch

This adds a new `browser_launch_opts` configuration option that allows
passing additional arguments to Playwright's browserType.launch().

This is useful for scenarios like:
- Enabling fake media streams for testing audio/video capture
- Passing custom browser flags for specific test requirements

Example usage:
```elixir
config :phoenix_test,
  playwright: [
    browser_launch_opts: [
      args: [
        "--use-fake-ui-for-media-stream",
        "--use-fake-device-for-media-stream"
      ]
    ]
  ]
```
@srcrip srcrip force-pushed the add-browser-launch-opts branch from 2d289cd to 12bb360 Compare March 2, 2026 20:03
Copy link
Owner

@ftes ftes left a comment

Choose a reason for hiding this comment

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

Nice, I like it.

Thanks Andrew, also for taking the time to describe your use case.
I find that very valuable as reference.

Just some minor comments before we get this in.

Test getUserMedia with and without fake media device flags to verify
the browser launch options actually affect browser behavior.
@srcrip
Copy link
Contributor Author

srcrip commented Mar 2, 2026

thanks for the fast response @ftes, I just commited a better test and I'll make the changes you requested here.

@srcrip
Copy link
Contributor Author

srcrip commented Mar 2, 2026

ok @ftes, feel free to review now.

@srcrip srcrip requested a review from ftes March 2, 2026 20:53
@srcrip
Copy link
Contributor Author

srcrip commented Mar 2, 2026

also, do you want me to create a PR to playwright_ex as well documenting this on that side? Right now it works because playwright_ex allows these undocumented configs, but it would probably be good to document it as well.

Copy link
Owner

@ftes ftes left a comment

Choose a reason for hiding this comment

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

Beautiful, I like the integration test.

Couple more suggestions/questions.

@srcrip srcrip requested a review from ftes March 3, 2026 18:06
@srcrip
Copy link
Contributor Author

srcrip commented Mar 3, 2026

ok ready again @ftes

end
end

defmodule PhoenixTest.Playwright.BrowserLaunchOptsWithoutFlagsTest do
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@ftes
Copy link
Owner

ftes commented Mar 3, 2026

Beautiful, let's get this merged.

also, do you want me to create a PR to playwright_ex as well documenting this on that side? Right now it works because playwright_ex allows these undocumented configs, but it would probably be good to document it as well.

Sure, would be great to document args and maybe other options that BrowserType.launch accepts.

@ftes ftes enabled auto-merge (squash) March 3, 2026 19:23
@ftes
Copy link
Owner

ftes commented Mar 3, 2026

Looks like we have to skip these for websocket connection.

@ftes ftes merged commit 4ec7d61 into ftes:main Mar 3, 2026
3 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.

3 participants