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: only check loading iframe in lifecycling #8348

Merged
merged 1 commit into from May 17, 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
20 changes: 20 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,12 @@ 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();
}

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

/**
* @internal
Expand Down Expand Up @@ -1416,6 +1429,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
3 changes: 3 additions & 0 deletions test/assets/frames/lazy-frame.html
@@ -0,0 +1,3 @@
<iframe width="100%" height="300" src="about:blank"></iframe>
<div style="height: 800vh"></div>
<iframe width="100%" height="300" src='./frame.html' loading="lazy"></iframe>
3 changes: 3 additions & 0 deletions test/assets/lazy-oopif-frame.html
@@ -0,0 +1,3 @@
<iframe width="100%" height="300" src="about:blank"></iframe>
<div style="height: 800vh"></div>
<iframe width="100%" height="300" src='www.example.com' loading="lazy"></iframe>
12 changes: 12 additions & 0 deletions test/frame.spec.ts
Expand Up @@ -278,6 +278,18 @@ describe('Frame specs', function () {
server.PREFIX + '/frames/frame.html?param=value#fragment'
);
});
itFailsFirefox('should support lazy frames', async () => {
const { page, server } = getTestState();

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

expect(page.frames().map((frame) => frame._hasStartedLoading)).toEqual([
true,
true,
false,
]);
});
});

describe('Frame.client', function () {
Expand Down
18 changes: 17 additions & 1 deletion test/oopif.spec.ts
Expand Up @@ -16,7 +16,11 @@

import utils from './utils.js';
import expect from 'expect';
import { getTestState, describeChromeOnly } from './mocha-utils'; // eslint-disable-line import/extensions
import {
getTestState,
describeChromeOnly,
itFailsFirefox,
} from './mocha-utils'; // eslint-disable-line import/extensions

describeChromeOnly('OOPIF', function () {
/* We use a special browser for this test as we need the --site-per-process flag */
Expand Down Expand Up @@ -386,6 +390,18 @@ describeChromeOnly('OOPIF', function () {
await target.page();
browser1.disconnect();
});
itFailsFirefox('should support lazy OOP frames', async () => {
const { server } = getTestState();

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

expect(page.frames().map((frame) => frame._hasStartedLoading)).toEqual([
true,
true,
false,
]);
});

describe('waitForFrame', () => {
it('should resolve immediately if the frame already exists', async () => {
Expand Down