microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.97k stars 3.67k forks source link

[Feature]: Add option to disable AudioContext autoplay #33590

Open andy-fillebrown opened 1 day ago

andy-fillebrown commented 1 day ago

🚀 Feature Request

When creating a new AudioContext, its initial state is "running", which is good for testing audio, but does not reflect the initial state encountered by users of a website, which is "suspended" and requires a user interaction for the AudioContext.resume() promise to resolve.

If possible, please add an option that makes AudioContext's initial state "suspended", and require a user interaction for the AudioContext.resume() promise to resolve.

Example

No response

Motivation

This would make it possible to test the user interaction requirements for autoplay implemented by browsers. See https://developer.chrome.com/blog/autoplay for more info on Chrome's requirements. Webkit's requirements are similar.

pavelfeldman commented 1 day ago

Could you provide a full repro case and example of proposed API?

andy-fillebrown commented 1 day ago

It may not be possible without changing the browser build settings. See bootstrap.diff:23122 for the webkit build for example.

I assume there's something similar for the chromium build. It might be better to leave the autoplay build settings alone so autoplay is disabled by default, and then add CLI flags for each browser to enable it. So for chromium the flag to set would be --autoplay-policy=no-user-gesture-required. I'm not sure if there are Firefox and Webkit equivalents.

If it were done that way then ignoreDefaultArgs could be used to disable autoplay: https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-ignore-default-args.