GM 0.8 and document.evaluate().snapshotItem().parentNode

75 views
Skip to first unread message

Dark Ryder

unread,
Jun 27, 2008, 1:20:11 PM6/27/08
to greasemonkey-users
After upgrading to Greasemonkey 0.8.20080609.0, one of my scripts has
started generating "Component is not available" errors. The script
can be found on us.o:

http://userscripts.org/scripts/review/16396

The line which generates the is "parent = comic.parentNode", which
certainly looks innocuous enough to me. One of the script's users
reports that wrapping the line with "with (unsafeWindow) { ... }"
resolves the issue, but I'm unclear on why it should be necessary to
bypass the wrapper in order to get an element's parent node.

The only possibility I can think of (and one which does not, to me,
suggest a solution) is that I'm getting the element via a
"document.evaluate" unordered snapshot and that it is therefore
"unsafe" to reach outside the set of nodes returned.

Any thoughts on how to correct this without using unsafeWindow?

Anthony Lieuallen

unread,
Jun 27, 2008, 1:35:27 PM6/27/08
to greasemon...@googlegroups.com
On 6/27/2008 1:20 PM, Dark Ryder wrote:
> After upgrading to Greasemonkey 0.8.20080609.0...

First check, was this (upgrade GM) done at exactly the same time that
you upgraded Firefox 2 to 3? In FF3, I see the same behavior. And I'm
similarly at a loss for an explanation. The best next step would be to
come up with a minimal test case. A sample page with as few elements as
possible, a script with as few statements as possible, which triggers
the same error. (Basically, start taking things away, and keep doing
that as long as you can take something away without removing the tiniest
bit that breaks.)

P.S. node.insertBefore(othernode, null) has the exact same affect as
node.appendChild(othernode) so you can skip that if test.

Dark Ryder

unread,
Jun 27, 2008, 1:39:42 PM6/27/08
to greasemonkey-users
On Jun 27, 10:35 am, Anthony Lieuallen <arant...@gmail.com> wrote:
> First check, was this (upgrade GM) done at exactly the same time that
> you upgraded Firefox 2 to 3?

Bah, I knew I left something out. No, I haven't upgraded to FF3 at
all yet, I'm still running 2.0.0.14.

I'm afraid I don't have the time to set up test cases this morning (I
was really hoping there was a known solution), but I'll see what I can
come up with this afternoon.

Joachim Ott

unread,
Jun 27, 2008, 2:07:13 PM6/27/08
to greasemonkey-users
It works when you omit the declaration of parent, i.e. change

var comic, comics, i, parent, title;
to
var comic, comics, i, title;

JavaScript+GM is still fun, tho.

Anthony Lieuallen

unread,
Jun 27, 2008, 2:10:16 PM6/27/08
to greasemon...@googlegroups.com
On 6/27/2008 2:07 PM, Joachim Ott wrote:
> It works when you omit the declaration of parent...

Crazy. This leads me to a test case:

var parent=document.body;
parent.parentNode;

Assign any element to a "var parent" and look for it's parentNode, and
you get this error. Sounds like it's related to:

http://greasemonkey.devjavu.com/ticket/108

Dark Ryder

unread,
Jun 27, 2008, 2:27:16 PM6/27/08
to greasemonkey-users
On Jun 27, 11:10 am, Anthony Lieuallen <arant...@gmail.com> wrote:
> Assign any element to a "var parent" and look for it's parentNode, and
> you get this error. Sounds like it's related to:
>
> http://greasemonkey.devjavu.com/ticket/108

And here I thought that locally declaring variables was supposed to
avoid problems like that! As a "permanent" workaround, I'm just
changing the variable name from "parent" to "parentNode".

Thanks for your help, both of you!

Joachim Ott

unread,
Jun 27, 2008, 2:32:14 PM6/27/08
to greasemonkey-users
Ok, parent is not a reserved word, but a keyword in Javascript. Maybe
that's why.

http://www.quackit.com/javascript/javascript_reserved_words.cfm
Reply all
Reply to author
Forward
0 new messages