Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support fake camera and microphone permissions #2525

Closed
grajesh690 opened this issue Jun 10, 2020 · 11 comments
Closed

[Feature] Support fake camera and microphone permissions #2525

grajesh690 opened this issue Jun 10, 2020 · 11 comments

Comments

@grajesh690
Copy link

const playwright = require("playwright");

const iPhone11 = playwright.devices["iPhone 11 Pro"];

(async () => {
// Try to add 'firefox' to the list ↓
const browser = await playwright.firefox.launch();
const context = await browser.newContext({
geolocation: { longitude: 52.520008, latitude: 13.404954 },
permissions: ["camera","microphone"],
});
const page = await context.newPage();
await page.goto('http://whatsmyuseragent.org/');
await page.screenshot({ path: example.png });
await browser.close();
})();

@grajesh690
Copy link
Author

I unable to grant permission for camera and microphone across the browsers

@pavelfeldman
Copy link
Member

Those permissions are not supported yet. What is your scenario?

@grajesh690
Copy link
Author

Those permissions are not supported yet. What is your scenario?

I need to grant permission by default for microphone and audio !

@pavelfeldman
Copy link
Member

pavelfeldman commented Jun 28, 2020

But do I understand it right that your scenario is not test-related? Why do you need that permission? Do you intend to record mic after that?

@magnuskenneth
Copy link

magnuskenneth commented Jun 30, 2020

Those permissions are not supported yet. What is your scenario?

I have the same issue, trying to set microphone permissions to be able to test my app in a state where it needs to be set. I don't need to record any audio in the test.

Do you have an estimate of when this might be supported?

@magnuskenneth
Copy link

magnuskenneth commented Jul 1, 2020

I just found a way to get it to work for me with chromium:

const browser = await chromium.launch({
    args: ['--use-fake-ui-for-media-stream']
});

const context = await browser.newContext({
    permissions: ['microphone']
});

@OlgaKuksa
Copy link

OlgaKuksa commented Jul 14, 2020

+1 for microphone/camera permissions support. Need to test videochat (at least starting videochat). Maybe some mocked ones?
For now I can set camera permission to Chromium, but not to Webkit in e.g. iPhone 11. Cross-browser support would be nice!
Actually, it would be nice to pass to Webkit same args as for Chrome in WebRTC testing guide: https://webrtc.org/getting-started/testing

@dgozman dgozman changed the title [BUG] Unknown permission camera for all the browsers [Feature] Support fake camera and microphone permissions Nov 24, 2020
@d4niloArantes
Copy link

Context:

  • Playwright Version: v1.10.0
  • Operating System: Linux Ubuntu 20.04.1
  • Node.js version: v10.19.0
  • Browser: WebKit

I'm testing a Videochat App and I was looking for how to pass arguments to Webkit but I can't find any information in the docs. I was able to do in Chrome and Firefox:

browser = await {chromium, webkit, firefox}[browserName].launch({
   args: ['--use-fake-ui-for-media-stream','--use-fake-device-for-media-stream'], // for chromium
   firefoxUserPrefs: {"media.navigator.streams.fake": true, "media.navigator.permission.disabled": true} // for firefox
});

When I run the code block above it runs perfectly in Chrome and Firefox but when it's time for WebKit I got this (I guess expected) error:

browserType.launch: Protocol error (Playwright.enable): Browser closed.
    ==================== Browser output: ====================
    <launching> /home/birl/.cache/ms-playwright/webkit-1446/pw_run.sh --inspector-pipe --no-startup-window --use-fake-ui-for-media-stream --use-fake-device-for-media-stream
    <launched> pid=67053
    [pid=67053][err] Cannot parse arguments: Unknown option --use-fake-ui-for-media-stream

If I get rid of this line args: ['--use-fake-ui-for-media-stream','--use-fake-device-for-media-stream'], // for chromium, WebKit pops up but it's no use for what I need to do. Is there a way to make it work for WebKit?

@pavelfeldman
Copy link
Member

I'll close this as a part of the bug triaging process. We have hundreds of bugs and feature requests with dozens and even hundreds of upvotes, while this one only has a few thumbs up. Please feel free to open a new bug and link this one if you'd like to see it addressed.

@pitops
Copy link

pitops commented Feb 10, 2022

the following works for loading permissions for microphone

const context = await browserTypes[browserName].launchPersistentContext(
      '',
      {
        headless: false,
        args: [
          `--disable-extensions-except=${extensionPath}`,
          `--load-extension=${extensionPath}`,
          '--use-fake-device-for-media-stream',
          '--no-sandbox'
        ],
        viewport: {
          width: 1920,
          height: 1080
        },
        permissions: ['microphone']
        // Uncomment to turn on "slow mode", useful in debugging
        // slowMo: 1000
      }
    )

@sogekng
Copy link

sogekng commented Nov 8, 2022

I'm lost, I would like to know if I could use permissions=['camera'], if I could choose an output device in the code, preferably for mac, then I could use OBS instead of the default camera

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants