From 5e6eed0d8716d02ec28d0ed242fd07300925a8e4 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 19 Nov 2020 19:20:53 -0800 Subject: [PATCH] fix(frames): do not start network idle timer after detach (#4502) This fixes a common flaky error on the bots: ``` Error: Cannot find object to emit "loadstate": Frame@f5b80c8c318c5471a1e6af552866e981 ``` --- src/client/connection.ts | 2 +- src/server/frames.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/connection.ts b/src/client/connection.ts index bf0461d640..cc0e01dc64 100644 --- a/src/client/connection.ts +++ b/src/client/connection.ts @@ -122,7 +122,7 @@ export class Connection { } const object = this._objects.get(guid); if (!object) - throw new Error(`Cannot find object to call "${method}": ${guid}`); + throw new Error(`Cannot find object to emit "${method}": ${guid}`); object._channel.emit(method, this._replaceGuidsWithChannels(params)); } diff --git a/src/server/frames.ts b/src/server/frames.ts index 043df215e6..8ce888a285 100644 --- a/src/server/frames.ts +++ b/src/server/frames.ts @@ -1056,7 +1056,10 @@ export class Frame extends EventEmitter { _startNetworkIdleTimer() { assert(!this._networkIdleTimer); - if (this._firedLifecycleEvents.has('networkidle')) + // We should not start a timer and report networkidle in detached frames. + // This happens at least in Firefox for child frames, where we may get requestFinished + // after the frame was detached - probably a race in the Firefox itself. + if (this._firedLifecycleEvents.has('networkidle') || this._detached) return; this._networkIdleTimer = setTimeout(() => this._onLifecycleEvent('networkidle'), 500); }