ServiceWorker implementation status in Firefox
I've been working on the Gecko implementation for a while now, helped by several other Mozillians and some of the first patches are now beginning to land on Nightly. Interest in trying out a build has been high within both Mozilla and outside. I've been procrastinating about a detailed hacks article, but I thought I'd at least share the build and what Firefox supports for now and what it doesn't.
- Download the build
- Run it using a clean profile.
- Go to about:config and set "dom.serviceWorkers.enabled" to true.
- Registration, installation, activation, unregistration. Update() is not according to the spec, the scripts themselves are not cached offline, so don't actually try to make offline apps yet.
- Intercepting navigation and fetch events and replying using a simple SameOriginResponse object.
- Intercepting Push API events.
- Cache API
- fetch() - You'll have to use XHR in the worker.
- ClientLists and postMessage() to talk to windows
- Persistence - ServiceWorker registrations are currently not stored across restarts.
- Anything that throws an error :)
- No devtools support right now.
SameOriginResponse is a relic of an earlier version of the spec. Similarly the Request object received from the fetch event is not exactly up to speed with the spec.
I have two sample applications on Github to try out the build. Note that ServiceWorkers require HTTPS connections. For development, please create a new boolean preference in about:config - "dom.serviceWorkers.testing.enabled" and set it to true. This will disable the HTTPS requirement.
Push API Test - Remember to run the Firefox build from the command line since this demo prints stuff to the terminal. Click the register button to sign up for Push notifications. To perform the push, copy the unique URL and run
curl -vX PUT 'URL'
The ServiceWorker will be spun up and a 'push' notification delivered.
Simple Network Interception - This example will load an iframe with some content. Refresh the page and the iframe's content should change and the browser should show an alert dialog. These changes are done by the ServiceWorkers (there are 2, one for the current scope and one for the sub/ scope) intercepting the requests for both "fakescript.js" and the iframe and injecting their own responses.
ContributingWe could always use help with the specification, implementation and testing.
The specification is improved by filing issues.
The tracking bug for the Gecko implementation is Bug 903441. There is a mercurial patch queue for patches that have not landed on trunk.
I (nsm) am around on the #content channel in irc.mozilla.org if you have questions.