Skip to content

Commit

Permalink
fix(webkit): unflake Page.setContent (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Jan 31, 2020
1 parent 2bf88fd commit c57fd22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
22 changes: 5 additions & 17 deletions src/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export class WKPage implements PageDelegate {
this._workers.setSession(session);
}

async initialize(session: WKSession, pagePausedOnStart: boolean) {
async initialize(session: WKSession) {
this._setSession(session);
await Promise.all([
this._initializePageProxySession(),
this._initializeSession(this._session, ({frameTree}) => this._handleFrameTree(frameTree, pagePausedOnStart)),
this._initializeSession(this._session, ({frameTree}) => this._handleFrameTree(frameTree)),
]);
}

Expand Down Expand Up @@ -240,26 +240,14 @@ export class WKPage implements PageDelegate {
this._page._frameManager.frameLifecycleEvent(frameId, event);
}

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

if (!pagePausedOnStart) {
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, pagePausedOnStart);
this._handleFrameTree(child);
}

_onFrameAttached(frameId: string, parentFrameId: string | null): frames.Frame {
Expand Down
8 changes: 3 additions & 5 deletions src/webkit/wkPageProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ export class WKPageProxy {
}

onPopupCreated(popupPageProxy: WKPageProxy) {
const wkPage = this._wkPage;
if (!wkPage || !wkPage._page.listenerCount(Events.Page.Popup))
return;
popupPageProxy.page().then(page => wkPage._page.emit(Events.Page.Popup, page));
if (this._wkPage)
popupPageProxy.page().then(page => this._wkPage!._page.emit(Events.Page.Popup, page));
}

private async _initializeWKPage(): Promise<Page> {
Expand All @@ -114,7 +112,7 @@ export class WKPageProxy {
}
assert(session, 'One non-provisional target session must exist');
this._wkPage = new WKPage(this._browserContext, this._pageProxySession);
await this._wkPage.initialize(session!, this._pagePausedOnStart);
await this._wkPage.initialize(session!);
if (this._pagePausedOnStart) {
this._resumeTarget(session!.sessionId);
this._pagePausedOnStart = false;
Expand Down

0 comments on commit c57fd22

Please sign in to comment.