33

I have a problem when I am trying to check the source of an interesting page which keeps refreshing automatically every 3-5 seconds (presumably due to some js script) which resets my Inspect Element Inspector window every time the page is refreshed.

Is there any other way other to stop that page from refreshing or perhaps the Inspector window from resetting itself other than turning on NoScript to stop the page from refreshing automatically?

Clone
  • 3,378
  • 11
  • 25
  • 41
  • Would [this](https://stackoverflow.com/questions/3527041/prevent-any-form-of-page-refresh-using-jquery-javascript) help? Not sure if you can actually prevent a software-triggerred refresh this way. I've tried patching `location.reload` but I guess that won't work if it's stored in the closure. – Bartek Banachewicz Apr 19 '17 at 06:10
  • 3
    Did you use debugger; and then start debugging your code. – fruitjs Apr 19 '17 at 06:14
  • You could try saving the web page files locally and go hunting for the offending js offline, circumvent it, then inspecting away. Bit crude but might work? – ne1410s Apr 19 '17 at 06:15
  • 1
    @BartekBanachewicz , I edited the question a bit to specify that I use Firefox. thnak you for your inputs! – Clone Apr 19 '17 at 07:16
  • 1
    @fruitjs, should I just type `debugger;` in the console? – Clone Apr 19 '17 at 07:18
  • in your code write debugger keyword and open your dev tool and refresh your page. if you dont open dev tool then the debugger will be suppress, use F10 to proceed. function abc(){ console.log("Before debugger"); debugger; //debugging will start } – fruitjs Apr 19 '17 at 09:48
  • You say "other than *turning on* noscript". That implies you've already got it installed, in which case it's an easy and reliable solution. – Chris H Apr 19 '17 at 16:09
  • When everything else fails, there is [fiddler](http://www.telerik.com/fiddler). – Theraot Apr 19 '17 at 16:53
  • Did the answers on [this](http://stackoverflow.com/q/821011/87015) or [this](http://stackoverflow.com/q/18273767/87015) work? I dont see why this was reopened. We seriously don't need a separate thread for each browser in the world. – Salman A Apr 20 '17 at 04:47
  • I can only hope this is a bug on the page and not intentional. Not only it's very disrespectful of the user's potentially limited and expensive bandwidth, but such shenanigans make the web page 100% unreadable to screen reader users. – Euro Micelli Apr 20 '17 at 17:10

5 Answers5

32

Usually I just open DevTools, switch to the appropriate panel if necessary, and hit pause.

Opening DevTools: Via menus, or by press F12, Ctrl+Shift+I, or Cmd+Shift+I depending on browser and OS.

Switching panels: Pick the panel from the tabs at the top of DevTools. It'll be called "Debugger" (Firefox, IE) or "Sources" (Chrome) or similar.

Pausing: In the Debugger/Sources panel, click the pause button (usually looks like the pause button on a television remote control, ||) or press the keyboard equivalent. Keyboard equivalents are

  • Firefox & Chrome: F8
  • IE: Ctrl+Shift+B
Mouneer
  • 12,827
  • 2
  • 35
  • 45
Loïc Lopes
  • 544
  • 8
  • 19
  • 3
    Brilliant. Simple. Easy. Works for me in Chrome, Firefox, IE11. – T.J. Crowder Apr 19 '17 at 13:20
  • There's a checkbox for ```Load``` under ```Event Listener Breakpoints``` which will pause on the load event. Worked great so I don't have to try to time hitting pause just right. – Stack Underflow Jan 29 '21 at 21:40
21

(Updated 2020-03-30)

In Firefox 74 this option is in Options -> Privacy & Security -> Permissions enter image description here

(Original reply)

Firefox has the option to prevent refresh natively, the option is in Advanced->General->Warn me when websites try to redirect or reload the pageenter image description here

berserck
  • 499
  • 4
  • 19
  • Interesting setting. Didn't remember I had that option in Firefox. Thank you for your answer! – Clone Apr 19 '17 at 07:15
  • @T.J.Crowder, could you please post the code you wrote before you removed it? I didn't get the chance to save it :,( – Clone Apr 20 '17 at 00:41
  • 1
    @Clone: It was really just `debugger;`, but if you want the long version, it was https://pastebin.com/yrZhAHd2. You shouldn't need that, though; [Louhike's approach](http://stackoverflow.com/a/43495344/157247) is simpler and works just as well (which is why I removed my answer). – T.J. Crowder Apr 20 '17 at 02:41
  • @T.J.Crowder Thank you! – Clone Apr 20 '17 at 03:20
8

The most popular solution for this problem is to trap the beforeunload event. The browser will ask the user for confirmation to leave the page. The code, in its simplest form, looks like this:

window.onbeforeunload = function() { return true }

You can enter this code in console. Alternately, you can simply paste the following URL in the browser address bar (console not required). You can even bookmark it.

javascript:window.onbeforeunload = function() { return true }

Be advised that modern browsers might chop off the javascript: part when you paste it inside the address bar; make sure you type it back.


To determine the cause of redirect in Firefox, try the following:

  • Open Web Developer Tools (CTRL + SHIFT + I), open "Toolbox Options" and check the "Enable persistent logs" option. This makes the logs persist across page loads (logs are cleared otherwise).

  • Now switch to "Network Monitor" tab.

  • Open the URL and let it refresh.

  • Inside the Network Monitor > Cause column you will find out why the page reloads.

Firefox Web Developer Tools > Network Monitor

The cause column is pretty ambiguous (Chrome does a much better job). However, if JavaScript was used to trigger page (re)load then it at least shows you the filename and line number of that script.

Salman A
  • 262,204
  • 82
  • 430
  • 521
  • The `onbeforeunload` trick will only work if the page refresh isn't on a loop within the page. E.g., it would stop this: `setTimeout(function() { location.reload(); }, 1000);` but not this: `setInterval(function() { location.reload(); }, 1000);` In the second case, it will just keep asking you to cancel over and over. :-) (Good idea, though.) – T.J. Crowder Apr 19 '17 at 20:32
  • thanks, I had to google this for a while until I found this nice solution. – Bri4n Sep 28 '22 at 01:44
1

When the page is still loading, you can press the Esc key. While the page is still white, press it. When you stop the page from loading at this point, this usually stops all the auto loaded javascript. Any scripts that run on actions are usually not effected. Each page is different, try different timings.

When I use a site called NovelUpdates there is javascript that can make certain elements hidden, and when I press Esc on page load all the elements that would be hidden after page load are visible. Then when I click a button that would execute javascript that operates with no problems. NoScript isn't going to solve your issue I believe.

Another example of this are those websites with annoying boxes that pop out after 10 seconds that says you aren't a member and can't view any more of this site without logging in, like some news article websites.

skaviouz
  • 45
  • 7
0

What you could do is use the command exit(), which is the equivalent to die in php and simply stops the script. If you don't know what's causing it and you don't want to look for the "bad boy", then you might as well stop the entire script at the very bottom of the page.

Xaphas
  • 501
  • 4
  • 20