Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access IndexedDB from Web Workers

I can not seem to figure out HOW to use indexedDB inside web worker. I've tried a lot of different ways, but indexedDB is always "undefined" in worker scope. I thought it was supposed to be accessible via indexedDB or self.indexedDB???

self.indexedDB = self.indexedDB || self.msIndexedDB || self.mozIndexedDB || self.webkitIndexedDB || self.OIndexedDB;

indexedDB = indexedDB || msIndexedDB || mozIndexedDB || webkitIndexedDB || OIndexedDB;

all are undefined ... i even iterated through the properties of the self object, and there was no indexedDB property or method. fwiw, i'm using ff 18, AND, ff nightly (21a), and i tried it with chrome.

like image 727
vector Avatar asked Jan 23 '13 12:01

vector


2 Answers

Update September 2015: Accessing IndexedDB from web worker in Firefox is now possible: https://bugzilla.mozilla.org/show_bug.cgi?id=701634

If you want to use IndexedDB in chrome just use the following line:

indexedDB = typeof window == 'object' ? window.indexedDB : webkitIndexedDB;
like image 96
Deni Spasovski Avatar answered Nov 12 '22 14:11

Deni Spasovski


indexeddb is accessible from Web Workers since firefox 37 (released March 31st, 2015).

IndexedDB
Database to store records holding simple values and hierarchical objects.

IndexedDB API WebWorkers screenshot

See Functions and classes available to Web Workers (MDN)

like image 39
mate64 Avatar answered Nov 12 '22 14:11

mate64