How to Prevent or Pause Before a Redirect in JavaScript

Published Mar 23, 2021

I needed to read some logs on a button click, but the click also triggered a redirect.

One way I could have solved this was simply by preserving logs in the console.

Another way was to pause the redirect entirely.

I was able to add this event listener on beforeunload in the JavaScript console in order to pause before the redirect.

window.addEventListener("beforeunload", () => { debugger }, false);

On redirect, we enter the debugger. From there, we can view logs, network calls, etc.


More JS Articles