trezy / next-safe

https://trezy.gitbook.io/next-safe/
BSD 3-Clause "New" or "Revised" License
174 stars 20 forks source link

[BUG]: microphone is not allowed in this document #44

Closed heymartinadams closed 2 years ago

heymartinadams commented 2 years ago

Describe the bug

Despite having explicitly allowed localhost:3000 access to the microphone in chrome://settings/content/microphone (see screenshot below), and despite having enabled the microphone in next-safe, I was unable to use it.

headers: nextSafe({
  ...,
  permissionsPolicy: {
    microphone: 'true'
  }
})

Initially filed a report here https://github.com/alan-ai/alan-sdk-web/issues/55 but then closed it once I realized it had to do with next-safe. I was able to use the microphone once I disabled next-safe altogether.

Screenshot: microphone specifically allowed for localhost:3000

image

Steps To Reproduce

No response

Version

v3.x.x

Relevant log output

[Violation] Permissions policy violation: microphone is not allowed in this document.
openMicrophone @ alan_lib.js?40cc:544
ns.start @ alan_lib.js?40cc:725
_activateAlanButton @ alan_lib.js?40cc:2007
eval @ alan_lib.js?40cc:2032
activateAlanButton @ alan_lib.js?40cc:2013
eval @ alan_lib.js?40cc:2246
alan_lib.js?40cc:2802

Microphone access is blocked in your browser settings. Enable it to allow the voice assistant using your microphone
switchState @ alan_lib.js?40cc:2802
onMicFail @ alan_lib.js?40cc:2457
fireEvent @ alan_lib.js?40cc:619
eval @ alan_lib.js?40cc:731
Promise.catch (async)
ns.start @ alan_lib.js?40cc:731
_activateAlanButton @ alan_lib.js?40cc:2007
eval @ alan_lib.js?40cc:2032
activateAlanButton @ alan_lib.js?40cc:2013
eval @ alan_lib.js?40cc:2246

Code of Conduct

heymartinadams commented 2 years ago

I just realized the permissions need to be set as follows:

headers: nextSafe({
  ...,
  permissionsPolicy: {
    microphone: 'self'
  }
})

Wasn’t clear entirely clear to me from this page: https://trezy.gitbook.io/next-safe/configuration-options/permissionspolicy, but glad I figured it out once I looked it up on Mozilla ☺️