Bug 12307 - No way to test error condition of synchronous XMLHttpRequest to file:///
Summary: No way to test error condition of synchronous XMLHttpRequest to file:///
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: XML (show other bugs)
Version: 420+
Hardware: Macintosh OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 10489
  Show dependency treegraph
 
Reported: 2007-01-17 17:40 PST by Jesse Costello-Good
Modified: 2014-06-13 17:04 PDT (History)
5 users (show)

See Also:


Attachments
test case (1.21 KB, text/html)
2007-02-15 02:55 PST, Alexey Proskuryakov
no flags Details
WIP patch (7.03 KB, patch)
2014-06-13 15:56 PDT, Alexey Proskuryakov
no flags Details | Formatted Diff | Diff
slightly better, but still fails tests (9.46 KB, patch)
2014-06-13 17:04 PDT, Alexey Proskuryakov
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Costello-Good 2007-01-17 17:40:10 PST
There is no way to tell whether an asynchronous XML HTTP request to the local disk (when running a page from file:///) has failed. 

// #1 works ok from HTTP
var r = new XMLHttpRequest();
r.open("GET", "http://www.apple.com/nowhere.html", true);
r.send();
// wait ...
r.status == 404

// #2 works ok synchronously
var r = new XMLHttpRequest();
r.open("GET", "nowhere.html", false);
r.send(); // throws an error 

// #3 but asynchronously ... no way to detect the error
var r = new XMLHttpRequest();
r.open("GET", "nowhere.html", true);
r.send();
// wait ... no error thrown
r.status == 0


Both Internet Explorer and Firefox seem to ignore async when requesting a resource from the local disk. They both throw an exception like Safari does in the second example. But they also both throw an exception in the third example whereas Safari doesn't.
Comment 1 Alexey Proskuryakov 2007-02-15 02:55:43 PST
Created attachment 13181 [details]
test case

In the future, we will probably dispatch an error event for XMLHttpRequest.

From my testing, it appears that IE 7 refuses to load local files altogether. Firefox 2 does raise an exception in send(), but if a local file is accessible, then the actual loading happens asynchronously. This behavior is not in accordance with draft XMLHttpRequest spec AFAICT.
Comment 2 Julien Chaffraix 2008-08-23 03:36:12 PDT
(In reply to comment #1)
> Created an attachment (id=13181) [edit]
> test case
> 
> In the future, we will probably dispatch an error event for XMLHttpRequest.

We have implemented 'onerror' from XMLHttpRequest level 2, which means that we now have a way to check for asynchronous request failures.

However during my quick testing, I have tried doing a synchronous one to a non-existent file (just modify the given test case to do a synchronous request) and we do not dispatch an error event nor do we throw an exception.

We do not raise an exception because it breaks some website (see http://trac.webkit.org/changeset/23889) but we could at least dispatch an event so there is a way to determine that an error occurred.
Comment 3 Alexey Proskuryakov 2009-02-24 07:25:32 PST
Renaming the bug, as it now tracks sync requests, not async ones.
Comment 4 Marcus Better 2009-09-22 07:07:25 PDT
(In reply to comment #1)
> From my testing, it appears that IE 7 refuses to load local files
> altogether.

This is not quite accurate, it can load local files if the native XHR implementation is switched on in the "Advanced" tab of the "Internet Options".
Comment 5 Alexey Proskuryakov 2014-06-13 15:56:51 PDT
Created attachment 233084 [details]
WIP patch

Fails some tests.
Comment 6 Alexey Proskuryakov 2014-06-13 17:04:44 PDT
Created attachment 233094 [details]
slightly better, but still fails tests