Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FileReader in macOS native apps using WebKit #613

Merged
merged 6 commits into from
Jan 31, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/FileSaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ function click (node) {
}
}

// Detect WebKit inside a native macOS app
var isWebKit = /AppleWebKit/.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)
: 'download' in HTMLAnchorElement.prototype
// Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app
: ('download' in HTMLAnchorElement.prototype && !isWebKit)
? function saveAs (blob, name, opts) {
var URL = _global.URL || _global.webkitURL
var a = document.createElement('a')
Expand Down Expand Up @@ -137,7 +140,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)) && typeof FileReader !== 'undefined') {
if (((isChromeIOS || (force && isSafari)) && typeof FileReader === 'object') || isWebKit && typeof FileReader === 'function') {
rajivshah3 marked this conversation as resolved.
Show resolved Hide resolved
// Safari doesn't allow downloading of blob URLs
var reader = new FileReader()
reader.onloadend = function () {
Expand Down