mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore(webkit): stop using windowOpen signal to determine initial empty page (#1776)
This commit is contained in:
parent
c2fc4035ba
commit
2e6f544342
@ -37,8 +37,6 @@ export class WKBrowser extends BrowserBase {
|
|||||||
readonly _contexts = new Map<string, WKBrowserContext>();
|
readonly _contexts = new Map<string, WKBrowserContext>();
|
||||||
readonly _wkPages = new Map<string, WKPage>();
|
readonly _wkPages = new Map<string, WKPage>();
|
||||||
private readonly _eventListeners: RegisteredListener[];
|
private readonly _eventListeners: RegisteredListener[];
|
||||||
private _popupOpeners: string[] = [];
|
|
||||||
private _closeOverride?: () => Promise<void>;
|
|
||||||
|
|
||||||
private _firstPageCallback: () => void = () => {};
|
private _firstPageCallback: () => void = () => {};
|
||||||
private readonly _firstPagePromise: Promise<void>;
|
private readonly _firstPagePromise: Promise<void>;
|
||||||
@ -60,7 +58,6 @@ export class WKBrowser extends BrowserBase {
|
|||||||
helper.addEventListener(this._browserSession, 'Playwright.pageProxyCreated', this._onPageProxyCreated.bind(this)),
|
helper.addEventListener(this._browserSession, 'Playwright.pageProxyCreated', this._onPageProxyCreated.bind(this)),
|
||||||
helper.addEventListener(this._browserSession, 'Playwright.pageProxyDestroyed', this._onPageProxyDestroyed.bind(this)),
|
helper.addEventListener(this._browserSession, 'Playwright.pageProxyDestroyed', this._onPageProxyDestroyed.bind(this)),
|
||||||
helper.addEventListener(this._browserSession, 'Playwright.provisionalLoadFailed', event => this._onProvisionalLoadFailed(event)),
|
helper.addEventListener(this._browserSession, 'Playwright.provisionalLoadFailed', event => this._onProvisionalLoadFailed(event)),
|
||||||
helper.addEventListener(this._browserSession, 'Playwright.windowOpen', this._onWindowOpen.bind(this)),
|
|
||||||
helper.addEventListener(this._browserSession, 'Playwright.downloadCreated', this._onDownloadCreated.bind(this)),
|
helper.addEventListener(this._browserSession, 'Playwright.downloadCreated', this._onDownloadCreated.bind(this)),
|
||||||
helper.addEventListener(this._browserSession, 'Playwright.downloadFinished', this._onDownloadFinished.bind(this)),
|
helper.addEventListener(this._browserSession, 'Playwright.downloadFinished', this._onDownloadFinished.bind(this)),
|
||||||
helper.addEventListener(this._browserSession, kPageProxyMessageReceived, this._onPageProxyMessageReceived.bind(this)),
|
helper.addEventListener(this._browserSession, kPageProxyMessageReceived, this._onPageProxyMessageReceived.bind(this)),
|
||||||
@ -98,10 +95,6 @@ export class WKBrowser extends BrowserBase {
|
|||||||
return this._firstPagePromise;
|
return this._firstPagePromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onWindowOpen(payload: Protocol.Playwright.windowOpenPayload) {
|
|
||||||
this._popupOpeners.push(payload.pageProxyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
_onDownloadCreated(payload: Protocol.Playwright.downloadCreatedPayload) {
|
_onDownloadCreated(payload: Protocol.Playwright.downloadCreatedPayload) {
|
||||||
const page = this._wkPages.get(payload.pageProxyId);
|
const page = this._wkPages.get(payload.pageProxyId);
|
||||||
if (!page)
|
if (!page)
|
||||||
@ -132,18 +125,7 @@ export class WKBrowser extends BrowserBase {
|
|||||||
this._connection.rawSend({ ...message, pageProxyId });
|
this._connection.rawSend({ ...message, pageProxyId });
|
||||||
});
|
});
|
||||||
const opener = pageProxyInfo.openerId ? this._wkPages.get(pageProxyInfo.openerId) : undefined;
|
const opener = pageProxyInfo.openerId ? this._wkPages.get(pageProxyInfo.openerId) : undefined;
|
||||||
let hasInitialAboutBlank = false;
|
const wkPage = new WKPage(context, pageProxySession, opener || null);
|
||||||
if (pageProxyInfo.openerId) {
|
|
||||||
const openerIndex = this._popupOpeners.indexOf(pageProxyInfo.openerId);
|
|
||||||
if (openerIndex !== -1) {
|
|
||||||
this._popupOpeners.splice(openerIndex, 1);
|
|
||||||
// When this page is a result of window.open($url) call, we should have it's opener
|
|
||||||
// in the list of popup openers. In this case we know there is an initial
|
|
||||||
// about:blank navigation, followed by a navigation to $url.
|
|
||||||
hasInitialAboutBlank = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const wkPage = new WKPage(context, pageProxySession, opener || null, hasInitialAboutBlank);
|
|
||||||
this._wkPages.set(pageProxyId, wkPage);
|
this._wkPages.set(pageProxyId, wkPage);
|
||||||
|
|
||||||
wkPage.pageOrError().then(async () => {
|
wkPage.pageOrError().then(async () => {
|
||||||
|
@ -59,14 +59,12 @@ export class WKPage implements PageDelegate {
|
|||||||
private readonly _evaluateOnNewDocumentSources: string[] = [];
|
private readonly _evaluateOnNewDocumentSources: string[] = [];
|
||||||
readonly _browserContext: WKBrowserContext;
|
readonly _browserContext: WKBrowserContext;
|
||||||
private _initialized = false;
|
private _initialized = false;
|
||||||
private _hasInitialAboutBlank: boolean;
|
|
||||||
private _firstNonInitialNavigationCommittedPromise: Promise<void>;
|
private _firstNonInitialNavigationCommittedPromise: Promise<void>;
|
||||||
private _firstNonInitialNavigationCommittedCallback = () => {};
|
private _firstNonInitialNavigationCommittedCallback = () => {};
|
||||||
|
|
||||||
constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPage | null, hasInitialAboutBlank: boolean) {
|
constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPage | null) {
|
||||||
this._pageProxySession = pageProxySession;
|
this._pageProxySession = pageProxySession;
|
||||||
this._opener = opener;
|
this._opener = opener;
|
||||||
this._hasInitialAboutBlank = hasInitialAboutBlank;
|
|
||||||
this.rawKeyboard = new RawKeyboardImpl(pageProxySession);
|
this.rawKeyboard = new RawKeyboardImpl(pageProxySession);
|
||||||
this.rawMouse = new RawMouseImpl(pageProxySession);
|
this.rawMouse = new RawMouseImpl(pageProxySession);
|
||||||
this._contextIdToContext = new Map();
|
this._contextIdToContext = new Map();
|
||||||
@ -262,8 +260,12 @@ export class WKPage implements PageDelegate {
|
|||||||
}
|
}
|
||||||
if (targetInfo.isPaused)
|
if (targetInfo.isPaused)
|
||||||
this._pageProxySession.send('Target.resume', { targetId: targetInfo.targetId }).catch(debugError);
|
this._pageProxySession.send('Target.resume', { targetId: targetInfo.targetId }).catch(debugError);
|
||||||
if (this._hasInitialAboutBlank)
|
if (this._page.mainFrame().url() === '') {
|
||||||
|
// Initial empty page has an empty url. We should wait until the first real url has been loaded,
|
||||||
|
// even if that url is about:blank. This is especially important for popups, where we need the
|
||||||
|
// actual url before interacting with it.
|
||||||
await this._firstNonInitialNavigationCommittedPromise;
|
await this._firstNonInitialNavigationCommittedPromise;
|
||||||
|
}
|
||||||
this._initialized = true;
|
this._initialized = true;
|
||||||
this._pagePromiseCallback(pageOrError);
|
this._pagePromiseCallback(pageOrError);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user