@@ -241,21 +241,28 @@ export class FocusMonitor implements OnDestroy {
241
241
this . _windowFocusTimeoutId = setTimeout ( ( ) => this . _windowFocused = false ) ;
242
242
} ;
243
243
244
+ // Event listener options that enable capturing and also mark the the listener as passive
245
+ // if the browser supports it.
246
+ const captureEventListenerOptions = supportsPassiveEventListeners ( ) ?
247
+ { passive : true , capture : true } : true ;
248
+
244
249
// Note: we listen to events in the capture phase so we can detect them even if the user stops
245
250
// propagation.
246
251
this . _ngZone . runOutsideAngular ( ( ) => {
247
- document . addEventListener ( 'keydown' , documentKeydownListener , true ) ;
248
- document . addEventListener ( 'mousedown' , documentMousedownListener , true ) ;
252
+ document . addEventListener ( 'keydown' , documentKeydownListener , captureEventListenerOptions ) ;
253
+ document . addEventListener ( 'mousedown' , documentMousedownListener ,
254
+ captureEventListenerOptions ) ;
249
255
document . addEventListener ( 'touchstart' , documentTouchstartListener ,
250
- supportsPassiveEventListeners ( ) ? ( { passive : true , capture : true } as any ) : true ) ;
256
+ captureEventListenerOptions ) ;
251
257
window . addEventListener ( 'focus' , windowFocusListener ) ;
252
258
} ) ;
253
259
254
260
this . _unregisterGlobalListeners = ( ) => {
255
- document . removeEventListener ( 'keydown' , documentKeydownListener , true ) ;
256
- document . removeEventListener ( 'mousedown' , documentMousedownListener , true ) ;
261
+ document . removeEventListener ( 'keydown' , documentKeydownListener , captureEventListenerOptions ) ;
262
+ document . removeEventListener ( 'mousedown' , documentMousedownListener ,
263
+ captureEventListenerOptions ) ;
257
264
document . removeEventListener ( 'touchstart' , documentTouchstartListener ,
258
- supportsPassiveEventListeners ( ) ? ( { passive : true , capture : true } as any ) : true ) ;
265
+ captureEventListenerOptions ) ;
259
266
window . removeEventListener ( 'focus' , windowFocusListener ) ;
260
267
261
268
// Clear timeouts for all potentially pending timeouts to prevent the leaks.
0 commit comments