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(webkit): make frames detect their initial load state #690

Merged
merged 2 commits into from
Jan 28, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"playwright": {
"chromium_revision": "733125",
"firefox_revision": "1018",
"webkit_revision": "1113"
"webkit_revision": "1119"
},
"scripts": {
"unit": "node test/test.js",
Expand Down
18 changes: 14 additions & 4 deletions src/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,27 @@ export class WKPage implements PageDelegate {
}

private _handleFrameTree(frameTree: Protocol.Page.FrameResourceTree) {
this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
const frame = this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
this._onFrameNavigated(frameTree.frame, true);

frame._utilityContext().then(async context => {
const readyState = await context.evaluate(() => document.readyState).catch(e => 'loading');
if (frame.isDetached())
return;
if (readyState === 'interactive' || readyState === 'complete')
this._page._frameManager.frameLifecycleEvent(frame._id, 'domcontentloaded');
if (readyState === 'complete')
this._page._frameManager.frameLifecycleEvent(frame._id, 'load');
});

if (!frameTree.childFrames)
return;

for (const child of frameTree.childFrames)
this._handleFrameTree(child);
}

_onFrameAttached(frameId: string, parentFrameId: string | null) {
this._page._frameManager.frameAttached(frameId, parentFrameId);
_onFrameAttached(frameId: string, parentFrameId: string | null): frames.Frame {
return this._page._frameManager.frameAttached(frameId, parentFrameId);
}

private _onFrameNavigated(framePayload: Protocol.Page.Frame, initial: boolean) {
Expand Down
16 changes: 11 additions & 5 deletions test/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,15 +759,21 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
response.end('Not found');
await navigationPromise;
});
it.skip(WEBKIT || FFOX)('should work with pages that have loaded before being connected to', async({page, context, server}) => {
it.skip(FFOX)('should work with pages that have loaded before being connected to', async({page, context, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.evaluate(async () => {
const child = window.open(document.location.href);
while(child.document.readyState !== 'complete' || child.document.location.href === 'about:blank')
await new Promise(setTimeout);
while (child.document.readyState !== 'complete' || child.document.location.href === 'about:blank')
await new Promise(f => setTimeout(f, 100));
});
const [, childPage] = await context.pages();
await childPage.waitForLoadState();
const pages = await context.pages();
expect(pages.length).toBe(2);
expect(pages[0]).toBe(page);
expect(pages[0].url()).toBe(server.EMPTY_PAGE);

expect(pages[1].url()).toBe(server.EMPTY_PAGE);
await pages[1].waitForLoadState();
expect(pages[1].url()).toBe(server.EMPTY_PAGE);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
});
it.skip(WEBKIT || FFOX)('should not treat navigations as new popups', async({page, server}) => {
it.skip(FFOX)('should not treat navigations as new popups', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
Expand Down