-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
getUserMedia with microphone fails #4160
Comments
You can follow the same basic procedure as @jennifer-shehane's comment on the webcam issue (#2704), but instead of using In module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, args) => {
// args.push('--use-fake-device-for-media-stream')
if (browser.name === 'chrome') {
args.push('--use-fake-ui-for-media-stream')
args.push('--use-fake-device-for-media-stream')
args.push('--use-file-for-fake-audio-capture=cypress/fixtures/your_sound.wav')
}
return args
})
} |
Thanks, playing with that now. |
@jaypan Great, please let us know how it works as we haven't manually tested this. I'd love to add a working example to our docs. |
Sorry it's taken me a while to get back to this. Unfortunately, it's not working for me. I've added this to cypress/plugins/index.js: module.exports = function (on, config) {
"use strict";
on('before:browser:launch', function (browser = {}, args) {
if (browser.name === 'chrome') {
args.push('--use-fake-ui-for-media-stream');
args.push('--use-fake-device-for-media-stream');
args.push('--use-file-for-fake-audio-capture=cypress/fixtures/audio/test.mp');
}
return args;
});
}; I'm still getting the same error:
Logging the args being sent to the browser, I see this:
Note that the file cypress/fixtures/audio/test.mp3 does exist. I've also tried the paths:
As well as all combinations with a leading slash. I've shut down the test runner (the browser GUI) in between each change to make sure that the args are picked up during browser launch, and can confirm that they are, but that the error still occurs. |
Have you tried using a
|
I was just digging through the docs and found that myself. I tried a .wav file, but it also results in the same error. I also tried removing the line to
|
Hmm, that's strange. I'm using Cypress 3.3.0 with Chromium 73 on Linux and it works fine for me, even without <!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
var constraints = {
audio: true,
video: false
};
navigator.mediaDevices.getUserMedia(constraints)
.then(stream => {
console.log(stream)
})
};
</script>
</head>
<body>
<p>Hello World</p>
</body>
</html> What version of Chrome are you using? |
Well, as soon as I use Chrome 74, I get the same error.... maybe some behavior changed between 73 and 74 w.r.t. how these command line args are handled. |
Oh, well that's a pain. Thanks for your help, much appreciated. |
Guys, I've just realized I was overlooking the problem altogether. I've been developing in Firefox - where my code works fine. Cypress of course runs in Chrome, not Firefox. I finally took the time to look open it in Chrome - and sure enough it wasn't working in the browser, hence it was a problem with my application, and not in Cypress. I think the biggest indicator of this was probably Cypress telling me from the start that it was a problem in my application and not in Cypress :) The actual problem is that Chrome blocks So I can comfortably say that this works (but the underlying application must be in HTTPS to work in Chrome): module.exports = function (on, config) {
"use strict";
on('before:browser:launch', function (browser = {}, args) {
if (browser.name === 'chrome') {
args.push('--use-fake-ui-for-media-stream');
args.push('--use-fake-device-for-media-stream');
args.push('--use-file-for-fake-audio-capture=cypress/fixtures/test.mp3');
}
return args;
});
}; I'll note that as can be seen from the code above, the code works with an |
@jaypan Great to hear you were able to get it to work! |
this error is due to chrome and other browsers block microphone access to not https sites |
Bug
Requests to access the user's microphone using
getUserMedia()
fail and crash Cypress test.Current behavior:
I have a web application which allows users to do voice recordings in their browser. Getting access to the microphone is done through the following
Cypress fails this test due to the call
.getUserMedia()
with the error:I have seen that some work has been done with webcams, but I'm not finding anything for microphones.
Desired behavior:
I would like this to not fail, so that I can test the application.
Steps to reproduce:
index.html:
Test:
Versions
macOS Mojave
Cypress 3.2.0
The text was updated successfully, but these errors were encountered: