Requests the geolocation permission on page load

Published on Updated on

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:

Lighthouse audit showing geolocation request on page load

Lighthouse checks all JavaScript executed on page load. If the code calls geolocation.getCurrentPosition() or geolocation.watchPosition(), 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.getCurrentPosition() and 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.

Resources

Updated on Improve article

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.