Skip to content

Angular 16 @HostListener('window:beforeunload', ['$event']) is not working #52256

@oleh-kazban-gl

Description

@oleh-kazban-gl

Which @angular/* package(s) are the source of the bug?

Zone.js

Is this a regression?

No

Description

After migration from 15.2.10 to 16.2.* (tried 16.2.3 and 16.2.9) the working approach with showing the default browser preventing reload popup is not working any more.
image

Working minimalistic solution (Angular 15) https://stackblitz.com/edit/angular-15-starter-pack-iuvmnk
The same solution with Angular 16 (not working) https://stackblitz.com/edit/stackblitz-starters-qhmmsm

Step to reproduce

ER: the default browser preventing reload popup should appear
AR: the default browser preventing reload popup doesn't appear

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-qhmmsm

Please provide the exception or error you saw

The browser doesn't show the default preventing reload popup.

Please provide the environment you discovered this bug in (run ng version)

@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]

Chrome 118.0.5993.89 64-bit / Chrome 118.0.5993.71 64-bit / Chrome 117.0.5938.132 64-bit / Edge 117.0.2045.60 64-bit

Anything else?

As you can see from the component code if I click on the layout and change it to the changed state I shoud see the default browser popup asking "Reload the site?", but in Chrome 118.0.5993.89 64-bit / Chrome 118.0.5993.71 64-bit / Chrome 117.0.5938.132 64-bit / Edge 117.0.2045.60 64-bit it doesn't appear (meanwhile it works in Firefox 118.0.2 64-bit or 15.2.10 version), Win 10.
One more mention about the same problem here: #50935

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions