Geolocation getCurrentPosition function broken in Chrome 65

The reason your geolocate code is no longer working...

- Chris Pook, 21st March 2018

As of the Chrome 65 update rolled out in March 2018, a bug has been introduced to the geolocate functionality of the browser. This manifests itself in timeouts to all calls to navigator.geolocation.getCurrentPosition() and navigator.geolocation.watchPosition().

We came across this bug during development of our Magento Collect in Store application which relies on the API to allow users to find collection locations near to them.

As of today we haven't been able to find a work around to the bug. However we suggest that you handle the situation by ensuring a timeout is set so that the function calls don't disappear in to a black hole. By setting a 5 second timeout you can gracefully return a message to the user along the lines of "location services are not available in your browser currently".


if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(
        function (position) {
            // on success this will be called.
        },
        function (err) {
            // on error (including timeout) this function will be called.
        },
        {
            timeout: 5000
        }
    );
}

The following Chromium bug was raised on March 14th and appears to cover the situation: Chromium Issue 820945