Javascript Chrome 更新 - 无法在“URL”上执行“createObjectURL”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53626318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:08:55  来源:igfitidea点击:

Chrome update-Failed to execute 'createObjectURL' on 'URL'

javascript

提问by Curly_Braces

I'm taking an image from the webcam and storing it to the server. Everything was working fine until I got the chrome update today. My latest chrome version is:

我正在从网络摄像头拍摄图像并将其存储到服务器。一切正常,直到我今天得到 chrome 更新。我最新的 chrome 版本是:

Version 71.0.3578.80 (64 bit)

版本 71.0.3578.80(64 位)

This line is throwing an error:

这一行抛出了一个错误:

camera.src = window.URL.createObjectURL(stream);  

Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.

无法在“URL”上执行“createObjectURL”:找不到与提供的签名匹配的函数。

According to this link here. I applied the code

根据这个链接在这里。我应用了代码

try {
  this.srcObject = stream;
} catch (error) {
  this.src = window.URL.createObjectURL(stream);
}

Its not displaying the camera feed.

它不显示相机提要。

For reference - This jsfiddlecode is not working on my chrome anymore.

供参考 - 此jsfiddle代码不再适用于我的 chrome。

回答by jtiscione

It's just been removed from the current version of Chrome. I suddenly started getting this error after it updated. I have no idea why it never printed deprecation warnings before today.

它刚刚从当前版本的 Chrome 中删除。更新后我突然开始收到此错误。我不知道为什么它在今天之前从未打印过弃用警告。

Instead of setting the srcproperty to URL.createObjectURL(stream)you're now supposed to set the srcObjectproperty to the stream directly. It seems to be working in Chrome and Firefox.

您现在应该直接将属性设置为流,而不是将src属性URL.createObjectURL(stream)设置为srcObject。它似乎适用于 Chrome 和 Firefox。

Source: https://developers.google.com/web/updates/2018/10/chrome-71-deps-rems

来源:https: //developers.google.com/web/updates/2018/10/chrome-71-deps-rems

回答by Devendra Rajput

Since google update version 71, this issue is generating. I also faced this issue. But now I got the solution to it. Here is the solution:

自 google 更新版本 71 以来,此问题正在生成。我也遇到过这个问题。但现在我得到了解决方案。这是解决方案:

Replace

代替

videoElement.src = URL.createObjectURL(screenStream);

to

videoElement.srcObject = screenStream;

回答by Fernando Rivero

In chrome, it works fine if you use:

在 chrome 中,如果您使用,它可以正常工作:

video.srcObject = stream;

Instead of:

代替:

this.srcObject = stream;

See printscreen here

在此处查看打印屏幕

回答by Emiliano Martín

Have you tried this?

你试过这个吗?

try {
  camera.srcObject = stream;
} catch (error) {
  camera.src = window.URL.createObjectURL(stream);
}