IE 11, XMLHttpRequest, xhr.upload no set in a Webworker

641 views Asked by At

while trying to code an upload library in JavaScrupt I ended with a weird problem on IE 11.

With XMLHttpRequest 2, you can upload files and get the progress. However, if you are trying to do so in a webworker, you won't get any progress from IE 11 (I tried only this version). You will get an error with the same code.

Here an example :

worker.js

self.addEventListener("message", function(e) {

    var file = e.data;

    var xhr = new XMLHttpRequest();
    if (xhr.upload)
       xhr.upload.onprogress = function(event){
          // here we get the progression through event.loaded
    };

    xhr.open('POST', '/upload.php', true);
    xhr.send(file);

});

main.js

var uploadworker = new Worker('worker.js');
uploadworker.postMessage( file );

If you use this code directly, it will work on any browser. If you use it in a webworker, it will not work in IE11. If fact you will get an "Invalid argument" on the line : if (xhr.upload) Because IE11 doesn't seem to have this property set when XMLHttpRequest is used in a webworker.

Anybody has an idea why this happens ?

1

There are 1 answers

3
Knu On

Anybody has an idea why this happens?

That's because it was a bug, that has been fixed in the meantime.