eligrey / FileSaver.js

An HTML5 saveAs() FileSaver implementation
https://eligrey.com/blog/saving-generated-files-on-the-client-side/
Other
21.65k stars 4.38k forks source link

corsEnabled uses deprecated synchronous xhr #655

Open zxubian opened 4 years ago

zxubian commented 4 years ago

Starting in Firefox 30, synchronous requests on the main thread have been deprecated due to their negative impact on performance and the user experience. Therefore, the async parameter may not be false except in a Worker.

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open

From FileSaver.js:

function corsEnabled (url, opts) {
  var xhr = new XMLHttpRequest()
  // use sync to avoid popup blocker
  xhr.open('HEAD', url, false)
  try {
    xhr.send()
  } catch (e) {}
  return xhr.status >= 200 && xhr.status <= 299
}
alekstar79 commented 4 years ago

Yes, Chrome also swears on Synchronous XMLHttpRequest.

[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

priley86 commented 4 years ago

Will passing xhr.open('HEAD', url, true) fix the issue? It may be worth forking this package...

igneosaur commented 3 years ago

Yeh, using xhr.open('HEAD', url); does fix the issue. However it does seem like the synchronous event was used deliberately to avoid popup blockers.

igneosaur commented 3 years ago

I guess there won't be a choice soon.