stopping just timed or looping scripts

Ask for help about NoScript, no registration needed to post
njem
Posts: 6
Joined: Sat May 28, 2011 5:40 am

stopping just timed or looping scripts

Post by njem »

I need to allow scripts to run so pages display right and things respond when you click on them, but I would like to kill scripts that run on a timer or loop. I tried this:
Scripts enabled, load page so it loads right.
Disable scripts to stop those that keep running.
Turn scripts back on so scripted buttons and such will work.

But when I did that apparently some timed/looping scripts kicked back in.

I keep a lot of articles and research papers open at a time and all the scripts that run eat a lot of cpu time and memory. But as noted you gotta have scripts for layout and buttons and such running or things just don't work. Any suggestions?

Thanks
Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
User avatar
therube
Ambassador
Posts: 7969
Joined: Thu Mar 19, 2009 4:17 pm
Location: Maryland USA

Re: stopping just timed or looping scripts

Post by therube »

I do that with Bank of America.

I log in, open multiple accounts in individual tabs, all with JavaScript blocked.
I open online billpay in yet another tab.
I review my accounts, then proceed to billpay.
Billpay requires JavaScript, so I (at that point) enable JavaScript there.
(I also have NoScript set to only refresh that page, not all of that domain.)
So long as I do not revisit the other banking pages (while JavaScript is enabled) those pages will not time out, will not *automatically log out.
(*not automatically logging out, does not mean the pages have not timed out, just means that the pages will still be visible to you, though after [whatever the timeout period is] they have actually timed out & if you were to perform some action on the page, you would be redirected to log in again)
When I have finished with billpay, I open or jump to some meaningless BoA page & disable JavaScript again.
Having done that, because JavaScript is blocked, the pages will remain. And I can have my banking accounts information & my billpay information visible for as long as I wish.
(Note, I also have NoScript set to [Options | Advanced | Untrusted] 'Forbid META redirections inside <NOSCRIPT> elements.)

That works & has worked for what I need.

If you need to interactively work on the same page, sometimes needing JavaScript, sometimes not, that may be more difficult?
Perhaps a surrogate? or script (bookmarklet or greasemonkey?) to kill the particular timers?
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball NoScript FlashGot AdblockPlus
Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20110520 Firefox/4.0.1 SeaMonkey/2.1
dhouwn
Bug Buster
Posts: 968
Joined: Thu Mar 19, 2009 12:51 pm

Re: stopping just timed or looping scripts

Post by dhouwn »

You might be happy to hear that the upcoming Firefox 5 will increase the timer resolution in background tabs.
You can get the beta at http://www.mozilla.com/en-US/firefox/all-beta.html.

Oh and you could also set noscript.forbidBGRefresh to 3 which would prevent pages from refreshing themselves using certain non-JS based techniques even when they are in your whitelist.

Last but not least, you could misuse session restore by setting browser.sessionstore.max_concurrent_tabs to 0 (which prevents tabs from being loaded again until clicked) and restart the browser and restore the session.
Last edited by dhouwn on Sat May 28, 2011 7:38 am, edited 4 times in total.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
njem
Posts: 6
Joined: Sat May 28, 2011 5:40 am

Re: stopping just timed or looping scripts

Post by njem »

Thanks TheRube but for one I was hoping to avoid all the off/on stuff. And this is on quite a range of sites, new references I need to follow all the time and such. Also many pages need script on at the start so they display right. What would be ideal is something smart enough to detect timed or looping scripts. Or maybe something that would allow pages to load with scripts but then turn off the scripts after a short time so none keep running. I suppose then if a script button didn't work I could manually turn it on for that page. I guess the criteria are:
Gotta have scripts at first to display correctly.
Gotta have scripts at least sometimes for things like scripted buttons.
Don't want continuously running scripts.

I wonder if there isn't a way to detect how long a script has run because once in a while on IE I'll get a pop up that some script is taking too long or something and do I want to stop it. To do that but automatically stop any script that's runs x seconds past page display might be perfect.
Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
njem
Posts: 6
Joined: Sat May 28, 2011 5:40 am

Re: stopping just timed or looping scripts

Post by njem »

DHouwn, interesting idea but not sure it helps. Reading the link it is just for background tabs but also even a 1s time, if that's what loops are based on, wouldn't change much. Typically there is some rotating ad, or checking to see if the content has been updated, or something happening every few seconds. I think on some pages there are multiple things doing that. Then you get a dozen pages open that are all doing that and before you know it 1/3 of cpu is gone. And for some reason memory goes too, at least my experiments with turning all scripts off shows that.
Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
dhouwn
Bug Buster
Posts: 968
Joined: Thu Mar 19, 2009 12:51 pm

Re: stopping just timed or looping scripts

Post by dhouwn »

njem wrote:What would be ideal is something smart enough to detect timed or looping scripts.
Too bad the halting problem is unsolvable in the general case. ;)
I wonder if there isn't a way to detect how long a script has run because once in a while on IE I'll get a pop up that some script is taking too long or something and do I want to stop it.
Firefox has such a detection too, it is controlled by the dom.max_script_run_time setting (seconds until the unresponsive script warning pops up).
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
User avatar
Giorgio Maone
Site Admin
Posts: 9524
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: stopping just timed or looping scripts

Post by Giorgio Maone »

Disabling timers is relatively easy by using Surrogate Scripts.

Just create the following two string preferences in about:config:
  1. noscript.surrogate.notimers.sources
    @^http:
  2. noscript.surrogate.notimers.replacement
    window.__proto__.setTimeout=window.__proto__.setInterval=function(){}
At this point, you can even allow scripts globally and all the setTimeout()/setInterval() calls will be ignored on HTTP pages (if you want to extend this ban to HTTPS pages, just replace "@^http:" with "@^https?:").
Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
dhouwn
Bug Buster
Posts: 968
Joined: Thu Mar 19, 2009 12:51 pm

Re: stopping just timed or looping scripts

Post by dhouwn »

njem wrote:Reading the link it is just for background tabs
True. I guess if you have several pages open you would have them open in tabs in one or two windows so all but two tabs would be background tabs.
Typically there is some rotating ad, or checking to see if the content has been updated, or something happening every few seconds.
That's some sort of polling and is generally achieved using the mentioned setTimeout/setInterval methods.
And for some reason memory goes too, at least my experiments with turning all scripts off shows that.
Active scripts get JIT-compiled so that's indeed connected but apart from that Firefox 4 suffers from some other memory management issues some of which have been fixed in Firefox 5.

Another thing I just remembered, you might want to activate "Apply these restrictions to whitelisted too" in the "Embeddings" tab in the NoScript settings and check "Forbid <IFRAME>" and "Forbid <FRAME>" in the settings. This way have to click placeholders (or use the "Blocked Items" menu) to enable Frames/IFrames even on sites in your whitelist. This way you can enable only the frames you need, reducing the load even further.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
njem
Posts: 6
Joined: Sat May 28, 2011 5:40 am

Re: stopping just timed or looping scripts

Post by njem »

Thanks folks I'll try these out and post my result.
Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
njem
Posts: 6
Joined: Sat May 28, 2011 5:40 am

Re: stopping just timed or looping scripts

Post by njem »

This is getting close but not there yet. Using your kill-timers config entries then some pages don't display right, even if scripts are allowed globally. Try bbc.co.uk. It has a box at the top with three stories in a rotating window and a button to rotate. Only one shows up with timers killed. Further down it has a window with heading buttons (tech, health, eco) that show different stories, also doesn't show. Getting rid of those config entries, if I allow scripts while it first loads it displays right, then turn off scripts but then the buttons to rotate stories don't work. There are lots of similar pages, this is just a good example. I know in some programming cases you don't want things to happen right away, you set a timer for something to happen 1ms after opening. Maybe BBC is doing similar?

A worst case page for scripts is www.washingtonpost.com/blogs/ezra-klein. Actually this one I can load without scripts and everything I need works. But it's a good test case for why to stop timed scripts. It's terrible in eating cpu and memory if all scripts run. And it keeps on running continuously. There are lots of pages like this, this is just worst case. Pages like this are where I wish scripts would run long enough to get everything set, then kill all continuously running ones. I can do that with noscript with manually turning scripting off an on, but then two things: A: I need to turn it on when opening a page then turn it off, till I open another page. B: Turning scripts off after the page is settled blocks things like the BBC rotate buttons.

What would work is for scripts to be generally allowed so things load right, then after x time, I don't know, maybe timers are killed then? So things can't run continuously but scripted buttons still work?
Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
dhouwn
Bug Buster
Posts: 968
Joined: Thu Mar 19, 2009 12:51 pm

Re: stopping just timed or looping scripts

Post by dhouwn »

Not sure whether I should have revived this thread for this or opened a new one in Web Tech section (Mods, please do as you please, eventually split this post into a new thread there), but for those of you who are interested in reducing the impact of background tabs, there is now a new extension from the ABP author for this: http://adblockplus.org/blog/preventing- ... -resources
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0
User avatar
therube
Ambassador
Posts: 7969
Joined: Thu Mar 19, 2009 4:17 pm
Location: Maryland USA

Re: stopping just timed or looping scripts

Post by therube »

Suspend Background Tabs conflict with Tab Stats
Suspend background tabs breaks twitter and Gmail

In the past we had BarTab & that worked very well (even if the unload tab function didn't work in SeaMonkey).
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball NoScript FlashGot AdblockPlus
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120511 Firefox/14.0a2 SeaMonkey/2.11a2
njem
Posts: 6
Joined: Sat May 28, 2011 5:40 am

Re: stopping just timed or looping scripts

Post by njem »

dhouwn thanks for the info. I'll try it out. If this works well it would be a big plus.

Njem
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19
Post Reply