Open matecsaj opened 1 year ago
There is no such option in WebKit. I'll leave it open as a feature request. Can you tell us a bit more about your use case and why you need it?
I use Playwright to automate something repetitive that I need to do on a noisy website. I settled on using WebKit because the website renders inconsistently with Chromium and Firefox. I run the automation headless while doing other work, and the random noises disturb my concentration.
I get that most people probably use Playwriter for testing. Imagine someone running current tests on a noisy website. Oh my, the overlapping audio would be awful.
Turning off all the sound on the computer is not practical because someone could, for example, initiate a video conference while you happen to be running Playwright.
A website has the stuff to see and stuff to hear. Currently, Playwright has a headless option to suppress visuals but nothing for sounds.
Instead of a WebKit-specific muting arg, it would be lovely if the launch method had a browser-agnostic keyword argument mute=True or False, which defaults to False for backward compatibility.
+1 for this. I want to be able to demo concurrently running tests on a video call. The audio and text-to-speech involved is overwhelming, and there's no apparent workaround.
If you just want to temporarily avoid this issue, you can consider injecting a JavaScript script
like this:
AUDIO_MUTE_JS_SCRIPT = """() => {
function disableVideoFeatures(video) {
video.autoplay = false;
video.muted = true;
video.src = '';
}
let videos_playwright = document.getElementsByTagName('video');
for (let i = 0; i < videos_playwright.length; i++) {
disableVideoFeatures(videos_playwright[i]);
}
let observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node instanceof HTMLVideoElement) {
disableVideoFeatures(node);
} else if (node.getElementsByTagName) {
let videos = node.getElementsByTagName('video');
for (let i = 0; i < videos.length; i++) {
disableVideoFeatures(videos[i]);
}
}
});
});
});
let config_playwright = { childList: true, subtree: true };
observer.observe(document.body, config_playwright);
}"""
await self.page.goto(base_url)
await self.page.evaluate(AUDIO_MUTE_JS_SCRIPT)
+1
+1
The Playwright documentation has a link to args for Chromium but not WebKit. I looked on the WebKit site but could not find a list. I googled for a similar code but found none that dealt with WebKit and sound. No matter what args I try, the sound keeps playing. How can the sound be muted? Help, please.