feat(firefox): support running beforeunload hooks when closing (#4003)
This commit is contained in:
parent
e3b76b2beb
commit
0b40d04b99
@ -549,8 +549,11 @@ class Page extends EventEmitter {
|
||||
return await this._frameManager.mainFrame().select(selector, ...values);
|
||||
}
|
||||
|
||||
async close() {
|
||||
await this._session.send('Browser.closePage' );
|
||||
async close(options = {}) {
|
||||
const {
|
||||
runBeforeUnload = false,
|
||||
} = options;
|
||||
await this._session.send('Browser.closePage', { runBeforeUnload });
|
||||
}
|
||||
|
||||
async content() {
|
||||
|
@ -104,7 +104,7 @@ pref("datareporting.policy.dataSubmissionPolicyAccepted", false);
|
||||
pref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
|
||||
|
||||
// Automatically unload beforeunload alerts
|
||||
pref("dom.disable_beforeunload", true);
|
||||
pref("dom.disable_beforeunload", false);
|
||||
|
||||
// Disable popup-blocker
|
||||
pref("dom.disable_open_during_load", false);
|
||||
|
@ -9,7 +9,7 @@
|
||||
"node": ">=8.9.4"
|
||||
},
|
||||
"puppeteer": {
|
||||
"firefox_revision": "0647e24cc0b90c07c8ddb32e63ce333839329527"
|
||||
"firefox_revision": "4ba5b441257d5938d032d09fc09e45ea9d8f2e3a"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node install.js",
|
||||
|
@ -1,5 +1,10 @@
|
||||
<div>beforeunload demo.</div>
|
||||
<script>
|
||||
window.addEventListener('beforeunload', event => {
|
||||
// Chrome way.
|
||||
event.returnValue = 'Leave?';
|
||||
// Firefox way.
|
||||
event.preventDefault();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -48,19 +48,30 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device
|
||||
await newPage.close();
|
||||
expect(await browser.pages()).not.toContain(newPage);
|
||||
});
|
||||
it_fails_ffox('should run beforeunload if asked for', async({context, server}) => {
|
||||
it('should run beforeunload if asked for', async({context, server}) => {
|
||||
const newPage = await context.newPage();
|
||||
await newPage.goto(server.PREFIX + '/beforeunload.html');
|
||||
// We have to interact with a page so that 'beforeunload' handlers
|
||||
// fire.
|
||||
await newPage.click('body');
|
||||
newPage.close({ runBeforeUnload: true });
|
||||
const pageClosingPromise = newPage.close({ runBeforeUnload: true });
|
||||
const dialog = await waitEvent(newPage, 'dialog');
|
||||
expect(dialog.type()).toBe('beforeunload');
|
||||
expect(dialog.defaultValue()).toBe('');
|
||||
expect(dialog.message()).toBe('');
|
||||
dialog.accept();
|
||||
await waitEvent(newPage, 'close');
|
||||
if (CHROME)
|
||||
expect(dialog.message()).toBe('');
|
||||
else
|
||||
expect(dialog.message()).toBe('This page is asking you to confirm that you want to leave - data you have entered may not be saved.');
|
||||
await dialog.accept();
|
||||
await pageClosingPromise;
|
||||
});
|
||||
it('should *not* run beforeunload by default', async({context, server}) => {
|
||||
const newPage = await context.newPage();
|
||||
await newPage.goto(server.PREFIX + '/beforeunload.html');
|
||||
// We have to interact with a page so that 'beforeunload' handlers
|
||||
// fire.
|
||||
await newPage.click('body');
|
||||
await newPage.close();
|
||||
});
|
||||
it('should set the page close state', async({context}) => {
|
||||
const newPage = await context.newPage();
|
||||
|
Loading…
Reference in New Issue
Block a user