fix(chromium): race between oopif attach and context clear

There is a race between:
- `Runtime.executionContextsCleared` coming in the OOPIF.
- `Page.frameNavigated`/`Target.attachedToTarget` when frame goes local->remote.

As a result, we can have stale execution contexts from the previous non-OOPIF
frame that does not exist anymore, instead of new contexts in the OOPIF.

This causes things like recorder trying to initialize in the wrong context and fail.

Now that we clear contexts upon local->remote switch, recorder waits for
the new context to be created an successfully initializes.
This commit is contained in:
Dmitry Gozman 2024-11-22 16:30:33 +00:00
parent f123f7ac69
commit fbf2cf536a

View file

@ -731,6 +731,10 @@ class FrameSession {
if (!frame)
return; // Subtree may be already gone due to renderer/browser race.
this._page._frameManager.removeChildFramesRecursively(frame);
for (const [contextId, context] of this._contextIdToContext) {
if (context.frame === frame)
this._onExecutionContextDestroyed(contextId);
}
const frameSession = new FrameSession(this._crPage, session, targetId, this);
this._crPage._sessions.set(targetId, frameSession);
frameSession._initialize(false).catch(e => e);