cherry-pick(#33834): fix: do not stall waiting for pending navigations after beforeunload dismiss (#33856)
This commit is contained in:
parent
f92b2339fe
commit
9365eb5dac
|
|
@ -842,6 +842,9 @@ class FrameSession {
|
||||||
event.type,
|
event.type,
|
||||||
event.message,
|
event.message,
|
||||||
async (accept: boolean, promptText?: string) => {
|
async (accept: boolean, promptText?: string) => {
|
||||||
|
// TODO: this should actually be a CDP event that notifies about a cancelled navigation attempt.
|
||||||
|
if (this._isMainFrame() && event.type === 'beforeunload' && !accept)
|
||||||
|
this._page._frameManager.frameAbortedNavigation(this._page.mainFrame()._id, 'navigation cancelled by beforeunload dialog');
|
||||||
await this._client.send('Page.handleJavaScriptDialog', { accept, promptText });
|
await this._client.send('Page.handleJavaScriptDialog', { accept, promptText });
|
||||||
},
|
},
|
||||||
event.defaultPrompt));
|
event.defaultPrompt));
|
||||||
|
|
|
||||||
|
|
@ -612,6 +612,9 @@ export class WKPage implements PageDelegate {
|
||||||
event.type as dialog.DialogType,
|
event.type as dialog.DialogType,
|
||||||
event.message,
|
event.message,
|
||||||
async (accept: boolean, promptText?: string) => {
|
async (accept: boolean, promptText?: string) => {
|
||||||
|
// TODO: this should actually be a RDP event that notifies about a cancelled navigation attempt.
|
||||||
|
if (event.type === 'beforeunload' && !accept)
|
||||||
|
this._page._frameManager.frameAbortedNavigation(this._page.mainFrame()._id, 'navigation cancelled by beforeunload dialog');
|
||||||
await this._pageProxySession.send('Dialog.handleJavaScriptDialog', { accept, promptText });
|
await this._pageProxySession.send('Dialog.handleJavaScriptDialog', { accept, promptText });
|
||||||
},
|
},
|
||||||
event.defaultPrompt));
|
event.defaultPrompt));
|
||||||
|
|
|
||||||
|
|
@ -104,3 +104,25 @@ it('should not stall on evaluate when dismissing beforeunload', async ({ page, s
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not stall on click when dismissing beforeunload', async ({ page, server }) => {
|
||||||
|
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33806' });
|
||||||
|
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
await page.setContent(`<a href="${server.PREFIX}/frames/one-frame.html">click me</a>`);
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.onbeforeunload = () => false;
|
||||||
|
});
|
||||||
|
page.on('dialog', async dialog => {
|
||||||
|
await dialog.dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.getByRole('link').click({ noWaitAfter: true });
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.onbeforeunload = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// This line should not timeout.
|
||||||
|
await page.getByRole('link').click({ timeout: 5000 });
|
||||||
|
await expect(page).toHaveURL(server.PREFIX + '/frames/one-frame.html');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue