Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: waitForNavigation in OOPIFs #8117

Merged
merged 1 commit into from Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/FrameManager.ts
Expand Up @@ -53,6 +53,7 @@ export const FrameManagerEmittedEvents = {
FrameAttached: Symbol('FrameManager.FrameAttached'),
FrameNavigated: Symbol('FrameManager.FrameNavigated'),
FrameDetached: Symbol('FrameManager.FrameDetached'),
FrameSwapped: Symbol('FrameManager.FrameSwapped'),
LifecycleEvent: Symbol('FrameManager.LifecycleEvent'),
FrameNavigatedWithinDocument: Symbol(
'FrameManager.FrameNavigatedWithinDocument'
Expand Down Expand Up @@ -422,6 +423,8 @@ export class FrameManager extends EventEmitter {
// an actual removement of the frame.
// For frames that become OOP iframes, the reason would be 'swap'.
if (frame) this._removeFramesRecursively(frame);
} else if (reason === 'swap') {
this.emit(FrameManagerEmittedEvents.FrameSwapped, frame);
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/common/LifecycleWatcher.ts
Expand Up @@ -82,6 +82,7 @@ export class LifecycleWatcher {

_maximumTimer?: NodeJS.Timeout;
_hasSameDocumentNavigation?: boolean;
_swapped?: boolean;

constructor(
frameManager: FrameManager,
Expand Down Expand Up @@ -121,6 +122,11 @@ export class LifecycleWatcher {
FrameManagerEmittedEvents.FrameNavigatedWithinDocument,
this._navigatedWithinDocument.bind(this)
),
helper.addEventListener(
this._frameManager,
FrameManagerEmittedEvents.FrameSwapped,
this._frameSwapped.bind(this)
),
helper.addEventListener(
this._frameManager,
FrameManagerEmittedEvents.FrameDetached,
Expand Down Expand Up @@ -211,15 +217,26 @@ export class LifecycleWatcher {
this._checkLifecycleComplete();
}

_frameSwapped(frame: Frame): void {
if (frame !== this._frame) return;
this._swapped = true;
this._checkLifecycleComplete();
}

_checkLifecycleComplete(): void {
// We expect navigation to commit.
if (!checkLifecycle(this._frame, this._expectedLifecycle)) return;
this._lifecycleCallback();
if (
this._frame._loaderId === this._initialLoaderId &&
!this._hasSameDocumentNavigation
)
) {
if (this._swapped) {
this._swapped = false;
this._newDocumentNavigationCompleteCallback();
}
return;
}
if (this._hasSameDocumentNavigation)
this._sameDocumentNavigationCompleteCallback();
if (this._frame._loaderId !== this._initialLoaderId)
Expand Down
24 changes: 24 additions & 0 deletions test/oopif.spec.ts
Expand Up @@ -154,6 +154,30 @@ describeChromeOnly('OOPIF', function () {
await utils.detachFrame(page, 'frame1');
expect(page.frames()).toHaveLength(1);
});

it('should support wait for navigation for transitions from local to OOPIF', async () => {
const { server } = getTestState();

await page.goto(server.EMPTY_PAGE);
const framePromise = page.waitForFrame((frame) => {
return page.frames().indexOf(frame) === 1;
});
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);

const frame = await framePromise;
expect(frame.isOOPFrame()).toBe(false);
const nav = frame.waitForNavigation();
await utils.navigateFrame(
page,
'frame1',
server.CROSS_PROCESS_PREFIX + '/empty.html'
);
await nav;
expect(frame.isOOPFrame()).toBe(true);
await utils.detachFrame(page, 'frame1');
expect(page.frames()).toHaveLength(1);
});

it('should keep track of a frames OOP state', async () => {
const { server } = getTestState();

Expand Down