Refresh a page automatically from the Browser console

You can refresh a page from within the browser console by running the following command:

location.reload()

If the website you are on has jQuery loaded you will be able to run jQuery commands.

If the website does not have jQuery loaded you can use the following bookmark to inject jQuery into the page:

javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){(function(){var d=document.createElement("div"),c=document.getElementsByTagName("body")[0],e=false,g="";d.style.position="fixed";d.style.height="32px";d.style.width="220px";d.style.marginLeft="-110px";d.style.top="0";d.style.left="50%";d.style.padding="5px 10px";d.style.zIndex=1001;d.style.fontSize="12px";d.style.color="#222";d.style.backgroundColor="#f99";if(typeof jQuery!="undefined"){g="This page already using jQuery v"+jQuery.fn.jquery;return f()}else{if(typeof $=="function"){e=true}}function a(i,k){var h=document.createElement("script");h.src=i;var j=document.getElementsByTagName("head")[0],b=false;h.onload=h.onreadystatechange=function(){if(!b&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){b=true;k();h.onload=h.onreadystatechange=null;j.removeChild(h)}};j.appendChild(h)}a("http://code.jquery.com/jquery.min.js",function(){if(typeof jQuery=="undefined"){g="Sorry, but jQuery wasn't able to load"}else{g="This page is now jQuerified with v"+jQuery.fn.jquery;if(e){g+=" and noConflict(). Use $jq(), not $()."}}return f()});function f(){d.innerHTML=g;c.appendChild(d);window.setTimeout(function(){if(typeof jQuery=="undefined"){c.removeChild(d)}else{jQuery(d).fadeOut("slow",function(){jQuery(this).remove()});if(e){$jq=jQuery.noConflict()}}},2500)}})();});

You can use like

   document.location.reload()

Use a browser tab "A" to open and control another browser tab "B". This allows you to continuously auto-reload a Web page in tab "B" that otherwise you have no control over. Your reload command from tab "A" will not be wiped out when tab "B" is reloaded.

I use this to refresh a Website so that it does not time out and log me out. This approach does not require jQuery, and does not require you to have any control over the target Web page HTML code.

Open a browser new tab "A", press F12, select Console. Type in something like this:

win1 = window.open("https://www.example.com");

timer1 = setInterval(function(){win1.location.href="https://www.example.com"},10*60*1000);

The "win1" is to assign a Javascript variable name to the new browser tab "B", so that you can have Javascript control over it. The "timer1" is also to assign a variable name for good practice and for later control. The setInterVal function runs an anonymous function to call "win1" or tab "B" to refresh it's "location.href", every 10 minutes.

You'll probably have to keep both tabs open. "Pin" them for easy access. Close both tabs to stop the auto-reload. Hard refresh of tab "A" may also stop the auto reload. You might also be able to use the variable "timer1" to cancel the auto reload.


If you want to use the console just type document.location.reload() in the console. But if you want to make it automatically - it needs to be in your code.

And yes, the console will take jquery if you have included the library in your code.

One more thing: for automatic refresh you need something like

setInterval(function(){ document.location.reload() },10*60*1000); But it not gonna work in the console, because after the first refresh this code won't be in the console anymore. Just place it in your code.