Today I learned about a new browser api called Permissions API. It's a new API that allow you to check the current state of different API permissions such as Geolocation.
It can look like this:
navigator.permissions.query({name:'geolocation'}).then(function(result) {
console.log('The current state of geolocation permissions are:', result.state);
// result.state can be "granted", "prompt" or "denied".
});
Use cases?
I came across it when looking for a way to check the status of geolocation before prompting the user to allow it. If you know the user has approved it you can show a map or load some locations when the page loads without bothering the user.
It's a experimental API so it's not the safest to use in production. It's supported in most major browsers execpt Safari, and you can read more about it here.