(with apologies to Jeff Atwood)

As you may know, one of my projects, Shout, is primarily a location based messaging app. That means getting the user’s location is the highest priority.

We gather the location using the standard HTML5 Geolocation API, making a call to Geolocation.watchPosition(). If the user agrees to share their location, it is pulled from various sources, primarily GPS.

On 13th March, we’d just pushed some code to production and hughjd began to notice something strange when using Shout on a desktop browser. Intermittently the user’s location wasn’t being identified.

However I was unable to reproduce the problem! So I then tried the app on Android, our primary platform, and here the issue was far more prevalent. In my testing, the location was never retrieved.

A Confusing Problem

Being developers familiar with the first rule of programming, we assumed the problem would be found in our latest commits to master. We started digging through commits, but we couldn’t find anything that could cause this issue. In the call to watchPosition() you can pass an optional timeout parameter, which by default is infinite. When passing “{ timeout : 5000 }”, we actually got an error thrown instead of just ‘nothing’.

Even more confusingly, my desktop worked fine and Android didn’t work at all, whereas for Hugh, his Android worked (mostly) fine and desktop didn’t work! What is going on!?

Intermittent issues are the most annoying to debug

With no help to be found on Google or Stack Overflow, and nothing to go on except that we had both updated Chrome just before the issue appeared, we (skeptically!) decided to look at browser versions. Hugh was on 65.x while I was on 64.x. Surely this couldn’t be a Chrome issue? After changing a few chrome settings and still having it work for me, I finally updated my Chrome to 65.x…and boom, the issue appeared! So it is a Chrome bug!

Confirming Our Suspicions

With these latest findings, we decided to look outside of our app for confirmation that this issue was occuring elsewhere, so we decided to test browser location with BrowserLeaks. Upon opening the page, we got the “(3) TIMEOUT Timeout expired”, just as with our app with a timeout parameter! Some refreshes worked, then further ones returned the same timeout, and only closing and reopening Chrome did we get the location again.

This confirms it, a bug in Chrome

We also looked at other ways to retrieve the users location, although they turned out to be not as accurate.

Awaiting And A Fix

So, if you were using Chrome 65.x+, then calls to location may have been causing issues on all platforms including mobile.

I went on to tweet at Google Devs, Chromium Devs and Android Devs, and it took a while but the bug was finally confirmed and fixed! If you want to read up on the exact problem, here’s the ticket for the issue – https://bugs.chromium.org/p/chromium/issues/detail?id=820945