How to enable camera and microphone in packaged application for Chrome OS or Chrome extension?

≡放荡痞女 提交于 2019-12-05 20:05:41

If you need to provide audio/video for a <webview>-embedded page, requiring "audioCapture"/"videoCapture" permissions is not enough.

To use those, the page requests permission to the browser. In normal Chrome you'll see an infobar allowing the user to allow/deny the request.

<webview> does not show those elements, instead it raises an event and it's up to the app to allow/deny it:

permissionrequest

Fired when the guest page needs to request special permission from the embedder.

The following example code will grant the guest page access to the webkitGetUserMedia API. Note that an app using this example code must itself specify audioCapture and/or videoCapture manifest permissions:

webview.addEventListener('permissionrequest', function(e) {
  if (e.permission === 'media') {
    e.request.allow();
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!