Skip to content

Commit e5e74d6

Browse files
committed
fix: Refine macOS WebView check so that it is false for browsers
1 parent 648ff96 commit e5e74d6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/FileSaver.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ function click (node) {
6666
}
6767
}
6868

69-
// Detect WebKit inside a native macOS app
70-
var isWebKit = /AppleWebKit/.test(navigator.userAgent)
69+
// Detect WebView inside a native macOS app by ruling out all browsers
70+
// We just need to check for 'Safari' because all other browsers (besides Firefox) include that too
71+
// https://www.whatismybrowser.com/guides/the-latest-user-agent/macos
72+
var isMacOSWebView = /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent)
7173

7274
var saveAs = _global.saveAs || (
7375
// probably in some web worker
7476
(typeof window !== 'object' || window !== _global)
7577
? function saveAs () { /* noop */ }
7678

77-
// Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app
78-
: ('download' in HTMLAnchorElement.prototype && !isWebKit)
79+
// Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView
80+
: ('download' in HTMLAnchorElement.prototype && !isMacOSWebView)
7981
? function saveAs (blob, name, opts) {
8082
var URL = _global.URL || _global.webkitURL
8183
var a = document.createElement('a')
@@ -140,7 +142,7 @@ var saveAs = _global.saveAs || (
140142
var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari
141143
var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent)
142144

143-
if ((isChromeIOS || (force && isSafari) || isWebKit) && typeof FileReader !== 'undefined') {
145+
if ((isChromeIOS || (force && isSafari) || isMacOSWebView) && typeof FileReader !== 'undefined') {
144146
// Safari doesn't allow downloading of blob URLs
145147
var reader = new FileReader()
146148
reader.onloadend = function () {

0 commit comments

Comments
 (0)