onBeforeUnload doesn't call methods, browser closes too fast?
问题 I'm trying to call a method in the beforeunload event handler. It seems like the browser is closing too fast. Here is my code: @HostListener('window:beforeunload', ['$event']) onBeforeUnload(): boolean { let logout: any; logout = logout(); while (logout = false) { console.log("session not ended") } return true; } public async logout(): Promise<boolean> { this.userSessionService.EndSession(this.userSessionId); this.oauthService.logOut(false); return true; } What I want to happen is when a user