fix(webkit): make frames detect their initial load state (#690)

This commit is contained in:
Dmitry Gozman 2020-01-28 13:05:38 -08:00 committed by Yury Semikhatsky
parent 19da86b4c9
commit 324874962c
3 changed files with 26 additions and 10 deletions

View File

@ -10,7 +10,7 @@
"playwright": {
"chromium_revision": "733125",
"firefox_revision": "1018",
"webkit_revision": "1113"
"webkit_revision": "1119"
},
"scripts": {
"unit": "node test/test.js",

View File

@ -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) {

View File

@ -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);
});
});