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.
Each Best Practices audit is weighted equally in the Lighthouse Best Practices Score. Learn more in The Best Practices score.
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.