Timer and anonymous function

146 views
Skip to first unread message

spirit

unread,
Mar 28, 2011, 10:43:59 AM3/28/11
to greasemonkey-users
Hello

On Firefox 4 I have a problem with run this code:

t = setTimeout(function(){alert(test)}, 500);

Its strange, because on last Firefox 3.6.16 and the same GM version
all works fine.

Of course this solution will work:

function test(){
alert("RunMe");
};
t = setTimeout(test, 500);

But correct all code is annoying. Any ide why first example dosn't
work?

spirit

unread,
Mar 29, 2011, 11:24:17 AM3/29/11
to greasemonkey-users
I check this again and its strange. Sometimes my all script do not
perform commands such setTimetout (but rest command scripts works
fine). When I run again Firefox everything work fine. At this moment
dont know if I have problem on my code or some extensions brake
scripts.

spirit

unread,
Apr 7, 2011, 9:50:09 AM4/7/11
to greasemonkey-users
Ok, I checked the matter thoroughly. On new profile in Firefox4 instal
only Greasemonkey.

And now, I wrote script who randomly do sth (like go to other page),
using this syntax:

t = setTimeout(function(){document.location.pathname = "xxx"}, 500);

And all will works fine, of course in anonymous function can be any
command. Sometimes to debug my script I use alert box. But in Firefox
4 when I use alert, this comand broke every timeout and interval, and
script stop work. Just one alert and script not work, even if I dont
use alert again. Delete alert in my script, refresh tab does not
change anything.

If I change anonymous function to normal function (with name), script
re-starts and work fine. If I dont do that, I must close tab and open
again << and all work, until I will not use alert again.

What is interesting, if I make and put button on page, add to it
eventlistener click (which activates alert) and press this buton,
script work correctly, so this kind of alert does not spoil anything.

Firefox 3.6.16 that problem is no exist, I use Windows XP. Any
solution or explain?

Anthony Lieuallen

unread,
Apr 7, 2011, 9:53:27 AM4/7/11
to greasemon...@googlegroups.com
On 04/07/11 09:50, spirit wrote:
> Sometimes to debug my script I use alert box. But in Firefox
> 4 when I use alert, this comand broke every timeout and interval, and
> script stop work. Just one alert and script not work, even if I dont
> use alert again. Delete alert in my script, refresh tab does not
> change anything.

This sounds a lot like the results I just found in relation to
GM_xmlHttpRequest:
https://github.com/greasemonkey/greasemonkey/issues#issue/1318/comment/965621

Firefox 4 has a completely new style "tab-modal" alert. It appears to
function ... in an unusual manner.

spirit

unread,
Apr 7, 2011, 10:14:38 AM4/7/11
to greasemonkey-users
I must correct sth, If I broke timer with using alert, change
anonymous function to name function dosn't repair anything, I must
delete alert from code, close and open tab again.

But what I see, this syntax work fine:

setTimeout("alert('aa')", 100);

That alert does not cause the described problem.
Reply all
Reply to author
Forward
0 new messages