Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit be03106

Browse files
committed
fix for file:/// xhr in Chrome
1 parent 9b4fcbe commit be03106

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/system-fetch.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,22 @@
3131

3232
xhr.onreadystatechange = function () {
3333
if (xhr.readyState === 4) {
34-
if (xhr.status === 200 || (xhr.status == 0 && xhr.responseText)) {
34+
// in Chrome on file:/// URLs, status is 0
35+
if (xhr.status == 0) {
36+
if (xhr.responseText) {
37+
load();
38+
}
39+
else {
40+
// when responseText is empty, wait for load or error event
41+
// to inform if it is a 404 or empty file
42+
xhr.addEventListener('error', error);
43+
xhr.addEventListener('load', load);
44+
}
45+
}
46+
else if (xhr.status === 200) {
3547
load();
36-
} else {
48+
}
49+
else {
3750
error();
3851
}
3952
}

0 commit comments

Comments
 (0)