revert: lifecycle refactoring, it breaks setContent (#4420)

This commit is contained in:
Pavel Feldman 2020-11-12 16:13:55 -08:00 committed by Andrey Lushnikov
parent 1230866be6
commit 6b5c2cf38b

View file

@ -386,8 +386,7 @@ class FrameSession {
const { windowId } = await this._client.send('Browser.getWindowForTarget');
this._windowId = windowId;
}
let isInitialLifecycle = true;
let lifecycleEventsEnabled: Promise<any>;
if (!this._isMainFrame())
this._addSessionListeners();
const promises: Promise<any>[] = [
@ -409,22 +408,20 @@ class FrameSession {
frame._evaluateExpression(binding.source, false, {}).catch(e => {});
}
const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ':';
if (!isInitialEmptyPage)
this._firstNonInitialNavigationCommittedFulfill();
this._eventListeners.push(helper.addEventListener(this._client, 'Page.lifecycleEvent', event => {
if (isInitialEmptyPage) {
// Ignore lifecycle events for the initial empty page. It is never the final page
// hence we are going to get more lifecycle updates after the actual navigation has
// started (even if the target url is about:blank).
// Note: isInitialLifecycle is reset after the Page.setLifecycleEventsEnabled response.
const ignoreLifecycle = isInitialLifecycle && isInitialEmptyPage;
if (!ignoreLifecycle)
this._onLifecycleEvent(event);
}));
lifecycleEventsEnabled.then(() => {
this._eventListeners.push(helper.addEventListener(this._client, 'Page.lifecycleEvent', event => this._onLifecycleEvent(event)));
});
} else {
this._firstNonInitialNavigationCommittedFulfill();
this._eventListeners.push(helper.addEventListener(this._client, 'Page.lifecycleEvent', event => this._onLifecycleEvent(event)));
}
}),
this._client.send('Log.enable', {}),
this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }).then(() => {
isInitialLifecycle = true;
}),
lifecycleEventsEnabled = this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }),
this._client.send('Runtime.enable', {}),
this._client.send('Page.addScriptToEvaluateOnNewDocument', {
source: sourceMap.generateSourceUrl(),