Users are mistrustful of or confused by pages that automatically request their location on page load.
How the Lighthouse geolocation audit fails
Lighthouse flags pages that request geolocation permission on load:
If the code calls
and geolocation permission has not already been granted, the audit fails.
If geolocation permission was granted to a page before the audit, Lighthouse can't identify any geolocation permission requests. So, make sure to reset permissions before running the audit.
Lighthouse reports the URL and line number of each request for geolocation permission.
How to ask for users' locations responsibly
Remove all calls to
geolocation.watchPosition() that occur on page load.
To provide a better user experience:
- Always request geolocation permission after a user action, not on page load.
- Clearly indicate that the action will request geolocation permission.
- Assume users won't give you their locations.
- Use a fallback if users don't grant geolocation permission.
See Google's User Location article for more information.