Firefox 1.5 and Greasemonkey 0.6.4: where is my DOMParserDecember 02, 2005
The good news is that Firefox 1.5 is out and for it there is also the newest Greasemonkey 0.6.4.
The bad news is that this combination breaks a lot of existing user scripts. There is a WiKi up that gives a helping hand at upgrading scripts but it is not complete (covers mainly XPCNativeWrappers, you know the unsafeWindow thingy).
I was quite surprised that the IMDB ratings for MyVue.com stopped working. It was specifically the DOMParser that stops working with the cryptic error message 'DOMParser is not a constructor'.
The instinctive thing would be to use responseXML instead of responseText but only until you remind your self that the GM_xmlhttpRequest implementation returns the same string for both functions (instead of the correct DOM object for responseXML).
I was just about to dive into manual parsing of the XML response with regexp and indexOf goodness but was literally saved by boogs from the Greaseblog.
He pointed me to the little known "new XML()" of Mozilla E4X. It can parse XML text strings and provide DOM like interface so it is good enough for the job.
There are some oddities of course. When first using it you will get a xml is a reserved identifier error. Don't ask why but the xml declaration has to be stripped out from the top of your xml document. Achieve this with
To get to a node use the following syntax:
xmlDoc..foo (for the first instance of foo tag). I found more information on the EX4 syntax at the E4X Expression Tester.
Now get busy fixing those old Greasemonkey scripts!
Turns out that you can use XPCNativeWrapper to instantiate a new DOMParser (and other missing objects like XMLSerializer, HTMLBodyElement, ...) like so:
var dp = new XPCNativeWrapper(window, "DOMParser").DOMParser.
I am not sure about the security implications of doing this.
TrackBack URL for this entry: