fix(events): avoid firing events after close/detach (#2919)

This commit is contained in:
Dmitry Gozman 2020-07-10 16:38:01 -07:00 committed by GitHub
parent fc6861410b
commit c63b706aac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -71,6 +71,11 @@ export class FrameManager {
this._mainFrame = undefined as any as Frame;
}
dispose() {
for (const frame of this._frames.values())
frame._stopNetworkIdleTimer();
}
mainFrame(): Frame {
return this._mainFrame;
}
@ -926,6 +931,7 @@ export class Frame {
}
_onDetached() {
this._stopNetworkIdleTimer();
this._detached = true;
this._detachedCallback();
for (const data of this._contextData.values()) {

View File

@ -145,6 +145,7 @@ export class Page extends EventEmitter {
}
_didClose() {
this._frameManager.dispose();
assert(this._closedState !== 'closed', 'Page closed twice');
this._closedState = 'closed';
this.emit(Events.Page.Close);
@ -152,11 +153,13 @@ export class Page extends EventEmitter {
}
_didCrash() {
this._frameManager.dispose();
this.emit(Events.Page.Crash);
this._crashedCallback(new Error('Page crashed'));
}
_didDisconnect() {
this._frameManager.dispose();
assert(!this._disconnected, 'Page disconnected twice');
this._disconnected = true;
this._disconnectedCallback(new Error('Page closed'));