download attribute not working in pinned tab

In Safari 11/12, I have an tag with href="data:" and attribute "download" to save the file when the link is clicked.

<!DOCTYPE html>

<html><body>

<a href="data:text/plain;charset=utf-8,Hello" download="hello.txt">

Download me

</a>

</body></html>


This works fine in an unpinned tab in Safari. Clicking on the link downloads the text "Hello" into a new file called hello.txt. However, in a pinned tab in Safari, the download attribute seems to be ignored and Safari opens the data in a new tab.

To see this you need to serve the above HTML code from a web server. If you just save the file and open it with a "file://" URL, it works as expected.


I have tried using a Blob instead but the behaviour was the same.

I have tried changing the mimeType to "application/octet-stream", which was a suggestion I found to a similar question. This does cause the data to be downloaded, but the filename is always "unknown.txt". This isn't suitable as I need to have control over the filename and extension (it's not hello.txt!)


As an extra note, the behaviour is actually different in Safari 11 and 12, but neither is working properly.

In 11, a new tab is opened showing the text.

In 12, it opens a new tab but this shows an error WebKitBlobResource error 1.


This looks like a bug in Safari to me. Can anyone suggest a workaround?


Thanks