FileSaver.js icon indicating copy to clipboard operation
FileSaver.js copied to clipboard

Safari overwrites page content when saving image file

Open iprotsyuk opened this issue 10 years ago • 7 comments

I use FileSaver to save an image file. It works pretty well in all the browsers but Safari. It does allow to save an image, but it replaces a web-page where saving was called with that image. It's pretty inconvenient in case that page had a dynamic content that can't be recovered by "Back" button.

I call FileSaver the following way: saveAs(blob, name + '.png', 'image/png');

I couldn't find any workarounds, but maybe it's possible to specify somehow for Safari to open the image in a new tab, s.t. it doesn't change the current page.

iprotsyuk avatar Feb 04 '16 18:02 iprotsyuk

I didn't see this before of Safari 9 released on Monday, saw it on a website I made 2 months before.

martinschilliger avatar Mar 23 '16 12:03 martinschilliger

In the demo it opens a new window. However I can't figure out which code does it.

valtumi avatar Mar 30 '16 01:03 valtumi

I found out, that it doesn't happen every time. But I personally have no idea what triggers the difference…

martinschilliger avatar Mar 30 '16 03:03 martinschilliger

If the saveAs happens after one second from the click that triggered it. So the different is the TIME.

zerdos avatar Apr 12 '16 12:04 zerdos

@zerdos, you mean a new tab opens if saveAs is called 1 s later, or a new tab doesn't open in this case?

iprotsyuk avatar Apr 12 '16 15:04 iprotsyuk

That is exactly it, it only allows window.open() to open up a new tab if it's done by a user interaction like click event. It doesn't work by just dispatching a click event since the event has be be event.isTrusted = true

so the blob has to be made synchronous to avoid being overwritten.

I'm still curious doe if we can create a link <a href="blob:xxx-xxx" target="_blank"> and dispatch a click event that is untrusted to open up the page later.

Another option would be to open a about:blank page on a trusted event and then (if the blob is generated asynchronous and lost it's trusted value) then you could redirect that popup later It would be like opening up a download page where it's solo purpose is to be overwritten

jimmywarting avatar May 26 '16 13:05 jimmywarting

Any news?

WuglyakBolgoink avatar Jan 25 '17 16:01 WuglyakBolgoink