GM script never runs unless @include about:blank

73 views
Skip to first unread message

PeterFacey

unread,
Aug 19, 2010, 1:57:56 PM8/19/10
to greasemonkey-users
I was trying to customise http://www.elgin.gov.uk . It's a site that
uses over 1.2 million characters of javascript on the client side and
a lot of DOM manipulation.

My script said @include http://www.elgin.gov.uk but, to my surprise,
it never ran (a script which just said alert("I am running") did not
alert).

By using the Firefox Error Console, and putting javascipt into the
direct evaluation "Code:" line, I discovered that window.document.href
was "about:blank" (which is my browser's default home page). This
despite the fact that only one window was displayed by Firefox and it
said at the top left "Elgin - Roadworks Information - Mozilla
Firefox".

So, I added to my script @include about:blank, knowing this was not
practical but hoping that at least the script would run. It did.

I then changed my script to say:
GM_log("This window:-");
var p = window;
GM_log("href="+p.location.href);
GM_log("title="+p.document.title);
GM_log("domain="+p.document.domain);
GM_log("Window.parent:-");
var p = window.parent;
GM_log("href="+p.location.href);
GM_log("title="+p.document.title);
GM_log("domain="+p.document.domain);
if (window.top==window.parent) {GM_log("Yes");}

which produced the following log:
This window:-
href=about:blank
title=
domain=www.elgin.gov.uk
Window.parent:-
href=http://www.elgin.gov.uk/index.cfm?
fuseaction=streetworks.streetworksHome&ORGANISATION_ID=0&API=0&INSERTHTMLHEAD=true&LOGOUT=0&CHK_LAAREA=not_set&DBUG=0&
title=Elgin - Roadworks Information
domain=www.elgin.gov.uk
Yes

The second (parent) window is the one FF is displaying and which
contains all the Elgin javascript and DOM objects. But somehow both
the FF error console and GM have been persuaded that the relevant
window is not that one but a child containing nothing. And this
results in GM not running the script (unless I @include about:blank).

I feel this is a problem with GM or FF rather than in my script.

Anyone have any ideas?

PeterFacey

unread,
Aug 19, 2010, 2:00:01 PM8/19/10
to greasemonkey-users
I forgot to add:
FF 3.6.8
GM: 0.8.20100408.6

Anthony Lieuallen

unread,
Aug 19, 2010, 2:15:23 PM8/19/10
to greasemon...@googlegroups.com
On 08/19/10 13:57, PeterFacey wrote:
> @include http://www.elgin.gov.uk

This include will never match anything. At best, you might end up at
the URL "http://www.elgin.gov.uk/" (note the trailing slash). You
probably want:

@include http://www.elgin.gov.uk*

The whole about:blank thing is a red herring, there's probably an iframe
that (briefly) happens to be at that address also, when loading that page.

PeterFacey

unread,
Aug 19, 2010, 4:14:58 PM8/19/10
to greasemonkey-users
Thanks, yes the uk* makes it work.

I find I have to use unsafeWindow to access the Elgin javascript
objects, as ordinary window just says "undefined".

Do I always need a / at the end of the URL? (Absence hasn't caused a
problem for me with other scripts)
Reply all
Reply to author
Forward
0 new messages