title: pagehide and/or beforeunload not firing in IOS Chrome, Safari
body: <p><strong>I'm trying to prompt the user whenever he/she tries to navigate away from the current browser (refresh, close tab and window, clicking back button from the browser)</strong>. I'm having this issue on <strong>IOS mobile that it does not fire pagehide and/or beforeunload</strong>.</p>
  
  <p>I'm aware that Safari does not support beforeunload event anymore so I've added an event listener for pagehide with similar logic, and that too does not fire. Code is written in angular.</p>
  
  <p>Approach tried:</p>
  
  <pre><code>// Method decorator, Did not work for both
  @Hostlistner(window:pagehide), @Hostlistner(window:beforeunload)
  
  doSomething(event:any){
   event.returnValue = true;
   return true;
  }
  
  // Component host property, Also tried this on beforeunload, did not work for both
  @Component({
  ...
  host: "(window:pagehide)" : "doSomething($event)"
  })
  
  // Plain javascript, have tried pagehide too, did not work for both
  window.onbeforeunload = (event) =&gt; {
    event.returnValue = true;
    return true;
  };
  
  //Also tried binding it via addEventListener method of window/document, did not work for both
  window.addEventListener('beforeunload',  (event) =&gt; {
    this.log("before unload");
    event.returnValue = true;
    return true;
  });
  </code></pre>
  
  <p>I have been trying it via stackblitz: <a href="https://stackblitz.com/edit/angular-qkezha?file=src%2Fapp%2Fapp.component.ts" rel="noreferrer">https://stackblitz.com/edit/angular-qkezha?file=src%2Fapp%2Fapp.component.ts</a>.</p>
  
  <p><strong>Device use for testing the issue: IPhone 6, IOS 12.1</strong></p>
  
  <p><strong>Issue arise on Mobile IOS both for Chrome and Safari</strong>, have not tested it in yet in Firefox but I doubt that it will work on there too. Code works on Android Chrome and Windows Desktop Chrome.</p>
  
  <p>I've been on this for several days now. Searching here and there. Any help or hints is very much appreciated. </p>