This repository was archived by the owner on Jun 10, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ export class IndexedDbProvider extends NoSqlProvider.DbProvider {
4545 this . _dbFactory = explicitDbFactory ;
4646 this . _fakeComplicatedKeys = ! explicitDbFactorySupportsCompoundKeys ;
4747 } else {
48- this . _dbFactory = window . _indexedDB || window . indexedDB || window . mozIndexedDB || window . webkitIndexedDB || window . msIndexedDB ;
48+ const win = this . getWindow ( ) ;
49+ this . _dbFactory = win . _indexedDB || win . indexedDB || win . mozIndexedDB || win . webkitIndexedDB || win . msIndexedDB ;
4950
5051 if ( typeof explicitDbFactorySupportsCompoundKeys !== 'undefined' ) {
5152 this . _fakeComplicatedKeys = ! explicitDbFactorySupportsCompoundKeys ;
@@ -57,6 +58,20 @@ export class IndexedDbProvider extends NoSqlProvider.DbProvider {
5758 }
5859 }
5960
61+ /**
62+ * Gets global window object - whether operating in worker or UI thread context.
63+ * Adapted from: https://stackoverflow.com/questions/7931182/reliably-detect-if-the-script-is-executing-in-a-web-worker
64+ */
65+ getWindow ( ) {
66+ if ( typeof window === 'object' && window . document ) {
67+ return window ;
68+ } else if ( self && self . document === undefined ) {
69+ return self ;
70+ }
71+
72+ throw new Error ( 'Undefined context' ) ;
73+ }
74+
6075 static WrapRequest < T > ( req : IDBRequest ) : SyncTasks . Promise < T > {
6176 const task = SyncTasks . Defer < T > ( ) ;
6277
You can’t perform that action at this time.
0 commit comments