Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Recognizing page load failure

346 views
Skip to first unread message

Chris Ross

unread,
Dec 1, 2011, 11:15:02 AM12/1/11
to dev-ext...@lists.mozilla.org

I have an extension that is already using a WebProgessListener to
watch for the user switching between different tabs so that it can
display and hide a toolbar when only the relevant tabs are displayed.

I'm want to be able to test, when the tab is opened and attempts to
load a document, if that fails. Due to any sort of connection failure,
or a 500-class response code.

I am looking at
https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads ,
which sounds like where I should be, but I don't see anything in there,
or the nsIWebProgress or nsIWebProgressListener that seem to relate to
the ultimate success or failure of loading a document.

I put dump() statements in all of the onLocationChange,
onStateChange, onProgressChange, and onStatusChange in my listener, but
can't identify any calls to those methods that give me the information
I'm looking for.

Any suggestions as to what I'm missing? Thanks...

- Chris

--
Chris Ross
chris...@markmonitor.com

Neil

unread,
Dec 2, 2011, 5:25:21 AM12/2/11
to
Chris Ross wrote:

> I'm want to be able to test, when the tab is opened and attempts to
> load a document, if that fails. Due to any sort of connection
> failure, or a 500-class response code.

For a connection failure, you will typically get an error page; you can
detect this using Components.isSuccessCode(aRequest.status). Do this in
the onLocationChange method of your listener. Note that sometimes
aRequest is null when it shouldn't be, so you need to check that first.

For a response code, you have to see if the request was an HTTP request
using if (aRequest instanceof Components.interfaces.nsHTTPChannel); if
that succeeds you can then read the request.responseStatus. I don't know
when the best time to check that is, but you might be lucky and find out
that onLocationChange works here too.

--
Warning: May contain traces of nuts.
0 new messages