question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

[FEATURE] geolocation permission

See original GitHub issue

šŸš€ Feature request

Is your feature request related to a problem?

Having GEOLOCATION_SUPPORT injection token does not quite answer the question of whether the developer can use the geolocation Web API. The GEOLOCATION_SUPPORT simply checks if navigator.geolocation object is available. However, the user may have received the browser popup during one of the previous visits to the website and automatically clicked ā€œBlockā€ (like many of us do these days whenever any popup shows up). In this case, the GEOLOCATION_SUPPORT will resolve to true, but geolocation$ observable will emit an error.

Describe the solution youā€™d like

To answer the question of whether the user has allowed the website access to geolocation, we can run the following code:

navigator.permissions.query({ name: 'geolocation' }).then((x) => console.log(x.state))
// this will print "prompt", "denied", or "granted"

I wonder if an injection token GEOLOCATION_PERMISSION could be introduced that would run the code above under the hood? Given the fact that this API returns a Promise, Iā€™m not sure if it can still be an Injection token or if itā€™ll have to be an observable service similar to the geolocation$

[Important] Something to keep in mind: the support for the API above is somewhat spotty: https://caniuse.com/permissions-api

Describe alternatives youā€™ve considered

Here people suggest using the second callback for the navigator.geolocation.watchPosition method thatā€™s called upon an error. This does not really solve the issue for me because calling this function will trigger the popup and I would like to know whether the geolocation Web API is available before the popup shows up.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
IKatsubacommented, Nov 27, 2020

I think we have to move up to Angular 9. Tomorrow Angular 8 LTS will end https://angular.io/guide/releases#support-policy-and-schedule

0reactions
DmitryEfimenkocommented, Dec 20, 2020

Created a PR for this: https://github.com/ng-web-apis/permissions/pull/1 Iā€™m closing this issue. Letā€™s move our conversation into the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Permissions API - MDN Web Docs
It uses Geolocation to query the user's current location and plot it out ... In our example, the Permissions functionality is handled by...
Read more >
Requests the geolocation permission on page load
Learn how to responsibly request geolocation permission in a way that provides good user experience.
Read more >
Request location permissions - Android Developers
... <grant-uri-permission> Ā· <instrumentation> Ā· <intent-filter> Ā· <manifest> Ā· <meta-data> ... <supports-screens> Ā· <uses-configuration> Ā· <uses-feature>Ā ...
Read more >
ask for geolocation permission again if it was denied
if a user denies permission for geolocation the first time, how can i ask for permission again when they click the geolocation button...
Read more >
geolocation - Feature policy
The geolocation policy controls whether the current document is allowed to use the Geolocation interface. If disabled in any document, calls to bothĀ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found