Thursday, July 27th, 2006

Pains of document.domain in FireFox 1.5

Category: JavaScript, Tip

Alexander Kirk has written about a problem with XHR, responseXML and document.domain in FireFox:

This will work in IE, Safari, and Opera.
This will not work in Firefox 1.0. This is very awkward but at least it has been fixed in 1.5.
So it will work in Firefox 1.5. But:

The responseXML object is useless. You can’t access it, you receive a Permission Denied when trying to access it’s content (e.g. documentElement). Very annoying.
Even stranger that responseText is still readable. What’s the reason for this? Is there some security risk i am unaware of or is it a plain bug?

As the responseText is available there is a pretty simple fix: re-parse the XML, which is kinda stupid and cpu intense if you have a lot of them. (something like: var doc =
(new DOMParser()).parseFromString(req.responseText, “text/xml”);

Posted by Dion Almaer at 1:55 pm

4.1 rating from 17 votes


Comments feed TrackBack URI

Comment by AndyC — July 27, 2006

See my post. Actually that bug had been opened on 2006-02-07 17:02 PDT and has not yet been dealt with.

Comment by Alexander Kirk — July 27, 2006

I’m very familiar with this bug, and have been using the re-parse workaround for some time. You may be interested to know that Firefox exhibits a similar bug with stylesheets – once you set document.domain, you can no longer programatically access the contents of included css stylesheets – permission denied!

Comment by heswell — July 27, 2006

ps for gods sake fix this commenting system – its an embarassment

Comment by heswell — July 27, 2006

This site is becoming an embarrassment…talking about Ajax but the hole experience is so 90’s…where is the Ajax you’re talking about?

It’s just so full of links and text that I haven’t requested about in the first place…

Comment by Ned — July 27, 2006

Please fix the title so that it spells “Firefox” instead of “Firefox”.
Did you just realized you wasted extra energy when you reached your finger to the “Shift” key when you’re capitalizing the second F while you’re not supposed to ;) ?

Comment by kourge — July 29, 2006

And, by the way, the responseXML “bug” in Firefox isn’t a bug. As stated in MDC, Mozilla browsers will not make responseXML available unless the server serves the MIME type text/xml.
There are two ways to fix this. One is to alter the server’s script to make it serve the Content-Type: text/xml header. The second way is to do something like this in your JavaScript code:

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
if (req.overrideMimeType) req.overrideMimeType("text/xml");
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");

This will force Mozilla browsers to parse the responded XML in the XMLHttpRequest object, given that the XML is well-formed.

Shouldn’t all Ajaxians take note of this?

Comment by kourge — July 29, 2006

Donjis go mambi?

Comment by Donji — March 19, 2007

kourge’s method fails in firefox 2.0/1.5. I have set both the server response type and overridemimetype nothing works. I had to resort to reparsing the response text as xml. Needless it is a great pain in, you where! FF is the best browser but slowly it may be moving towards the Netscape way.

Comment by dude code — June 24, 2007

Leave a comment

You must be logged in to post a comment.