Skip to content

Commit 6b5c2cf

Browse files
pavelfeldmanaslushnikov
authored andcommitted
revert: lifecycle refactoring, it breaks setContent (#4420)
1 parent 1230866 commit 6b5c2cf

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/server/chromium/crPage.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ class FrameSession {
386386
const { windowId } = await this._client.send('Browser.getWindowForTarget');
387387
this._windowId = windowId;
388388
}
389-
390-
let isInitialLifecycle = true;
389+
let lifecycleEventsEnabled: Promise<any>;
391390
if (!this._isMainFrame())
392391
this._addSessionListeners();
393392
const promises: Promise<any>[] = [
@@ -409,22 +408,20 @@ class FrameSession {
409408
frame._evaluateExpression(binding.source, false, {}).catch(e => {});
410409
}
411410
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) {
415412
// Ignore lifecycle events for the initial empty page. It is never the final page
416413
// hence we are going to get more lifecycle updates after the actual navigation has
417414
// 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+
}
423422
}),
424423
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 }),
428425
this._client.send('Runtime.enable', {}),
429426
this._client.send('Page.addScriptToEvaluateOnNewDocument', {
430427
source: sourceMap.generateSourceUrl(),

0 commit comments

Comments
 (0)