[Greasemonkey] "Invalid document, could not get global object" error?

Michael Kraft mjk4984 at yahoo.com
Sun Aug 28 13:44:54 EDT 2005

A script which used to work all the time on a specific page in GM 0.3.1 now
frequently dumps out an "Invalid document, could not get global object" error
when greasemonkey.logChrome is enabled.  This effectively stops the script from

The script is designed to automate processing of one frame (of 4 frames) in a
web page generated by php so it "clicks" objects depending on a set of rules. 
The script will keep running until it determines that the reloaded page now
longer contains a certain object and then it will stop.  This worked great in

Now though frequently it will spit out the error and then list the doc contents
as being the previous page's source (the page that displayed right before the
one that is currently showing).  For some reason Greasemonkey will only allow
doc contents to be either blank or "<HTML><HEAD/></HTML>" otherwise it throws
up that error and the script won't execute. 

What seems to be happening is that sometimes the
GM_DocHandler.prototype.onProgressChange function is triggered before the web
page is unloaded which results in the error (I believe this is why the previous
page's contents are listed). Since there is a removeProgressListener(this) call
at the end of the function, it stops it from further checking on that page.  I
saw two doc contents of "<HTML><HEAD/></HTML>" shortly after the error in the
log, but it is not clear what page they came from since that information isn't

I tried removing the check to see what would happen and my script starting
working 100% of the time on the page.

Why exactly is that check there?  Is there a way to keep it from checking until
the page finished unloading since that appears to be what the problem is?

More information about the Greasemonkey mailing list