@@ -386,8 +386,7 @@ class FrameSession {
386
386
const { windowId } = await this . _client . send ( 'Browser.getWindowForTarget' ) ;
387
387
this . _windowId = windowId ;
388
388
}
389
-
390
- let isInitialLifecycle = true ;
389
+ let lifecycleEventsEnabled : Promise < any > ;
391
390
if ( ! this . _isMainFrame ( ) )
392
391
this . _addSessionListeners ( ) ;
393
392
const promises : Promise < any > [ ] = [
@@ -409,22 +408,20 @@ class FrameSession {
409
408
frame . _evaluateExpression ( binding . source , false , { } ) . catch ( e => { } ) ;
410
409
}
411
410
const isInitialEmptyPage = this . _isMainFrame ( ) && this . _page . mainFrame ( ) . url ( ) === ':' ;
412
- if ( ! isInitialEmptyPage )
413
- this . _firstNonInitialNavigationCommittedFulfill ( ) ;
414
- this . _eventListeners . push ( helper . addEventListener ( this . _client , 'Page.lifecycleEvent' , event => {
411
+ if ( isInitialEmptyPage ) {
415
412
// Ignore lifecycle events for the initial empty page. It is never the final page
416
413
// hence we are going to get more lifecycle updates after the actual navigation has
417
414
// started (even if the target url is about:blank).
418
- // Note: isInitialLifecycle is reset after the Page.setLifecycleEventsEnabled response.
419
- const ignoreLifecycle = isInitialLifecycle && isInitialEmptyPage ;
420
- if ( ! ignoreLifecycle )
421
- this . _onLifecycleEvent ( event ) ;
422
- } ) ) ;
415
+ lifecycleEventsEnabled . then ( ( ) => {
416
+ this . _eventListeners . push ( helper . addEventListener ( this . _client , 'Page.lifecycleEvent' , event => this . _onLifecycleEvent ( event ) ) ) ;
417
+ } ) ;
418
+ } else {
419
+ this . _firstNonInitialNavigationCommittedFulfill ( ) ;
420
+ this . _eventListeners . push ( helper . addEventListener ( this . _client , 'Page.lifecycleEvent' , event => this . _onLifecycleEvent ( event ) ) ) ;
421
+ }
423
422
} ) ,
424
423
this . _client . send ( 'Log.enable' , { } ) ,
425
- this . _client . send ( 'Page.setLifecycleEventsEnabled' , { enabled : true } ) . then ( ( ) => {
426
- isInitialLifecycle = true ;
427
- } ) ,
424
+ lifecycleEventsEnabled = this . _client . send ( 'Page.setLifecycleEventsEnabled' , { enabled : true } ) ,
428
425
this . _client . send ( 'Runtime.enable' , { } ) ,
429
426
this . _client . send ( 'Page.addScriptToEvaluateOnNewDocument' , {
430
427
source : sourceMap . generateSourceUrl ( ) ,
0 commit comments