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

Conversation

rajivshah3
Copy link
Contributor

In a macOS native app that uses WebKit, calling saveAs on a Blob attempts to open the blob URL. This results in a message that says There is no application set to open the URL blob:http... (see iotaledger/spark-wallet#89 (comment)).

As in Safari, the FileReader API should be used. However, changes need to be made to the browser detection because of a few differences between Safari and WebKit:

  • HTMLAnchorElement.download is defined
  • typeof FileReader returns 'function' instead of 'object'

With these changes, the expected behavior is achieved:

image

Fixes #509

@Floriferous
Copy link

I have a similar issue where HTMLAnchorElement itself is undefined in a node test environment, could we also first check if it exists before trying to access its prototype?

Like this:
HTMLAnchorElement && !isWebKit && ('download' in HTMLAnchorElement.prototype)

I suggest the isWebkit check is done before trying to find 'download', as isWebKit is a boolean that has already been calculated, so no need to perform the in operation if it is not needed.

@jdeanquin-dg
Copy link

I have a similar issue where HTMLAnchorElement itself is undefined in a node test environment, could we also first check if it exists before trying to access its prototype?

Like this:
HTMLAnchorElement && !isWebKit && ('download' in HTMLAnchorElement.prototype)

I suggest the isWebkit check is done before trying to find 'download', as isWebKit is a boolean that has already been calculated, so no need to perform the in operation if it is not needed.

Hello @Floriferous I have submitted a PR to fix the problem in node environments since my tests were failing even if not trying to test FileSaver at all #620 620

Copy link
Owner

@eligrey eligrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍 - I will merge your changes once you bump the version

src/FileSaver.js Outdated Show resolved Hide resolved
@rajivshah3
Copy link
Contributor Author

@eligrey will do. Do you want me to rebuild the dist as well?

@eligrey
Copy link
Owner

eligrey commented Jan 31, 2020

Yeah, you should also re-build dist.

Make sure that you also maintain compatibility with iOS as per #577. I don't have an iOS device to test.

Thanks for taking the time to PR!

@rajivshah3
Copy link
Contributor Author

@eligrey just tested, still works on iOS Chrome

Using isWebKit before isSafari could cause Safari to use FileReader even if force === false, since the user agent for Safari also includes AppleWebKit
@eligrey eligrey merged commit 648ff96 into eligrey:master Jan 31, 2020
@rajivshah3 rajivshah3 deleted the feature/webkit-macos branch January 31, 2020 00:46
rajivshah3 added a commit to iotaledger/spark-wallet that referenced this pull request Jan 31, 2020
Includes eligrey/FileSaver.js#613, which fixes an issue on macOS when exporting SeedVaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot save files on Outlook Mac
4 participants