Skip to content

Commit a230302

Browse files
yaustarSteven Yau
andauthored
Fixes using the local file system in special browser mode (playcanvas#2597)
Solves the issue where the browser returns status code 0 on XHR requests file requests when the browser is using '--allow-file-access-from-file' flag. See https://cmatskas.com/interacting-with-local-data-files-using-chrome/ This is needed in special cases such as using CefSharp which embeds a Chromium browser into a C# app under special settings Co-authored-by: Steven Yau <syau@snaphcat.com>
1 parent 4e871eb commit a230302

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/net/http.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,20 @@ Object.assign(Http.prototype, {
448448
_onReadyStateChange: function (method, url, options, xhr) {
449449
if (xhr.readyState === 4) {
450450
switch (xhr.status) {
451+
case 0: {
452+
// If status code 0, it is assumed that the browser has cancelled the request
453+
454+
// Add support for running Chrome browsers in 'allow-file-access-from-file'
455+
// This is to allow for specialised programs and libraries such as CefSharp
456+
// which embed Chromium in the native app.
457+
if (xhr.responseURL && xhr.responseURL.startsWith('file:///')) {
458+
// Assume that any file loaded from disk is fine
459+
this._onSuccess(method, url, options, xhr);
460+
} else {
461+
this._onError(method, url, options, xhr);
462+
}
463+
break;
464+
}
451465
case 200:
452466
case 201:
453467
case 206:

0 commit comments

Comments
 (0)