Reputation: 369
How to re-ask for permission for a video camera or microphone in JavaScript after decline in JavaScript. For example if decline reask permission while user will not agree
Upvotes: 2
Views: 8945
Reputation: 136578
You can't "reask" when the user has denied access from it.
What you can do however is to monitor when they will change this setting, by listening to the PermissionStatus.onchange
event (that is in Chromium based browsers, Firefox still doesn't support the camera
value).
So you'd do:
// after you caught denial
const status = await navigator.permissions.query({name: "camera"});
status.addEventListener("change", (evt) => {
// request again
navigator.mediaDevices.getUserMedia({ video: true })
.then(handleStream)
.catch(handleDeny);
}, { once: true });
Upvotes: 0
Reputation: 17265
You can't (as this could lead to permission prompt spam).
The user will have to reset or change this in the browser settings. You'll need to guide them to that when getting a NotAllowedError from getUserMedia (it is a rather complex process) or you explain the process carefully in advance, avoiding the "deny" click most of the time.
Upvotes: 2