Is there a way to keep running Javascript console's instructions after page reloads?

Joined
Jun 19, 2014
Messages
4
Reaction score
0
Hi everyone. I'm new to this, so sorry if this question could seem trivial.
Let's suppose using browser console to run this loop on a random tab:
Code:
var i = 1;
function myLoop () {           
   setTimeout(function () {    
      location.reload()      
      i++;                     
      if (i < 10) {            
         myLoop();             
      }                        
   }, 3000)
}


myLoop();
After first reload, console instructions get nulled, and the loop can't continue. This should be normal.
Now, as title says, I was just wondering if there is a way to execute externally a script by console, and keep it running when page changes - maybe after a form is filled and submitted. I have taken a look for this on Stackoverflow, and it doesn't seem possible; one interesting solution I have found was about including an iframe into a local file, but it isn't clean and could be inapplicable, as long as many sites deny being loaded in iframes.

Maybe it's just my approach to be wrong, and I'd like to have a confirmation.
Thank you in advance
 
1. Add breakpoint
2. Reload page
3. Insert code
4. Resume

Above steps are meant for debugging. If you want to use the console for
automation purposes, then they won't work.
 
Thank you guys, then it was my approach to the console to be wrong.
At the end I decided to create a Chrome extension and it seems to work efficiently.

Starting with this assumption, those who would be interested in doing that specific loop have to check manifest's permissions and also replace location.reload() with chrome.tabs.reload() in this way:
Code:
var i = 1;                     


function myLoop () {           
   setTimeout(function () {    
      chrome.tabs.reload()
      i++;                     
      if (i < 10) {            
         myLoop();             
      }                        
   }, 3000)
}


myLoop();
 
Back
Top