The microphone permission is attached to an origin, for an extension that would be chrome-extension://YOUR_EXTENSION_ID. The issue you are hitting is requesting microphone access in environments that do not have the UX affordance to request it. As a result, the request fails and you get the permission denied error as though the user declined the request. The workaround I would normally suggest is to programatically open a chrome extension page as a full tab to request the permission. Once it is granted, the sidepanel can access it. So within your sidepanel.html, have something like
```js
function async getMic() {
const micPermission = await navigator.permissions.query({name: "microphone"});
if (micPermission.state !== "granted") {
chrome.tabs.create({url: "request-mic.html"}, (tab) => {
chrome.tabs.onRemoved.addListener(function listener(tabId) {
if (tabId ===
tab.id) {
chrome.tabs.onRemoved.removeListener(listener); // Remove listener after execution
getMic();
}
});
})
} else {
const mic = navigator.mediaDevices.getUserMedia({audio: true})
}
}
```
Where you create a `request-mic.html` page in your extension that just calls
```js
navigator.permissions.request({ name: "microphone" })
```