我已经使用 react-webcam 响应 JS 扩展来访问相机并制作屏幕截图。在普通的 webapp 中它可以正常工作,但在 chrome 扩展中,尝试通过以下方式访问相机:
navigator.mediaDevices.getUserMedia({video: true})
.then(function(stream) {
console.log(stream)
})
.catch(function(err) {
console.log(err)
});
我得到 DOMException: Invalid security origin in console。任何想法如何解决这一问题?
编辑:权限 - 我的 manifest.json
{
"manifest_version": 2,
"name": "__MSG_peeps_name__ DEV",
"description": "__MSG_peeps_description__",
"version": "4.0.0",
"content_security_policy": "script-src 'self' 'unsafe-eval' https://ssl.google-analytics.com https://apis.google.com https://www.google-analytics.com; object-src 'self'",
"default_locale": "en",
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "/icons/icon_48.png",
"default_popup": "index.html"
},
"icons": {
"16": "/icons/icon_16.png",
"32": "/icons/icon_32.png",
"48": "/icons/icon_48.png",
"64": "/icons/icon_64.png",
"128": "/icons/icon_128.png"
},
"web_accessible_resources": [
"app/*",
"/images/*",
"favicon.ico"
],
"sandbox": {
"pages": ["page.html"]
},
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Alt+P"
}
}
},
"permissions": [
"activeTabs",
"tabs",
"storage",
"identity",
"videoCapture",
"identity.email",
"chrome-extension://*"
],
"oauth2": {
"client_id": "12345.apps.googleusercontent.com",
"scopes": [
"email",
"profile",
"https://www.googleapis.com/auth/contacts.readonly"
]
},
"key":"12345
}