Skip to content

Commit

Permalink
Use FileReader in macOS native apps using WebKit (#613)
Browse files Browse the repository at this point in the history
Use FileReader in macOS native apps using WebKit
  • Loading branch information
eligrey committed Jan 31, 2020
2 parents 480d547 + 7a8ff3c commit 648ff96
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
10 changes: 6 additions & 4 deletions dist/FileSaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
node.dispatchEvent(evt);
}
}
} // Detect WebKit inside a native macOS app


var isWebKit = /AppleWebKit/.test(navigator.userAgent);
var saveAs = _global.saveAs || ( // probably in some web worker
typeof window !== 'object' || window !== _global ? function saveAs() {}
/* noop */
// Use download attribute first if possible (#193 Lumia mobile)
: 'download' in HTMLAnchorElement.prototype ? function saveAs(blob, name, opts) {
// Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app
: 'download' in HTMLAnchorElement.prototype && !isWebKit ? function saveAs(blob, name, opts) {
var URL = _global.URL || _global.webkitURL;
var a = document.createElement('a');
name = name || blob.name || 'download';
Expand Down Expand Up @@ -153,7 +155,7 @@

var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent);

if ((isChromeIOS || force && isSafari) && typeof FileReader !== 'undefined') {
if ((isChromeIOS || force && isSafari || isWebKit) && typeof FileReader !== 'undefined') {
// Safari doesn't allow downloading of blob URLs
var reader = new FileReader();

Expand Down
2 changes: 1 addition & 1 deletion dist/FileSaver.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 648ff96

Please sign in to comment.