Skip to content

Commit 3248749

Browse files
dgozmanyury-s
authored andcommitted
fix(webkit): make frames detect their initial load state (#690)
1 parent 19da86b commit 3248749

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"playwright": {
1111
"chromium_revision": "733125",
1212
"firefox_revision": "1018",
13-
"webkit_revision": "1113"
13+
"webkit_revision": "1119"
1414
},
1515
"scripts": {
1616
"unit": "node test/test.js",

src/webkit/wkPage.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,27 @@ export class WKPage implements PageDelegate {
235235
}
236236

237237
private _handleFrameTree(frameTree: Protocol.Page.FrameResourceTree) {
238-
this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
238+
const frame = this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
239239
this._onFrameNavigated(frameTree.frame, true);
240+
241+
frame._utilityContext().then(async context => {
242+
const readyState = await context.evaluate(() => document.readyState).catch(e => 'loading');
243+
if (frame.isDetached())
244+
return;
245+
if (readyState === 'interactive' || readyState === 'complete')
246+
this._page._frameManager.frameLifecycleEvent(frame._id, 'domcontentloaded');
247+
if (readyState === 'complete')
248+
this._page._frameManager.frameLifecycleEvent(frame._id, 'load');
249+
});
250+
240251
if (!frameTree.childFrames)
241252
return;
242-
243253
for (const child of frameTree.childFrames)
244254
this._handleFrameTree(child);
245255
}
246256

247-
_onFrameAttached(frameId: string, parentFrameId: string | null) {
248-
this._page._frameManager.frameAttached(frameId, parentFrameId);
257+
_onFrameAttached(frameId: string, parentFrameId: string | null): frames.Frame {
258+
return this._page._frameManager.frameAttached(frameId, parentFrameId);
249259
}
250260

251261
private _onFrameNavigated(framePayload: Protocol.Page.Frame, initial: boolean) {

test/navigation.spec.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,15 +759,21 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
759759
response.end('Not found');
760760
await navigationPromise;
761761
});
762-
it.skip(WEBKIT || FFOX)('should work with pages that have loaded before being connected to', async({page, context, server}) => {
762+
it.skip(FFOX)('should work with pages that have loaded before being connected to', async({page, context, server}) => {
763763
await page.goto(server.EMPTY_PAGE);
764764
await page.evaluate(async () => {
765765
const child = window.open(document.location.href);
766-
while(child.document.readyState !== 'complete' || child.document.location.href === 'about:blank')
767-
await new Promise(setTimeout);
766+
while (child.document.readyState !== 'complete' || child.document.location.href === 'about:blank')
767+
await new Promise(f => setTimeout(f, 100));
768768
});
769-
const [, childPage] = await context.pages();
770-
await childPage.waitForLoadState();
769+
const pages = await context.pages();
770+
expect(pages.length).toBe(2);
771+
expect(pages[0]).toBe(page);
772+
expect(pages[0].url()).toBe(server.EMPTY_PAGE);
773+
774+
expect(pages[1].url()).toBe(server.EMPTY_PAGE);
775+
await pages[1].waitForLoadState();
776+
expect(pages[1].url()).toBe(server.EMPTY_PAGE);
771777
});
772778
});
773779

0 commit comments

Comments
 (0)