google-chrome-extensionchrome-extension-manifest-v3

I am trying to access user microphone from offscreen - Chrome Extension Manifest V3


I was managed to get access to video stream & system audio using

await navigator.mediaDevices.getDisplayMedia({audio: true, video: true});

But I need also access to microphone. I tried to use

navigator.mediaDevices.getUserMedia({video: false, audio: true}) 

inside offscreen.

But I am getting Error: Not supported error

Possible solve (not wanted)

I could just open page using chrome.tabs.create or inject iframe, ask for permission. But it doesn't fill my needs, if user closes it I don't have access audio stream. I could create tab again and ask for permission again. But I think it should be possible in offscreen. What am I missing?


Solution

  • I found solution. You need at first ask for permission on options.html (or any extension page), After user accepts, you are able to use navigator.mediaDevices.getUserMedia() inside offscreen.html