mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
fix (#386)
This commit is contained in:
parent
a3e3ff73bd
commit
b858ae3316
@ -19,7 +19,7 @@ import * as frames from '../frames';
|
||||
import { debugError, helper, RegisteredListener } from '../helper';
|
||||
import * as dom from '../dom';
|
||||
import * as network from '../network';
|
||||
import { WKTargetSession } from './wkConnection';
|
||||
import { WKTargetSession, WKTargetSessionEvents } from './wkConnection';
|
||||
import { Events } from '../events';
|
||||
import { WKExecutionContext, EVALUATION_SCRIPT_URL } from './wkExecutionContext';
|
||||
import { WKNetworkManager } from './wkNetworkManager';
|
||||
@ -133,7 +133,8 @@ export class WKPage implements PageDelegate {
|
||||
helper.addEventListener(this._session, 'Runtime.executionContextCreated', event => this._onExecutionContextCreated(event.context)),
|
||||
helper.addEventListener(this._session, 'Console.messageAdded', event => this._onConsoleMessage(event)),
|
||||
helper.addEventListener(this._session, 'Dialog.javascriptDialogOpening', event => this._onDialog(event)),
|
||||
helper.addEventListener(this._session, 'Page.fileChooserOpened', event => this._onFileChooserOpened(event))
|
||||
helper.addEventListener(this._session, 'Page.fileChooserOpened', event => this._onFileChooserOpened(event)),
|
||||
helper.addEventListener(this._session, WKTargetSessionEvents.Disconnected, event => this._page._didDisconnect()),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -64,29 +64,17 @@ export class WKTarget {
|
||||
// old target does not close the page on connection reset.
|
||||
oldTarget._pagePromise = null;
|
||||
oldTarget._wkPage = null;
|
||||
this._adoptPage();
|
||||
}
|
||||
|
||||
private _adoptPage() {
|
||||
this._session.once(WKTargetSessionEvents.Disconnected, () => {
|
||||
// Once swapped out, we reset _page and won't call _didDisconnect for old session.
|
||||
if (this._wkPage)
|
||||
this._wkPage._page._didDisconnect();
|
||||
});
|
||||
this._wkPage.setSession(this._session);
|
||||
}
|
||||
|
||||
async page(): Promise<Page> {
|
||||
if (!this._pagePromise) {
|
||||
this._wkPage = new WKPage(this._browser, this._browserContext);
|
||||
this._wkPage.setSession(this._session);
|
||||
// Reference local page variable as |this._frameManager| may be
|
||||
// cleared on swap.
|
||||
const page = this._wkPage._page;
|
||||
this._pagePromise = new Promise(async f => {
|
||||
this._adoptPage();
|
||||
await this._initializeSession(this._session);
|
||||
f(page);
|
||||
});
|
||||
this._pagePromise = this._initializeSession(this._session).then(() => page);
|
||||
}
|
||||
return this._pagePromise;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user