[Greasemonkey] Using Greasemonkey scripts with non-HTML pages

Alex Garrett ljagged at gmail.com
Mon Aug 29 18:08:36 EDT 2005

This question could very well demonstrate my complete ignorance of
Javascript, the DOM, and Greasemonkey (maybe all at once), but I would
appreciate a bit of advice or a pointer to where I can find more
information, if possible. I don't know enough about the problem space
to figure out the best place to look for a solution.

What I'd like to know is if it's possible for a Greasemonkey script to
load and be used for a non-HTML page, particularly one like:


Consider the following GM script:

var images = document.getElementsByTagName("img");
for(var i = 0; i < images.length; ++i) {

If you go to http://www.google.com, it works. If you go to
http://www.google.com/intl/en/images/logo.gif it doesn't work.

When you load the image-only URL in Firefox and use the DOM Inspector,
it shows an HTML node with a BODY node with an IMG node that contains
'src' and 'alt' attributes for the single IMG node. However, if you do
a 'view source', you just get a dump of the binary data instead of an
HTML wrapper that the DOM Inspector seems to be inspecting.

So, what's going on here? Does GM only hook into actual HTML
documents? Is there any way make the script work with plain old image
URLs? Is this a DOM thing? A Firefox thing? Are there some firefox API
calls that can hook into this kind of document?

I apologize if these questions either have obvious answers or if
they're completely misinformed by my lack of knowledge about how
Firefox handles loading documents. Any pointers would be greatly


More information about the Greasemonkey mailing list