Categories
JavaScript Answers

How to reprompt for permissions with getUserMedia() after initial denial with JavaScript?

Spread the love

Sometimes, we want to reprompt for permissions with getUserMedia() after initial denial with JavaScript.

In this article, we’ll look at how to reprompt for permissions with getUserMedia() after initial denial with JavaScript.

How to reprompt for permissions with getUserMedia() after initial denial with JavaScript?

To reprompt for permissions with getUserMedia() after initial denial with JavaScript, we can call the navigator.permissions.query method.

For instance, we write

const permissionObj = await navigator.permissions.query({ name: "microphone" });

to call navigator.permissions.query in an async function with an object with the name property set to a string with the permission that we want get.

The user will then be prompted with the permission prompt and permissionObj will have the user’s choice once the prompt is closed.

query returns a promise so we use await to get permissionObj.

Conclusion

To reprompt for permissions with getUserMedia() after initial denial with JavaScript, we can call the navigator.permissions.query method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *