playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Add support for better testing WebRTC applications with Webkit

Open OlgaKuksa opened this issue 5 years ago • 34 comments

According to WebRTC testing guide, there is a list of parameters which are recommended to be passed to Chrome or Firefox for testing WebRTC applications. But there is nothing for Safari (Webkit). Is there a way to make Playwright Webkit engine support flags like Chromium does? That would be nice for testing apps which use WebRTC. IMHO - same Playwright API across all the browser engines would be great!

UPD: There's an article A Closer Look Into WebRTC. It states that AV capture devices in Webkit can be mocked and camera and microphone policy can be set to allowed state to avoid prompts from getUserMedia.

OlgaKuksa avatar Jul 16 '20 14:07 OlgaKuksa

Any progress on this? Webkit WebRTC testing would be a huge boon for a major project I'm working on.

R-Bower avatar Mar 06 '21 21:03 R-Bower

I was looking into this too (made a discussion/q&a about it here: https://github.com/microsoft/playwright/discussions/6166).

Just to repeat what I found: on a mac target, you can configure the system prefs (defaults) in a similar manner to chrome. But I have not figured out how to do it on linux webkit yet.

Additionally, attempting to grant camera permissions on webkit currently causes playwright to throw, at least in linux.

I know none of this info is a "solve" but just wanted to share what I'd learned in case it helps someone else.

kirbysayshi avatar Apr 09 '21 21:04 kirbysayshi

I think I found here what I have asked in the 2525

d4niloArantes avatar Apr 26 '21 21:04 d4niloArantes

did you find anything? we have a large suit of test for our video application --- which is working perfect on chrome with --fake-camera flag. We love to run it on safari, but still struggling.

innoist avatar May 01 '21 07:05 innoist

@kirbysayshi i confirm that it adding permission: ['camera'], also throw on mac os 10.15.7 with playwright 1.10.0

Xotabu4 avatar May 05 '21 12:05 Xotabu4

The not-headless webkit version works setting --enable-mock-capture-devices=true option. For the --headless version (using wpe), we need to enable "enable-mock-capture-devices" in the wpe build: https://wpewebkit.org/reference/wpewebkit/2.23.90/WebKitSettings.html#webkit-settings-set-enable-mock-capture-devices

vpalmisano avatar Aug 04 '21 08:08 vpalmisano

I've prepared a patch for adding a "enable-mock-capture-devices" command line option to the wpe executable. I'm no able to update the browser_patches/webkit/patches/bootstrap.diff, I've tried ./browser_patches/export.sh webkit but the script stops at this command git merge-base $REMOTE_BROWSER_UPSTREAM/$BASE_BRANCH $CURRENT_BRANCH.

The patch:

diff --git a/Tools/MiniBrowser/wpe/main.cpp b/Tools/MiniBrowser/wpe/main.cpp
index ff87f17bd3dc..cf6650a4fda1 100644
--- a/Tools/MiniBrowser/wpe/main.cpp
+++ b/Tools/MiniBrowser/wpe/main.cpp
@@ -42,9 +42,6 @@ static gboolean automationMode;
 static gboolean ignoreTLSErrors;
 static gboolean inspectorPipe;
 static gboolean noStartupWindow;
-// Playwright begin
-static gboolean enableMockCaptureDevices;
-// Playwright end
 static const char* userDataDir;
 static const char* contentFilter;
 static const char* cookiesFile;
@@ -72,9 +69,6 @@ static const GOptionEntry commandLineOptions[] =
     { "inspector-pipe", 'v', 0, G_OPTION_ARG_NONE, &inspectorPipe, "Expose remote debugging protocol over pipe", nullptr },
     { "user-data-dir", 0, 0, G_OPTION_ARG_STRING, &userDataDir, "Default profile persistence folder location", "FILE" },
     { "no-startup-window", 0, 0, G_OPTION_ARG_NONE, &noStartupWindow, "Do not open default page", nullptr },
-// Playwright begin
-    { "enable-mock-capture-devices", 0, 0, G_OPTION_ARG_NONE, &enableMockCaptureDevices, "Enable mock capture devices", nullptr },
-// Playwright end
     { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uriArguments, nullptr, "[URL]" },
     { nullptr, 0, 0, G_OPTION_ARG_NONE, nullptr, nullptr, nullptr }
 };
@@ -395,9 +389,6 @@ int main(int argc, char *argv[])
                 return static_cast<WPEToolingBackends::HeadlessViewBackend*>(data)->snapshot();
             });
     }
-    if (enableMockCaptureDevices) {
-        webkit_settings_set_enable_mock_capture_devices(settings, TRUE);
-    }
 // Playwright end
     auto* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
         "backend", viewBackend,

vpalmisano avatar Aug 04 '21 13:08 vpalmisano

I have recently tried this in webkit headless as well as headed mode . it always shows pop-up message for camera permission (ie. doesn't suppress permission) even with launch option argument provided. Not sure if I am using correct launch options. Here is the snippet of my config and test

`import { PlaywrightTestConfig } from "@playwright/test";

const config: PlaywrightTestConfig = {

use: {
    headless: true,
    screenshot: "on",
    trace: "retain-on-failure",
    baseURL: "https://uat.groww.in",        
    acceptDownloads : true,       
},
projects:[
    {
        name:"chrome",
        use:{
            browserName:"chromium",
            permissions:["camera"],
            launchOptions:{
                args:[
                    "--no-sandbox",
                    "--disable-setuid-sandbox",
                    "--use-fake-device-for-media-stream",
                    "--use-fake-ui-for-media-stream",
                    "--use-file-for-fake-video-capture=./data/fakeCameraCapureDP.y4m"
                ]
            }
        }
    },
    {
        name:"firefox",
        use:{
            browserName:"firefox",
            launchOptions:{
                args:[
                    "--quiet",
                    "--use-test-media-devices" 
                ],
                firefoxUserPrefs: { "media.navigator.streams.fake": true, "media.navigator.permission.disabled": true }
            }               
        },
    },
    {
        name:"safari",
        use:{
            browserName:"webkit",
            launchOptions:{
                args:[
                    "--enable-mock-capture-devices=true",
                    "--enable-media-stream=true"
                ]
            }
        }
    }
],
retries: 0,
timeout: 1000000,
reporter: [
    ['line'], 
    ["json", { outputFile: "test-result.json" }],
    ['experimental-allure-playwright']
],
// testDir : 'fixtures',
testDir : 'test',

} export default config;`

test `import test, { expect } from "../fixtures/basePages"

let cam_launcher = "//*[text()='Test my cam']"; let stop_webcam = "//button[text()='Stop webcam']"

test.describe('dummy camera test',async()=>{ test('webcam test',async({page,context,browser})=>{ await page.goto('https://webcamtests.com/'); await page.locator(cam_launcher).click(); await page.locator(stop_webcam).waitFor(); await page.locator(stop_webcam).click() }) })`

note : I created this only to test fake camera.

terminal command: npx playwright test dummy.test --headed --project=safari attached trace.zip trace.zip

test-failed-1

When can we expect this working ?

Palak-Jethwani avatar Nov 17 '21 14:11 Palak-Jethwani

Just add permissions: ['microphone', 'camera'] You will be able to run it locally after this in Headless mode too

But I am not able to run it on Git Actions Even after adding

permissions: ['microphone', 'camera'],
use: {
        channel: 'chrome',
        launchOptions:{
          args:[
              "--use-fake-device-for-media-stream",
              "--use-fake-ui-for-media-stream",
          ]
      }
      }

I am getting error

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Exit status 1
npm ERR! 
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Error: Process completed with exit code 1.

ronit100ms avatar Apr 08 '22 22:04 ronit100ms

Its been 2year since the feature request was opened and i can see no progress was made by the Playwright team.

nirazv avatar Aug 19 '22 18:08 nirazv

Upvoting this 👍🏻 would be great to have webrtc testing support in Firefox and Webkit.

cscheffauer avatar Sep 15 '22 08:09 cscheffauer

Upvoting this - my team uses Playwright to test our WebRTC application, and it would help to expand test coverage across multiple browsers.

nickpell avatar Oct 28 '22 22:10 nickpell

up!

Sxoo avatar Nov 09 '22 10:11 Sxoo

Up!!

ivanrosvimi avatar Nov 21 '22 11:11 ivanrosvimi

up!

AurimasG12 avatar Dec 01 '22 09:12 AurimasG12

bump

mikallojjus avatar Dec 01 '22 09:12 mikallojjus

Up.

svajunas-budrys avatar Dec 01 '22 09:12 svajunas-budrys

up

Vinyzu avatar Dec 15 '22 19:12 Vinyzu

up

domme1908 avatar Dec 19 '22 10:12 domme1908

Up!

ghost avatar Jan 23 '23 14:01 ghost

up

skyuplam avatar Feb 28 '23 04:02 skyuplam

up!

maalfrid avatar Feb 28 '23 09:02 maalfrid

Having webcam and microphone permissions for webkit would allow us to test video calls on it.

Xotabu4 avatar Mar 06 '23 15:03 Xotabu4

Getting error:

Can't find variable: RTCRtpSender
ReferenceError: Can't find variable: RTCRtpSender

For webkit browser running in docker container - mcr.microsoft.com/playwright:latest

For webkit on macos - works fine.

Xotabu4 avatar Mar 10 '23 10:03 Xotabu4

are there any recommended workarounds for this? it's pretty mission-critical for our usage of playwright

it works fine it chromium, just not webkit or firefox

aroman avatar Aug 10 '23 22:08 aroman

Did an experiment today, mocking getUserMedia and it works

https://gist.github.com/KernelFolla/2647d7c644dce10913c592b1708f3a1e

I guess it's possible to mock browser's API for testing anyway

KernelFolla avatar Oct 04 '23 17:10 KernelFolla

Any solution for webkit yet?

BreamIsAFish avatar Nov 05 '23 17:11 BreamIsAFish

Are there any updates on this, I am trying to implement video call tests for our product however I can not simulate webcams for both chrome and safari. @pavelfeldman @kirbysayshi

acanyasar avatar Nov 14 '23 14:11 acanyasar

+1. Support for audio would be appreciated for speech testing.

siddharth2023 avatar Feb 27 '24 20:02 siddharth2023

Any updates? this issue is open since nearly 4 years now - would be great to get support! 💯

cscheffauer avatar Mar 22 '24 11:03 cscheffauer