Bookmarklets updated to comply with DOM 2 rule

DOM 2 does not allow nodes to be moved between documents -- in fact, it requires that implementations throw an error when code tries to do so. But for years, Gecko has not enforced this rule.

It's a bit embarrassing that Internet Explorer gets this right and we get it wrong. Someone might think Gecko is trying to embrace and extend the DOM.

Soon, Gecko will start enforcing the rule on trunk. But bringing Gecko in line with this aspect of the DOM spec risks breaking Gecko-specific code, such as code in extensions and bookmarklets written for Firefox. For example, my Search Keys extension used to create some nodes in the chrome document, and some in the foreground tab, before putting them in the tab that that just loaded. Search Keys 0.8 creates all elements in the correct document.

I also updated the following bookmarklets to create nodes in the correct document and/or use importNode when copying nodes between documents:

These bookmarklets previously only worked in browsers that violated the DOM spec by allowing nodes to be moved between documents without a call to importNode or adoptNode. Maybe some of them work in IE now.

If you use those bookmarklets, you should grab the new versions so they won't break when you update to next week's trunk build or to Firefox 3.

359 Responses to “Bookmarklets updated to comply with DOM 2 rule”

  1. voracity Says:

    I don’t understand why this was implemented. I read through the bug, and I still don’t understand it. Do you have any ideas why its considered useful? IE + standards conformance doesn’t make sense to me, since DOM v3 (or v4) could just remove the requirement, and Gecko’s behaviour is a superset of IE’s behaviour.

    Also, does a workaround just involve invoking innerHTML/removeChild (or something equivalent if that’s not standard enough)?

  2. Wladimir Palant Says:

    I just hope Gecko won’t copy Internet Explorer’s error message here – I rarely see anything so useless and misleading :)

  3. Jesse Ruderman Says:

    Gecko’s error message is “Node cannot be used in a document other than the one in which it was created” :)

  4. Øyvind Ø Says:

    Except for punctuation, it can’t be much better..:D

  5. Jesse Ruderman Says:

    How would you improve its punctuation? No errors jump out at me…

  6. Øyvind Says:

    Though English is not my first language, nor my second, I am still pretty sure there is supposed to be a dot at the end of the error message. It is a sentence after all.

    But it was more ment as irony. The error message can’t be missunderstood. Sorry, for the double confusion here. As long as the appendChild method works the way it was intended, I am happy..:)