denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.96k stars 5.39k forks source link

hope: XMLHttpRequest in deno #2191

Closed runnerSnail closed 4 years ago

MarkTiedemann commented 5 years ago

I believe XMLHttpRequest is needed for upload progress events.

Download progress can be measured with fetch already:

async function main() {
  let largeFileUrl = "http://download.inspire.net.nz/data/20MB.zip";
  let response = await fetch(largeFileUrl);
  let contentLength = parseInt(response.headers.get("Content-Length"));
  let readTotal = 0;
  let buffer = new Uint8Array(4096);
  let encoder = new TextEncoder();
  while (true) {
    let { nread, eof } = await response.body.read(buffer);
    readTotal += nread;
    let percent = ((readTotal / contentLength) * 100).toFixed(2);
    Deno.stdout.write(encoder.encode(`\r${percent}%`));
    if (eof) break;
  }
}

main();
kitsonk commented 5 years ago

I really think XMLHttpRequest is a big ole can of worms. It is a really old API with a load of crap to try to make it compatible with the browsers. IMO we really have to draw the line of "browser compatibility" somewhere.

The best thing is that is someone desired, to use the built in Deno bindings to create a polyfill in std and bring it into core if it actually worked well.

ry commented 5 years ago

I agree with @kitsonk - it would be great if we didn't support XHR.

@MarkTiedemann I believe that "progress events" are available through fetch streaming?

ry commented 4 years ago

Won’t implement

ruifortes commented 3 years ago

https://forum.rescript-lang.org/t/current-recommendations-on-fetching-data-and-promises/888/2

Ciantic commented 2 years ago

I'm having problems with WASM files generated with emscripten because it uses in JS wrapper XMLHttpRequest.

https://github.com/emscripten-core/emscripten/issues/6241