Skip to content

Commit

Permalink
fix: Refine macOS WebView check so that it is false for browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
rajivshah3 committed May 22, 2020
1 parent 648ff96 commit e5e74d6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/FileSaver.js
Expand Up @@ -66,16 +66,18 @@ function click (node) {
}
}

// Detect WebKit inside a native macOS app
var isWebKit = /AppleWebKit/.test(navigator.userAgent)
// Detect WebView inside a native macOS app by ruling out all browsers
// We just need to check for 'Safari' because all other browsers (besides Firefox) include that too
// https://www.whatismybrowser.com/guides/the-latest-user-agent/macos
var isMacOSWebView = /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.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) unless this is a native macOS app
: ('download' in HTMLAnchorElement.prototype && !isWebKit)
// Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView
: ('download' in HTMLAnchorElement.prototype && !isMacOSWebView)
? function saveAs (blob, name, opts) {
var URL = _global.URL || _global.webkitURL
var a = document.createElement('a')
Expand Down Expand Up @@ -140,7 +142,7 @@ var saveAs = _global.saveAs || (
var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari
var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent)

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

0 comments on commit e5e74d6

Please sign in to comment.