My webapp loads Google Maps JS API v3 in the html head like this:
<head>
<script src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places"></script>
</head>
Everything works fine, except in ~1 out of 100 mobile pageviews, Google Maps will make a callback to global gm_authFailure
, which according to Google occurs when 'authentication fails' https://developers.google.com/maps/documentation/javascript/events#auth-errors
To debug, I'm capturing the entire console log from document load, and within my global gm_authFailure
function:
I'm printing the log, which just prior to
gm_authFailure
being called, always shows the below, which according to the docs, happens when Google determines the maps library wasn't loaded from https://maps.googleapis.com/maps/api/js:Google Maps JavaScript API error: NotLoadingAPIFromGoogleMapsError https://developers.google.com/maps/documentation/javascript/error-messages#not-loading-api-from-google-maps-error
I'm also capturing the call stack that called
gm_authFailure
, usingnew Error().stack
which outputs the below, which suggests a. the Maps library IS being loaded from maps.googleapis.com, and b. the error occurs at library authentication, rather than calling the library to use it.at gm_authFailure (https://EXAMPLE.COM/MY_PATH:3276:22) at https://maps.googleapis.com/maps-api-v3/api/js/40/7/common.js:73:368 at Qp.o (https://maps.googleapis.com/maps-api-v3/api/js/40/7/common.js:149:177) at Object.c [as _tj1nu1] (https://maps.googleapis.com/maps-api-v3/api/js/40/7/common.js:67:84) at https://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?1shttps%3A%2F%EXAMPLE.COM%2FMY_PATH&4sMY_API_KEY&callback=_xdc_._tj1nu1&key=MY_API_KEY&token=18280:1:28
Hypothesis:
- Affected users have some app, browser extension, or cellular data saving feature that's blocking or caching the maps library and thus confusing the Maps library
- Is it strange that in the
gm_authFailure
callstack, the initiating 'https://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate' URL has my API key listed twice?
Things I know:
When
gm_authFailure
is called, the library won't work anymore, e.g. I'm not able to create a new map:var test_map = new google.maps.Map(document.getElementById("test_google_map"), {"zoom":2}) console.log(test_map.zoom)
is undefined as opposed to 2
- Users that trigger this error often have other recorded pageloads on the same & different days that load without error.
- I'm unable to reproduce the error using the same device/browser & visiting the same page
- Even though this happens in only ~1% of pageloads, it's happening ~100 times/day, so I'm confident it's not a fluke.