eligrey / eligrey/FileSaver.js
cors detection not working in MS Edge
- Dominant language
- JavaScript
- Stars
- 22k
- Forks
- 4.3k
- PR merge metrics
- No merged PRs in 30d
Description
Using FileSaver.js 2.0.4.
I think this is going to be an "Edge" case but I'm having an issue where `download("...")` fails in MS Edge with a CORS error before it even gets into `saveAs()`.
From the browser console:
```
download("[...REDACTED...]")
Access to XMLHttpRequest at '[...REDACTED...]' from origin 'http://suro.test' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
FileSaver.js:42 could not download file
xhr.onerror @ FileSaver.js:42
error (async)
download @ FileSaver.js:41
(anonymous) @ VM3573:1
FileSaver.js:44 GET [...REDACTED...] net::ERR_FAILED
```
I believe I traced the issue to what I'm fairly certain is [a bug in Edge](https://stackoverflow.com/questions/67530674/cors-blocked-in-ms-edge-but-works-in-all-other-browsers/67530675#67530675) but it struck me that FileSaver performs a CORS check and has alternative methods of downloading a file if it fails so this ideally shouldn't have failed.
It seems like you could perform the CORS check sooner and pass `url` to `saveAs` instead of the `xhr.response` if the CORS fails.
Am I way off? Should I just go to bed? Thanks for listening! I'm sure I could find some time to make a PR tomorrow or this weekend if the above sounds like it makes sense.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.