Test a website that requires microphone access with playwright
Pop-up in question comes up and seems to ignore supposedly granted permissions. Permission can be given manually, but this seems against the spirit of automation.
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context(permissions=['microphone'])
...
Granting permissions via context doesn't work for some reason. The permission pop-up still comes up.
I also tried to record a walkthrough with playwrights record script, but it's not recording granting microphone permissions.
You're missing some command line flags that tell chrome to simulate having a microphone. Give this sample a shot.
from playwright.sync_api import sync_playwright
def run(playwright):
chromium = playwright.chromium
browser = chromium.launch(headless=False, args=['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream'])
context = browser.new_context()
context.grant_permissions(permissions=['microphone'])
page = context.new_page()
page.goto("https://permission.site/")
page.click('#microphone')
page.pause()
# other actions...
browser.close()
with sync_playwright() as playwright:
run(playwright)