Trouble with asynchronous behaviour of location.href in Firefox 3.0.3

25 views
Skip to first unread message

eijk

unread,
Dec 4, 2008, 8:50:50 AM12/4/08
to greasemonkey-users
Hi!

The location hack doesn't seem to work anymore, as location.href
evaluation seems now to be treated asynchronously. Consider:

// ==UserScript==
// @name Location Hack Test
// @namespace tag:tilman...@web.de,2008:userscripts
// @include *
// ==/UserScript==

if (unsafeWindow.console !== undefined)
GM_log = unsafeWindow.console.log;

location.href = "javascript:void(document.title = 'TEST')";

GM_log(document.title);

setTimeout(function() { GM_log(document.title); }, 0);

This will output on my machine:

tag:tilman...@web.de,2008:userscripts/Location Hack Test:
greasemonkey-users | Google Groups
tag:tilman...@web.de,2008:userscripts/Location Hack Test: TEST

So, only after returning from the userscript, the href will be
evaluated. This also makes the getGlobalValue implementation using the
location hack almost unusable. I am not so keen on defining tons of
async callbacks...

I am doing something dumb here?

Regards,

Tilman

eijk

unread,
Dec 4, 2008, 9:07:55 AM12/4/08
to greasemonkey-users
I mean, apart from "GM_log = unsafeWindow.console.log".

Anthony Lieuallen

unread,
Dec 4, 2008, 9:50:52 AM12/4/08
to greasemon...@googlegroups.com
On 12/4/2008 8:50 AM, eijk wrote:
> The location hack doesn't seem to work anymore, as location.href
> evaluation seems now to be treated asynchronously. ...

Wasn't it always? If it doesn't work "anymore", when exactly did it?

eijk

unread,
Dec 4, 2008, 10:17:12 AM12/4/08
to greasemonkey-users
For me, it worked before (i.e. under Firefox 2). Or put differently:
You are saying, that the
code at the end of

http://wiki.greasespot.net/Location_hack

for window.getGlobalValue() should never have worked?

Regards,

Tilman

esquifit

unread,
Dec 5, 2008, 5:32:31 PM12/5/08
to greasemon...@googlegroups.com
This is an interesting point. Try the following:

1) Make a new userscript that runs on 'http://wiki.greasespot.net/Location_hack'
2) Copy the code at the end of that page and paste it into the new script
3) Append the following lines:

alert(window.getGlobalValue('wgServer'));
alert(window.getGlobalValue('wgPageName'));
alert(window.getGlobalValue('wgArticleId'));

I would expect the following:

1st alert: http://wiki.greasespot.net
2nd alert: Location_hack
3rd alert: 1551

However, I'm getting:

1st alert:
2nd alert: http://wiki.greasespot.net
3rd alert: Location_hack

That is, the alert are returning the value set in the previous invocation.

Putting the alerts into setTimeout doesn't help, so I think this is
not an timing issue or a problem between the GM scope and the page's.
In fact, all alerts but the first one are returning values, that is,
*before the script returns*.

Another way to see it could be that this is an issue in the way
Firefox evaluates things within a function scope. There is a recent
report about this kind of (apparent?) problem, see [1] and the
comments that ensue.

Finally, note that if you insert an alert('foo') just before the line
'location.href = ... ', then everything works fine. I cannot explain
this behaviour.

[1] http://nedbatchelder.com/blog/200812/internet_explorer_mystery_1376.html

Reply all
Reply to author
Forward
0 new messages