Skip to content

Commit

Permalink
fix(webkit): make frames detect their initial load state (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored and yury-s committed Jan 28, 2020
1 parent 19da86b commit 3248749
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
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 @@ -235,17 +235,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

0 comments on commit 3248749

Please sign in to comment.