cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.69k stars 3.16k forks source link

`--use-file-for-fake-audio-capture` doesn't work on Chrome #5592

Closed tomoyamachi closed 3 years ago

tomoyamachi commented 4 years ago

Current behavior:

I use --use-file-for-fake-audio-capture for testing getUserMedia behaviour on Chrome. https://github.com/cypress-io/cypress/issues/4160

But cypress v3.5.0 and v3.6.0, --use-file-for-fake-audio-capture doesn't work it.

Desired behavior:

--use-file-for-fake-audio-capture works on Chrome.

Steps to reproduce: (app code and test code)

// plugins/index.js
module.exports = (on, config) => {
    on('before:browser:launch', (browser = {}, args) => {
        if (browser.name === 'chrome') {
            args.push('--use-fake-device-for-media-stream')
            args.push('--use-fake-ui-for-media-stream')
            args.push('--use-file-for-fake-audio-capture=cypress/fixtures/sample.wav')
        }
        return args
    })
}

and args output

[ '--test-type',
  '--ignore-certificate-errors',
  '--start-maximized',
  '--silent-debugger-extension-api',
  '--no-default-browser-check',
  '--no-first-run',
  '--noerrdialogs',
  '--enable-fixed-layout',
  '--disable-popup-blocking',
  '--disable-password-generation',
  '--disable-save-password-bubble',
  '--disable-single-click-autofill',
  '--disable-prompt-on-repos',
  '--disable-background-timer-throttling',
  '--disable-renderer-backgrounding',
  '--disable-renderer-throttling',
  '--disable-restore-session-state',
  '--disable-translate',
  '--disable-new-profile-management',
  '--disable-new-avatar-menu',
  '--allow-insecure-localhost',
  '--reduce-security-for-testing',
  '--enable-automation',
  '--disable-device-discovery-notifications',
  '--disable-infobars',
  '--autoplay-policy=no-user-gesture-required',
  '--disable-site-isolation-trials',
  '--metrics-recording-only',
  '--disable-prompt-on-repost',
  '--disable-hang-monitor',
  '--disable-sync',
  '--disable-web-resources',
  '--safebrowsing-disable-auto-update',
  '--safebrowsing-disable-download-protection',
  '--disable-client-side-phishing-detection',
  '--disable-component-update',
  '--disable-default-apps',
  '--use-fake-ui-for-media-stream',
  '--use-fake-device-for-media-stream',
  '--disable-ipc-flooding-protection',
  '--disable-backgrounding-occluded-window',
  '--disable-breakpad',
  '--password-store=basic',
  '--use-mock-keychain',
  '--proxy-server=http://localhost:65342',
  '--proxy-bypass-list=<-loopback>',
  '--remote-debugging-port=65349',
  '--use-file-for-fake-audio-capture=cypress/fixtures/sample.wav' ]

I tried to absolute wav file path, but it doesn't work too.

Versions

Cypress v3.5.0, 3.6.0 OS : macOS 10.15 Chrome 78.0.3904.87, 79.0.3945.16

following version worked fine Cypress v3.4.1 OS : macOS 10.15 Chrome 78.0.3904.87

jennifer-shehane commented 4 years ago

I see the arg reading in the Chrome args output as the same path you specified: --use-file-for-fake-audio-capture=cypress/fixtures/sample.wav

Can you detail what the actual issue is? Is the audio file eventually not playing within the web application? What is the error point?

IhorPryyma commented 4 years ago

I'm facing the same issue with MAC Chrome. Did you find a solution?

AliakseiK commented 4 years ago

Issue reproduced for me as well. --use-file-for-fake-audio-capture doesn't work for 79 version of chrome on Mac OS. Sample audio isn't playing. I verified it on 76 version and works fine. Issue isn't related cypress, it is related to Chrome.

guest271314 commented 4 years ago

To output audio to speakers when using --use-fake-file-for-audio-capture flag try using AudioContext MediaStreamAudioSourceNode or HTML <audio> element

navigator.mediaDevices.getUserMedia({audio: true})
.then(stream => {
  const audio = new Audio();
  audio.autoplay = true;
  audio.srcObject = stream;
});
navigator.mediaDevices.getUserMedia({audio: true})
.then(mediaStream => {
  const ac = new AudioContext();
  const source = ac.createMediaStreamSource(mediaStream);
  source.connect(ac.destination);
});

Command line

chromium-browser --allow-file-access-from-files --autoplay-policy=no-user-gesture-required --use-fake-device-for-media-stream --use-fake-ui-for-media-stream --use-file-for-fake-audio-capture=$HOME/test.wav%noloop --user-data-dir=$HOME/test 'file:///home/user/testUseFileForFakeAudioCaptureChromium.html'

Tested at Chromium 80.0.3987.7 (32-bit) *nix (both file: protocol and launching Chromium point to "https://github.com" and running the code at console).

To test download attached .txt file, save as .html, adjust paths at above command.

testUseFileForFakeAudioCaptureChromium.txt

tomoyamachi commented 4 years ago

Sorry for the late reply. It looks fail to play audio. But there is no error logs.

BTW, I ran @guest271314's scripts on Mac, and I got error message. I put test.wav to a target path, but fail to read it.

$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version

Google Chrome 79.0.3945.88

$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --allow-file-access-from-files \
  --autoplay-policy=no-user-gesture-required \
  --use-fake-device-for-media-stream \
  --use-fake-ui-for-media-stream \
  --use-file-for-fake-audio-capture=$HOME/test/test.wav \
  --user-data-dir=$HOME/test/data \
  file://$HOME/test/testUseFileForFakeAudioCaptureChromium.html

[39131:86787:0104/000139.036863:ERROR:simple_sources.cc(30)] Failed to read /Users/xxxx/test/test.wav as input to the fake device.
guest271314 commented 4 years ago

Can you upload the wav file that you are testing here or print the output of mediainfo test.wav or mkvmerge -J test.wav? The path to the file or URL to load should be a string.

davidhennemann commented 4 years ago

I think its an issue with chromium and not cypress. I created a bug report in their issue tracker.

https://bugs.chromium.org/p/chromium/issues/detail?id=1032604

jennifer-shehane commented 3 years ago

Since this issue hasn't had activity in a while, we'll close the issue until we can confirm this is still happening. Please comment if there is new information to provide concerning the original issue and we'd be happy to reopen.

andreieftimie commented 3 years ago

Did anyone manage to get this working (found some workaround)?

loszer commented 3 years ago

according to https://bugs.chromium.org/p/chromium/issues/detail?id=1032604#c37 plugin/index.js add chrome args "--no-sandbox" demo code:

on('before:browser:launch', (browser = {}, launchOptions = { args: [] }) => {
    if (browser.name === 'chrome') {
      // https://bugs.chromium.org/p/chromium/issues/detail?id=1032604#c37
      launchOptions.args.push('--no-sandbox')
      launchOptions.args.push('--allow-file-access-from-files')
      launchOptions.args.push('--use-fake-ui-for-media-stream')
      launchOptions.args.push('--use-fake-device-for-media-stream')
      // mp3 not work
      launchOptions.args.push('--use-file-for-fake-audio-capture=tests/fixtures/hello.wav')
    }
    return launchOptions
  })
mattrussell-sonocent commented 3 years ago

@loszer Adding --no-sandbox worked a treat for us, thanks for sharing the workaround.