@@ -21,7 +21,7 @@ import { logDebug, logError } from './log';
21
21
import { Deferred } from './promise' ;
22
22
import { ExponentialBackoff } from '../remote/backoff' ;
23
23
import { isIndexedDbTransactionError } from '../local/simple_db' ;
24
- import { getWindow } from '../platform/dom' ;
24
+ import { getDocument } from '../platform/dom' ;
25
25
26
26
const LOG_TAG = 'AsyncQueue' ;
27
27
@@ -235,12 +235,18 @@ export class AsyncQueue {
235
235
// Visibility handler that triggers an immediate retry of all retryable
236
236
// operations. Meant to speed up recovery when we regain file system access
237
237
// after page comes into foreground.
238
- private visibilityHandler = ( ) : void => this . backoff . skipBackoff ( ) ;
238
+ private visibilityHandler : ( ) => void = ( ) => {
239
+ const document = getDocument ( ) ;
240
+ if ( document ) {
241
+ logDebug ( LOG_TAG , 'Visibility state changed to ' , document . visibilityState ) ;
242
+ }
243
+ this . backoff . skipBackoff ( ) ;
244
+ } ;
239
245
240
246
constructor ( ) {
241
- const window = getWindow ( ) ;
242
- if ( window && typeof window . addEventListener === 'function' ) {
243
- window . addEventListener ( 'visibilitychange' , this . visibilityHandler ) ;
247
+ const document = getDocument ( ) ;
248
+ if ( document && typeof document . addEventListener === 'function' ) {
249
+ document . addEventListener ( 'visibilitychange' , this . visibilityHandler ) ;
244
250
}
245
251
}
246
252
@@ -293,9 +299,9 @@ export class AsyncQueue {
293
299
this . verifyNotFailed ( ) ;
294
300
if ( ! this . _isShuttingDown ) {
295
301
this . _isShuttingDown = true ;
296
- const window = getWindow ( ) ;
297
- if ( window ) {
298
- window . removeEventListener ( 'visibilitychange' , this . visibilityHandler ) ;
302
+ const document = getDocument ( ) ;
303
+ if ( document && typeof document . removeEventListener === 'function' ) {
304
+ document . removeEventListener ( 'visibilitychange' , this . visibilityHandler ) ;
299
305
}
300
306
await this . enqueueEvenAfterShutdown ( op ) ;
301
307
}
0 commit comments