feat(Page): add option to run 'beforeunload' when closing the page (#2478)

Today, `page.close()` method doesn't run page's beforeunload listeners.
This way users can be sure that `page.close()` actually closes the
page.

This patch adds an optional `runBeforeUnload` option to the
`page.close()` method that would run beforeunload listeners. Note:
running beforeunload handlers might cancel page closing.

Fixes #2386.
This commit is contained in:
Andrey Lushnikov
2018-05-03 01:51:45 +03:00
committed by GitHub
parent 376018854b
commit a310d57d84
4 changed files with 41 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
<script>
window.addEventListener('beforeunload', event => {
event.returnValue = 'Leave?';
});
</script>