Skip to content

Commit db78801

Browse files
committed
Use FileReader in macOS native apps using WebKit
1 parent 9a0a1e4 commit db78801

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/FileSaver.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ function click (node) {
6666
}
6767
}
6868

69+
// Detect WebKit inside a native macOS app
70+
var isWebKit = /AppleWebKit/.test(navigator.userAgent)
71+
6972
var saveAs = _global.saveAs || (
7073
// probably in some web worker
7174
(typeof window !== 'object' || window !== _global)
7275
? function saveAs () { /* noop */ }
7376

74-
// Use download attribute first if possible (#193 Lumia mobile)
75-
: 'download' in HTMLAnchorElement.prototype
77+
// Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app
78+
: ('download' in HTMLAnchorElement.prototype && !isWebKit)
7679
? function saveAs (blob, name, opts) {
7780
var URL = _global.URL || _global.webkitURL
7881
var a = document.createElement('a')
@@ -137,7 +140,7 @@ var saveAs = _global.saveAs || (
137140
var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari
138141
var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent)
139142

140-
if ((isChromeIOS || (force && isSafari)) && typeof FileReader !== 'undefined') {
143+
if (((isChromeIOS || (force && isSafari)) && typeof FileReader === 'object') || isWebKit && typeof FileReader === 'function') {
141144
// Safari doesn't allow downloading of blob URLs
142145
var reader = new FileReader()
143146
reader.onloadend = function () {

0 commit comments

Comments
 (0)