Skip to content

Commit 5bb701b

Browse files
authored
Merge pull request #652 from rajivshah3/fix/only-macos-webview
2 parents 648ff96 + 43bbd2f commit 5bb701b

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

dist/FileSaver.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@
8383
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
8484
node.dispatchEvent(evt);
8585
}
86-
} // Detect WebKit inside a native macOS app
86+
} // Detect WebView inside a native macOS app by ruling out all browsers
87+
// We just need to check for 'Safari' because all other browsers (besides Firefox) include that too
88+
// https://www.whatismybrowser.com/guides/the-latest-user-agent/macos
8789

8890

89-
var isWebKit = /AppleWebKit/.test(navigator.userAgent);
91+
var isMacOSWebView = /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent);
9092
var saveAs = _global.saveAs || ( // probably in some web worker
9193
typeof window !== 'object' || window !== _global ? function saveAs() {}
9294
/* noop */
93-
// Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app
94-
: 'download' in HTMLAnchorElement.prototype && !isWebKit ? function saveAs(blob, name, opts) {
95+
// Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView
96+
: 'download' in HTMLAnchorElement.prototype && !isMacOSWebView ? function saveAs(blob, name, opts) {
9597
var URL = _global.URL || _global.webkitURL;
9698
var a = document.createElement('a');
9799
name = name || blob.name || 'download';
@@ -155,7 +157,7 @@
155157

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

158-
if ((isChromeIOS || force && isSafari || isWebKit) && typeof FileReader !== 'undefined') {
160+
if ((isChromeIOS || force && isSafari || isMacOSWebView) && typeof FileReader !== 'undefined') {
159161
// Safari doesn't allow downloading of blob URLs
160162
var reader = new FileReader();
161163

dist/FileSaver.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/FileSaver.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "file-saver",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "An HTML5 saveAs() FileSaver implementation",
55
"main": "dist/FileSaver.min.js",
66
"files": [

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)