7

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.

1

2 Answers 2

11

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;
8
  • 2
    thanks a million. i searched all night and never found that. it looks like it's going to be a WHILE before it's available ... well, i've only wasted 1 day of my time ... back to the drawing board ...
    – vector
    Jan 23, 2013 at 17:26
  • np, if you need basic examples of IndexedDB usage check out this project github.com/denimf/IndexedDbToDo Jan 23, 2013 at 18:24
  • And I just noticed that you are a new user so you should accept the answer if it solves your problem. Jan 23, 2013 at 18:25
  • i'd love to, but, i don't know how, lmao. i was going to do that as soon as you answered the first time, but i don't see the option [o_O]
    – vector
    Jan 23, 2013 at 22:03
  • 2
    Deni, fyi, as of chrome 24 (current stable channel) you don't need that stuff, indexedDB is no longer prefixed in chrome. A straight indexedDB will suffice, no matter if you're running in a worker or not.
    – dgrogan
    Feb 2, 2013 at 2:39
4

is accessible from Web Workers since 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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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