0

I'm trying to run "inherited" code and since I'm fairly new to HTML & javascript I keep running into annoying little issues (that's how you learn :D ).
I have a GET request that is meant to load an mp4 file from a server, but for the sake of debugging and practice, I'm trying to load it from a local directory. I enabled the "--allow-file-access-from-files" flag on my chrome, so I know it's not a SOP issue. I can't figure out why, the request is sent 3 times, ALWAYS the first and last fail and the 2nd doesn't, but the file is not loaded.

here's a simplified version of the code:

var req = new XMLHttpRequest();
req.open('GET', currentFileName, true);
// currentFileName is an mp4 in the same directory
req.responseType = 'blob';

req.onload = function () {
    // Onload is triggered even on 404
    // so we need to check the status code
    if (this.status === 200) {
        console.log("success!");
        doSomeFunc();
        }
    }
};
req.send();

here's the network log:
enter image description here

I looked into many possible solutions (example 1, 2, 3, 4, 5)
Couldn't find a question where this happens with local files.
What might be wrong?

Jon Nir
  • 507
  • 3
  • 15
  • So how is your code being called? – epascarello Apr 20 '20 at 16:59
  • You can't make XHR requests to local files, it's a cross-domain request, since XHR works with http(s) protocol, not with file protocol. Setting `--allow-file-access-from-files` flag doesn't circumvent that. – Teemu Apr 20 '20 at 17:00

0 Answers0