Skip to content

Commit f397f3d

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

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/FileSaver.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,19 @@ 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) &&
73+
&& !/Safari/.test(navigator.userAgent)
7174

7275
var saveAs = _global.saveAs || (
7376
// probably in some web worker
7477
(typeof window !== 'object' || window !== _global)
7578
? function saveAs () { /* noop */ }
7679

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

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

0 commit comments

Comments
 (0)