Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (35 sloc) 958 Bytes

Geofencing Explained

What's All This About?

TODO(slightlyoff): explain motivation for feature here.

Registering A Geofence

Registering for a geofence is straightforward:

<!DOCTYPE html>
<!-- https://app.example.com/index.html -->
<html>
  <head>
    <script>
      navigator.serviceWorker.register("/sw.js");

      navigator.serviceWorker.whenReady().then(function(sw) {
        // TODO
      });
    </script>
  </head>
  <body> ... </body>
</html>

Handling Geofence Events

Location notification happens from the Service Worker context via the new ... event.

// sw.js
self.<...> = function(event) {
  // TODO
};

Removing Geofences

// TODO

Notes

  • Since Service Workers are a requirement for Geofencing, and since Service Workers are limited to HTTPS origins, sites served without encryption will always fail to register for fences.
  • SW event handlers aren't allowed to run forever.