How to prevent URL redirects in Chrome?

Solution 1:

I realize this is far from a perfect answer, as this will only work for responses that serve up content, but I decided to post it as there are currently zero useful, actionable answers.

As a quick-and-dirty solution you may be able to use the debugger (accessible by F12 or CTRL+SHIFT+I in most browsers) to give your self an opportunity to opt out of a redirect.

Run this line in the console before the page runs any scripts of its own:

window.onbeforeunload = function(){ return 'Leave page?'; };

For example, using Chrome:

  • Open the debugger (F12) and switch to the Sources tab.
  • Press F8 to put the debugger into step-through mode.
  • Navigate to the problematic page. It will begin to load but the debugger won't allow scripts to run.
  • Paste the above code into the console and hit enter.
  • Press F8 again to allow scripts to run and let the page finish loading.
  • Now you will see a prompt before any redirect occurs and you'll have an opportunity to cancel it.
  • If the page repeatedly tries to redirect you, you can tell chrome not to display the dialog again. Further attempts by the page to navigate you elsewhere will fail silently.

Prompt restores user control