简体   繁体   中英

Chrome extension microphone capture

I have a browser_action extension where the user can press start and stop in order to capture some audio input. After the file has been recorded I would like to dump its url in the console. The problem is that I cannot get access to the microphone. This is what I have tried so far:

navigator.webkitGetUserMedia - does not work, navigator.webkitGetUserMedia({ audio: true },...); calls the error callback with a MediaDeviceFailedDueToShutdown. I tried looking into that error but I found nothing useful about that. That error is nowhere to be found.

Could you please guide me to the right path? Thank you.

So it turns out that I have to get the user media from within an html page that is baked into the extension itself. After the user has given access to the microphone, the background script of the extension also gets access to it.

In my case, after installing I launch the welcome.html page where access is being requested:

background.js

chrome.runtime.onInstalled.addListener((details) => {
    if (details.reason.search(/install/g) === -1) {
        return
    }
    chrome.tabs.create({
        url: chrome.extension.getURL("welcome.html"),
        active: true
    })
})

welcome.js

navigator.webkitGetUserMedia({ audio: true }, s => {...}, err => {...}

尝试将“ audioCapture”添加到manifest.json中的权限中:

"permissions": ["fullscreen", "audioCapture"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM