导航器 MediaDevices getUserMedia notAllowedError

navigator MediaDevices getUserMedia notAllowedError

我突然收到一个 navigator.MediaDevices.getUserMedia notAllowedError,我不是一个月前。没有代码改变。我正在使用火狐 68.01。当我在 AWS 上 运行 文件时出现问题,但在本地 运行 时不会出现问题。我刷新了 Firefox,但这没有帮助。以安全模式启动无效。就像我说的那样,这以前工作正常并且可以在本地工作,但不能在服务器上工作。我该如何解决这个问题?

"The request is not allowed by the user agent or the platform in the current context"

getUserMedia 现在即使在 Firefox 中也需要安全连接 (https)。

在 Firefox 68 中,这显示为 NotAllowedError,这是 Chrome 直到最近才使用的方式。

从 Firefox 69 开始,getUserMedia 方法将在不安全的连接 (http) 中完全消失,匹配 spec 以及 Chrome 今天的工作方式。

http://localhost 应该仍然有效,因为它现在被认为是安全的。

来自this Mozilla blog

Firefox 68 behavior

In Firefox 68, getUserMedia will still be there, but the promise returned from it will always be rejected with NotAllowedError, while enumerateDevices will continue to work until Firefox 69. This matches how Chrome has worked for a good while (pre Chrome 74), and should be highly web compatible. It is an intermediate stepping stone to Firefox 69.

Firefox 69 behavior

In Firefox 69, both getUserMedia and enumerateDevices will throw TypeError. This matches how Chrome 74+ and the the spec now work.

It is worth pointing out that this TypeError exception will come from the absence of the navigator.mediaDevices object in insecure contexts—or, if callbacks are used, the absence of the deprecated navigator.mozGetUserMedia function. Any JavaScript that doesn’t test for this before invoking navigator.mediaDevices.getUserMedia() will get an immediate exception thrown instead of merely having its promise rejected. Compared to Firefox 68, this might affect surrounding code, hence the two-step process.