3

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 ?

kamel B
  • 303
  • 1
  • 3
  • 9
  • Did you use exactly this code? Could it be that xhr is declared in the wrong scope when you use it in a webworker? Can you show the full(er) code including the webworker? – GolezTrol Sep 07 '15 at 09:49
  • Yes GolezTrol it's the exact code. I updated my post with all details of my implementation. – kamel B Sep 07 '15 at 14:43

1 Answers1

1

Anybody has an idea why this happens?

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

Knu
  • 14,806
  • 5
  • 56
  • 89