Unable to Suppress Camera Permission Popup in Headless Mode on Selenium Grid

65 views
Skip to first unread message

Ramapriya Prasathe

unread,
Aug 6, 2025, 6:29:26 AMAug 6
to Selenium Users

Hi all,

I’m currently facing an issue running our Selenium tests on Chrome in headless mode via Selenium Grid.

🔧 Scenario:
  • The test navigates to our web app (Client Portal) where a “Record Video” button appears.

  • On clicking the button, the app requests camera and microphone permissions.

  • We're not uploading any files, just need to simulate camera access for recording.

  • Tests are executed using the --headless=new Chrome mode on the Grid.

  • We’ve already added the following ChromeOptions:

options.addArguments("--use-fake-ui-for-media-stream");
options.addArguments("--use-fake-device-for-media-stream");
options.addArguments("--headless=new");

❌ Problem:

Even after adding these arguments, the browser permission popup still appears during test execution, causing the test to hang or fail.

✅ Expected:

With the above flags, the browser should automatically allow camera/mic access and suppress the permission popup.

🧪 Setup:
  • Selenium Grid with Chrome (headless)

  • Java + TestNG

  • RemoteWebDriver is used to pass ChromeOptions


🙏 Request:

Has anyone successfully run WebRTC camera access tests in headless mode using Selenium Grid?

  • Any ideas why the permission popup still appears?

  • Do we need to simulate a media stream with a fake file?

  • Could this be due to a mismatch in Chrome version, or the Grid node not accepting the flags?

Any guidance would be appreciated!

Thanks,
Ramapriya

Screenshot 2025-08-06 at 3.20.39 PM.png

Saikat Das

unread,
Aug 6, 2025, 9:55:43 AMAug 6
to seleniu...@googlegroups.com
Hello Ramapriya,
What I understand is that you are trying to block the pop-up coming from the Chrome browser.
Below, I found one possible way that is 
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches",
     Arrays.asList("disable-popup-blocking"));
Please check this URL "https://developer.chrome.com/docs/chromedriver/capabilities". Please let us know if it is working or not
Thank you

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/selenium-users/7cb65624-f1ad-4bde-8555-67a574e7107bn%40googlegroups.com.


--
Best regards,

Saikat Das
Quality Analyst - II | Risk Success Private Limited

Saikat Das

unread,
Aug 6, 2025, 10:03:49 AMAug 6
to seleniu...@googlegroups.com

Remove the excludeSwitches line entirely. The disable-popup-blocking argument should remain enabled (not excluded) to ensure permission dialogues are handled properly in headless mode.

This configuration will automatically grant camera and microphone permissions without showing any pop-up dialogues in your Selenium Grid tests.

Ramapriya Prasathe

unread,
Aug 7, 2025, 5:11:25 AMAug 7
to seleniu...@googlegroups.com
Hi Saikat,
Thanks for your response.
Unfortunately, It has no impact on media access prompts or Chrome’s behavior regarding hardware permissions. Here our goal to do allow permissions and not on blocking the pop ups

Please let me know if you have any approach for this issue

Thanks,
Ramapriya.

Lajish Lakshmanan

unread,
Aug 19, 2025, 2:41:55 AMAug 19
to Selenium Users
Hi @ramapriya,

In headless mode, Chrome and Firefox handle WebRTC permissions differently. By default, real camera/mic won’t work in headless mode (since no GUI is present). The usual approach is to use fake device streams.

public static void main(String[] args) {
        // Setup Chrome preferences
        Map<String, Object> prefs = new HashMap<>();
        Map<String, Object> profile = new HashMap<>();
        Map<String, Object> contentSettings = new HashMap<>();

        contentSettings.put("media_stream_camera", 1);
        contentSettings.put("media_stream_mic", 1);

        profile.put("managed_default_content_settings", contentSettings);
        prefs.put("profile", profile);


        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", prefs);

        // Headless mode
        options.addArguments("--headless=new");   // use new headless (Chrome 109+)
        options.addArguments("--use-fake-ui-for-media-stream");    // skip permission popup
        options.addArguments("--use-fake-device-for-media-stream"); // fake cam/mic
        options.addArguments("--allow-file-access-from-files");
        options.addArguments("--use-file-for-fake-video-capture=/path/to/test.y4m"); // optional custom video if you need
        options.addArguments("--use-file-for-fake-audio-capture=/path/to/test.wav"); // optional custom audio if you need

        WebDriver driver = new ChromeDriver(options);
        driver.get("https://your-webrtc-app-url.com");
    }

Try above code for your AUT and let us know.


Thanks,
Lajish Lakshmanan
Reply all
Reply to author
Forward
0 new messages