@@ -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,22 @@ 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 (
242
+ LOG_TAG ,
243
+ 'Visibility state changed to ' ,
244
+ document . visibilityState
245
+ ) ;
246
+ }
247
+ this . backoff . skipBackoff ( ) ;
248
+ } ;
239
249
240
250
constructor ( ) {
241
- const window = getWindow ( ) ;
242
- if ( window && typeof window . addEventListener === 'function' ) {
243
- window . addEventListener ( 'visibilitychange' , this . visibilityHandler ) ;
251
+ const document = getDocument ( ) ;
252
+ if ( document && typeof document . addEventListener === 'function' ) {
253
+ document . addEventListener ( 'visibilitychange' , this . visibilityHandler ) ;
244
254
}
245
255
}
246
256
@@ -293,9 +303,12 @@ export class AsyncQueue {
293
303
this . verifyNotFailed ( ) ;
294
304
if ( ! this . _isShuttingDown ) {
295
305
this . _isShuttingDown = true ;
296
- const window = getWindow ( ) ;
297
- if ( window ) {
298
- window . removeEventListener ( 'visibilitychange' , this . visibilityHandler ) ;
306
+ const document = getDocument ( ) ;
307
+ if ( document && typeof document . removeEventListener === 'function' ) {
308
+ document . removeEventListener (
309
+ 'visibilitychange' ,
310
+ this . visibilityHandler
311
+ ) ;
299
312
}
300
313
await this . enqueueEvenAfterShutdown ( op ) ;
301
314
}
0 commit comments