Only request geolocation information in response to a user gesture?

It seems there's a recommendation from Google not to load geolocation on page load:

Users are mistrustful of or confused by pages that automatically request their location on page load. Rather than automatically requesting a user's location on page load, tie the request to a user's gesture, such as a tapping a "Find Stores Near Me" button. Make sure that the gesture clearly and explicitly expresses the need for the user's location.

And it doesn't matter if you use watchPosition() or getCurrentPosition():

Lighthouse collects the JavaScript that was executed on page load. If this code contains calls to geolocation.getCurrentPosition() or geolocation.watchPosition(), and geolocation permission was not already granted, then the user's location was requested.

We also noticed that there's a massive delay in getting the geolocation of user since that Chrome update.


The watchPosition() method lets you register a handler that the browser calls automatically every time that the device's position changes. This is preferable to polling.

id = navigator.geolocation.watchPosition(success[, error[, options]])

The violation is not related to polling. It is caused by attempting to access geolocation on page load. Geolocation access should only be requested after a user "gesture" like a click or tap.

document.querySelector('.permission-granted-button').addEventListener('click', () => {
  navigator.geolocation.watchPosition(successCallback, errorCallback, optionsObject);
});

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition