0x80004005 (NS ERROR FAILURE) and other firefox errors
From Helpful
| These are primarily notes This is probably not going to be complete in any real sense, but may be useful information nonetheless. |
Contents |
0x80040111 (NS ERROR NOT AVAILABLE)
Reason
This usually happens when you have a XMLHttpRequest onerror handler in which you tried to read the result's status (or statusText) when that value is not available, usually meaning it was broken off, or it failed in a specific way.
The W3 specs tell you that you shouldn't try to read status in the onerror handler because for some problems it may not be set, and that in this case an error must (!) be raised.
This error is specific to Gecko (Firefox, Mozilla) because it adheres to those specs closer than most other browsers. The Gecko specs also tell you not to do this (...as I recall, I can't actually find it right now).
The cause is often that the browser never got a reponse with a HTTP status to parse out, for example via requests that are broken off on the client, a connection that broke because of some connectivity problem, and sometimes a (seriously) malformed server response.
The problem can also occur when AJAX is canceled by page unload, e.g. when you trigger AJAX from a form that also causes a page-reload-style submission (often a form with a submit-type button).
Fix
If this happens in your own handler code, the simplest fix is probably wrapping the status read in a try-catch.
If you use AJAX from some library and implicitly its error handler, it's a bug in that library that has not yet been fixed, so google around for a fix and bug its creator. If such a library it lets you write your own callbacks and its documentation didn't warn you about this, bug them about it too.
When caused by the form problem, you can usually avoid it fairly easily. One solution is to use only a <button>, <input type="button">, or anything else that looks clickable enough but doesn't submit a form (like a submit button would), so that the only event is the AJAXing.
Alternatively, you could omit the <form> so that a submit-type button wouldn't know where to go, so won't do anything -- but I should check whether there are that may assume something, such as going to the current url.
Unknowns
It is technically possible that a server can cause a malformed HTTP response (often caused by a bad script), or no response at all
There may be other causes, I'm not sure.
See also
- http://www.w3.org/TR/XMLHttpRequest/ (the "The XMLHttpRequest Object" section)
- https://bugzilla.mozilla.org/show_bug.cgi?id=238559
0x80004005 (NS ERROR FAILURE)
A general-purpose mozilla error, but if your own Javascript causes it it usually points to one of relatively few problems.
Figuring out what failed
The error will mention a function after the error, which gives a decent hint of the problem. For example:
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLSelectElement.selectedIndex]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
...and so on mentions nsIDOMHTMLSelectElement.selectedIndex. This particular error was caused by trying to set an out-of-bounds selectedIndex on a SELECT element (and is an example from [1]).
XMLHttpRequest
Common types of XmlHTTPRequest bugs/abuse will usually mention either nsIXMLHttpRequest.open or nsIXMLHttpRequest.send.
Errors are specific to each function, but usually your problem is one of:
- stale references, often between documents (think (popup) windows, frames, iframes, and embeds), or the browser got confused about when it should clean up. For example, the document the XHR was created in does not exist anymore, or using an old reference to a new embedded plugin object (e.g. video)
- Use of firebug:
- If you are using firebug, you should be aware that there are older versions that did not handle XHR in frames well. Firebug would be the sole cause of the last mentioned error.
- triggering ajax from the firebug command line is sandboxed may cause this in certain cases
- trying cross-domain XHR, or using an absolute URL (verify)
- that you violated the specs or did something nonsensical, e.g. trying to send() more than once(verify) or trying to set headers after sending data (verify)
You can even look at the firefox XHR source code e.g. for send() to see what cases trigger this error.
TODO: Read:
Unsorted
Categories: Error | Internet | Webdev

