Automatically reload page in Chrome without plugin

After 6 years I have a solution for this!

The answer is inspired by the other answers here.

Edub's answer didn't work for me, it reloaded the page over and over, and didn't observe setInterval's duration parameter. I don't understand why Edub's answer doesn't work as expected.

This works for me in Chrome 67:

javascript:document.getElementsByTagName("body")[0].innerHTML = "<iframe id=\"testFrame\" src=\""+window.location.toString()+"\" style=\"position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;\"><\/iframe>";reloadTimer = setInterval(function(){ document.getElementById("testFrame").src=document.getElementById("testFrame").src },10000)

Formatted version:

document.getElementsByTagName("body")[0].innerHTML = 
"<iframe id=\"testFrame\" 
        src=\"" + window.location.toString() + "\" 
      style=\"position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;\">
<\/iframe>";
reloadTimer = setInterval(
    function(){ 
        document.getElementById("testFrame").src=document.getElementById("testFrame").src
    },
    10000
)

This works by replacing the current document body with an iframe pointing to the window's current location.

Then a call to setInterval is made, that makes the page reload on a timer.

This works well as a bookmark. setInterval's complementary function can be called by bookmark too: javascript:clearTimer(reloadTimer)

Notes:

  • Some sites detect they are being accessed via iframe and attempt to prevent access (Stack sites for instance!)

  • Browsers strip the prefix javascript: when pasting into the address bar so it has to be entered manually. However javascript: is not stripped if entered via bookmark.


You could do it through the Chrome Developer Tools using key combination ctrl+shift+j. Load the page you want, say for example: http://www.w3schools.com/jsref/dom_obj_frame.asp then hit ctrl+shift+j to open the developer tools. Right click on the body tag and select edit as html replace the inner contents (leaving the tag and closing tags intact) with the following:

<iframe id="testFrame" src="http://www.w3schools.com/jsref/dom_obj_frame.asp" style="position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;" onload="setInterval(document.getElementById('testFrame').contentWindow.location.reload(), 10000);"></iframe>

to stop editing as html you can either hit esc or click on one of the tags outside of the one you're editing. The page should start reloading every 10 seconds, you can close the developers tools if you'd like and it will continue to refresh, no plugin needed :)


Taking the solution from Justin Buser one step further lead me to:

document.getElementsByTagName("body")[0].innerHTML = "<iframe id=\"testFrame\" src=\""+window.location.toString()+"\" style=\"position: absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%;\" onload=\"setInterval(document.getElementById(\'testFrame\').contentWindow.location.reload(), 10000);\"><\/iframe>"

The idea to embed the site in an iframe to be able to reload it works fine (i guess). I just wrote some code to get the body elment and replace the innerhtml with an Iframe to the current url.

This way it is possible to bookmark some JavaScript code and fire it at any site to reload it. Hope it helps.