2

There is a web site with this snippet in every page:

var refreshSite; 
refreshSiteInterval();
function refreshSiteInterval() {
  refreshSite = setInterval(
    function() { document.location = document.location; }, 
    420000);
};
function stopRefreshSite() {
  clearInterval(refreshSite);
}

Calling stopRefreshSite() from javascript console stops the timed refresh from occurring.

I'd like to disable this recurring refresh with a chrome extension. I thought that a content script which calls stopRefreshSite() whenever the page loads makes sense, though because content scripts execute in an isolated world this doesn't seem to be possible.

Is there any way to call the webpage function? Or would trying to prevent the original javascript from running in the first place be a better strategy?

0

1 Answer 1

4

To execute script on the page, you have to insert a script element into it, which is easily done and covered in this answer: Building a Chrome Extension - Inject code in a page using a Content script.

In your case:

var script = document.createElement('script');
script.textContent = "stopRefreshSite()";
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);
Sign up to request clarification or add additional context in comments.

6 Comments

...although I can't immediately see any reason for preferring document.head over just using document.documentElement.
I've added the script with "run_at": "document_end" and while the script is definitely running, I can't find the injected script element. I'm starting to debug...
@DavidResnick: Note the last line of the above. :-) We're removing it after adding it, since it's adding it that runs the code it contains. You could take that line out if you like.
Yeah, I scratched my head looking at that... ;) Thanks a lot for your help!
@Legends: On modern browsers today, yeah. Not on (say) IE11. I'm not even sure what support was like in 2015.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.