Service Worker with IndexedDB Demo

In this demo, the below image is stored in IndexedDB when the service worker is installed. When the service worker is active, the image will be fetched from IndexedDB store when it is requested.

If There Wasn't That Issue with Firefox…

This works in Chromium (and Chrome), but currently not in Firefox. And yes, it's supposed to work in Firefox as well. When the service worker is active, and the page gets (re-)loaded, Firefox is throwing an error with the following message (unfortunately there's no additional information in the console error log):

A ServiceWorker intercepted the request and encountered an unexpected error.

Here the Image:

You are supposed to be seeing an image here.

Issue Report

The issue is filed in the Firefox issue tracker as bug 1253777.

Workaround for Firefox

For Firefox versions 46 or greater, there's a workaround that copies the image Blob to an ArrayBuffer. The workaround is only available from Firefox version 46 or greater because it uses FileReader, which isn't supported in workers in prior versions.

Source Code

The source code is available here under the terms of the Apache License Version 2.0.