Skip to content
Learn Measure Blog Case studies About
On this page
  • How the Lighthouse geolocation audit fails
  • How to ask for users' locations responsibly
  • Resources

Requests the geolocation permission on page load

May 2, 2019 — Updated Aug 28, 2019
Appears in: Best Practices audits
On this page
  • How the Lighthouse geolocation audit fails
  • How to ask for users' locations responsibly
  • Resources

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 #

  • Source code for Requests the geolocation permission on page load audit
  • User Location
Last updated: Aug 28, 2019 — Improve article
Return to all articles
Share
subscribe

Contribute

  • File a bug
  • View source

Related content

  • developer.chrome.com
  • Chrome updates
  • Web Fundamentals
  • Case studies
  • Podcasts
  • Shows

Connect

  • Twitter
  • YouTube
  • Google Developers
  • Chrome
  • Firebase
  • Google Cloud Platform
  • All products
  • Terms & Privacy
  • Community Guidelines

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.