如何在Chrome扩展程序弹出窗口中提供webkitGetUserMedia权限?

问题描述:

我已经成功使用webkitGetUserMedia从普通网页上的网络摄像头捕捉视频,但是当我尝试在我的Chrome扩展程序的popup.html中执行此操作时,没有任何反应。我没有收到任何权限错误,它似乎从来没有问过(inforbar从不在弹出窗口中滑落)。有没有办法解决?它看起来并不像我可以在清单json中给予权限。

I've successfully used webkitGetUserMedia to capture video from my webcam on a normal webpage, but when I try to do this in the popup.html of my Chrome Extension nothing happens. I don't get any permission errors, it just never even seems to ask (the inforbar never slides down in the popup window). Is there any way around this? It doesn't look like I can give permissions in the manifest json.

这是一个便宜的黑客攻击,但如果您创建选项页面,并在JS中包含对 webkitGetUserMedia 的调用,它将在用户在选项页面中允许之后请求该扩展的所有URI的权限后台页面也有权使用它。

It's a cheap hack, but if you create an options page for your extension and include a call to webkitGetUserMedia in the JS for it, it will request permission for all URIs for that extension, after the user allows it in the options page the background page will also have permission to use it.