By default, dialogs are auto-dismissed by Playwright, so you don't have to handle them. However, you can register a dialog handler before the action that triggers the dialog to accept or decline it.
As a result, following snippet will never resolve:
:::warn WRONG! :::
If there is no listener for page.on('dialog'), all dialogs are automatically dismissed.
When page.close([options]) is invoked with the truthy
runBeforeUnload value, it page runs its unload handlers. This is the only case when page.close([options]) does not wait for the page to actually close, because it might be that the page stays open in the end of the operation.
You can register a dialog handler to handle the beforeunload dialog yourself: