2

I've been trying to figure how a html5 browser like chrome or firefox performs geolocation under the hood but I'm running into some difficulties.

Difficulties

To be more precise, I want to know what happens when a piece of javascript calls navigator.geolocation.getCurrentPosition (success_func) but before success_func actually gets called back. I want to know how the browser goes about obtaining the latitude and longitude coordinates. What's the protocol it uses? What servers does it query to obtain this information? etc.

Here's what I have determined and tried:

  • Chrome and Firefox uses the MAC of nearby wifi access points to obtain geolocation by sending it to googlesapi.com. It is this MAC-wifi based implementation I am most interested in.
  • By the time success_func gets called, the browser has already obtained the geolocation data.
  • I made limited progress using proxy and packet captures like tcpcatcher and wireshark. I see a query is being made to googleapis.com:443 but of course it's over tls/ssl which means I can't read it. (using ssl monitor in tcpcatcher causes geoloc to fail in browser)
  • I tried using builtin devtool and console in browser but it seems to omit the communication that grabs the geoloc data. For example, using chrome's devtool (ctrl+shift+I), it does not show any CONNECT methods or connections to googleapis.com even though tcpcatcher clearly captures that during geolocation.
  • I've tried looking at the source to determine this but not having much luck. The problem is that browser codebases are just humongous and locating the pertinent class and source files would be difficult especially since I'm unfamiliar with their overall design. grepping for interesting keywords only goes so far.

If you guys were trying to determine and reverse the protocol a given browser uses to implement geolocation how would you guys proceed?

Other Resources

Here are some things I've already looked at that I found helpful:

The problem is some of the info mentioned there is out-of-date and no longer accurate. My aim now is to figure out exactly what changed and how an external custom application can use this protocol itself for geolocation.

6
  • Off-topic since both Chromium and Firefox are open-source, and thus this question is about software development. Jul 31, 2014 at 18:57
  • 1
    @JasonGeffner It seems to fit within the definition in the help center; this question is not about debugging, but rather about converting source code to plain English (in the least charitable interpretation). Questions about reading source code (especially large, unfamiliar codebases) don't seem to be ruled out by the help center's definition.
    – Brilliand
    Jul 31, 2014 at 19:36
  • 2
    It takes about 5 seconds to enter googleapis.com geolocation from mac address into google to find the reference at developers.google.com/maps/documentation/business/geolocation/…. This includes a "WiFi access point objects" section. Jason is right, you don't need any reverse engineering. Jul 31, 2014 at 20:30
  • @GuntramBlohm There's only one issue with that: it requires enabling billing which requires inputting credit card and personal info. This is the first thing I've tried. How is chrome and firefox able to use the api in this case? Do they have a special api-key they use or something?
    – greatwolf
    Jul 31, 2014 at 20:51
  • When I first posted this, the question felt like it was in the spirit of RE. However, if SO is a better fit, feel free to migrate it there.
    – greatwolf
    Jul 31, 2014 at 21:13

1 Answer 1

2

For Firefox (i.e. Gecko) and Chrome (i.e. Blink) you can just look in the source code:

Searching the Firefox codebase for getCurrentPosition yields the source file nsGeolocation.cpp. As you see in the linked source line, it creates an instance of a geolocation provider. Assuming Firefox for Desktop, there is only the NetworkGeolocationProvider (FirefoxOS may also use GPS).

In essence, Gecko opens an XMLHttpRequest to the URL specified in about:config as geo.wifi.uri. Per default this is https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%.

Blink performs its http request in network_location_request.cc, with the same API endpoint defined as in Firefox (cf. location_arbitrator_impl.cc).

(NB: I looked at Gecko HG revision a4f779bd7cc2 and Blink SVN revision 287303)

Not the answer you're looking for? Browse other questions tagged or ask your own question.