When we debug JavaScript, sometimes we cannot find how a page redirects to another page. Normally, it happens when we have lots of JavaScript involved in the web page. Many third-party JavaScripts also make it hard to find.

You can add a breakpoint of window.unload and window.beforeunload events in this case. Follow these steps to add a breakpoint:

  1. Open Chrome DevTools.
  2. Open the Sources tab.
  3. Expand Event Listener Breakpoints from the right panel.
  4. Expand the Load group from there.
  5. Check unload and/or beforeunload.

Now, try to replicate the issue, the debugger will block whenever those events will trigger.