8

I am getting an error when opening an indexedDB database on Firefox. This code works fine in Chrome, but fails in Firefox.

<script type="text/javascript">
  var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
  var request = indexedDB.open("TestDB", 1);  
</script>

The Javascript error occurs on the line indexedDB.open("TestDB", 1).

tshepang
  • 12,111
  • 21
  • 91
  • 136
JIJIL
  • 81
  • 1
  • 7

2 Answers2

10

In my case, this error was due to privacy settings in Firefox. Setting history settings to "Firefox will: Remember history" in the preferences panel enabled IndexedDB to work.

user2398029
  • 6,699
  • 8
  • 48
  • 80
  • Your solution is more agreeable. Have a look at the limitations section in https://developer.mozilla.org/en-US/docs/IndexedDB/Basic_Concepts_Behind_IndexedDB – Ezhil V Mar 30 '13 at 13:10
-2

indexedDB object is method of window instance, so it must be

<script type="text/javascript">
  window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB ||  window.msIndexedDB;
var request = indexedDB.open("TestDB", 1);  
</script>

In you code, indexedDB become a local function. It doesn't work, obviously.

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
  • You made it worse. And why would a local function not work? [Functions are first class citizens in javascript](http://stackoverflow.com/a/61094/383793) – Chris Wesseling Mar 30 '13 at 10:21
  • these API functions (another one is indexedDB.cmp) should bind the owner object instance when invoking them. They are not pure function, although they should be since we are not using any instance variables (from user point of view). But from browser point of view, these function are not pure due to security check, they need to assess owner instance object. – Kyaw Tun Mar 30 '13 at 15:58