Skip to content

Commit

Permalink
fix: check lifecycle comp. on same page navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed May 16, 2022
1 parent 785abf4 commit 5572d4c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/common/FrameManager.ts
Expand Up @@ -108,6 +108,9 @@ export class FrameManager extends EventEmitter {
);
}
);
session.on('Page.frameStartedLoading', (event) => {
this._onFrameStartedLoading(event.frameId);
});
session.on('Page.frameStoppedLoading', (event) => {
this._onFrameStoppedLoading(event.frameId);
});
Expand Down Expand Up @@ -287,6 +290,13 @@ export class FrameManager extends EventEmitter {
this.emit(FrameManagerEmittedEvents.LifecycleEvent, frame);
}

_onFrameStartedLoading(frameId: string): void {
const frame = this._frames.get(frameId);
if (!frame) return;
frame._onLoadingStarted();
this.emit(FrameManagerEmittedEvents.LifecycleEvent, frame);
}

_onFrameStoppedLoading(frameId: string): void {
const frame = this._frames.get(frameId);
if (!frame) return;
Expand Down Expand Up @@ -650,6 +660,10 @@ export class Frame {
* @internal
*/
_name?: string;
/**
* @internal
*/
_hasStartedLoading = false;

/**
* @internal
Expand Down Expand Up @@ -1416,6 +1430,13 @@ export class Frame {
this._lifecycleEvents.add('load');
}

/**
* @internal
*/
_onLoadingStarted(): void {
this._hasStartedLoading = true;
}

/**
* @internal
*/
Expand Down
7 changes: 6 additions & 1 deletion src/common/LifecycleWatcher.ts
Expand Up @@ -255,7 +255,12 @@ export class LifecycleWatcher {
if (!frame._lifecycleEvents.has(event)) return false;
}
for (const child of frame.childFrames()) {
if (!checkLifecycle(child, expectedLifecycle)) return false;
if (
child._hasStartedLoading &&
!checkLifecycle(child, expectedLifecycle)
) {
return false;
}
}
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions test/assets/frames/lazy-frame.html
@@ -0,0 +1,4 @@
<iframe width="100%" height="300" src="about:blank"></iframe>
<div style="height: 600vh">
</div>
<iframe width="100%" height="300" src='./frame.html' loading="lazy"></iframe>
10 changes: 10 additions & 0 deletions test/frame.spec.ts
Expand Up @@ -278,6 +278,16 @@ describe('Frame specs', function () {
server.PREFIX + '/frames/frame.html?param=value#fragment'
);
});
it('should support lazy frames', async () => {
const { page, server } = getTestState();

await page.setViewport({ width: 1158, height: 1227 });
await page.goto(server.PREFIX + '/frames/lazy-frame.html');

const frames = page.frames();
expect(frames.length).toBe(3);
expect(frames[frames.length - 1]._hasStartedLoading).toBeFalsy();
});
});

describe('Frame.client', function () {
Expand Down

0 comments on commit 5572d4c

Please sign in to comment.