Bug 216918

Summary: WKWebView does not support `blob:` URLs as `href` value in anchors with `download` attribute
Product: WebKit Reporter: Thomas Steiner <tomac>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Severity: Normal CC: adam, ajuma, annevk, cdumez, ddkilzer, dmt021, felek.000, gleb.khmyznikov, glebmatveev, karlcow, karl+webkit, mrskman, shershnev.av, uwolfer, vladislavitsi, webkit-bug-importer, xfortin
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=226440
Bug Depends on: 167341    
Bug Blocks:    
Description Flags
screenshot none

Description Thomas Steiner 2020-09-24 01:32:33 PDT
I just realized that the `download` attribute doesn't work with blob: URLs in WKWebView. In contrast, data: URLs work there. Is this on purpose? Both methods work correctly in Safari itself. Here's a small demo: https://wkwebview-download.glitch.me/.
Comment 1 Radar WebKit Bug Importer 2020-09-24 05:22:14 PDT
Comment 2 youenn fablet 2021-01-08 07:12:59 PST
*** Bug 220461 has been marked as a duplicate of this bug. ***
Comment 3 felek.000 2021-01-20 23:25:36 PST
Hello i have similar problem (IPad,Mac) on Chrome mac working ipad not. When i store files in indexDB(for offline) as blob. Then i want to open them in browser as new tab.Its not working shows only info WebKitBlobResource error 1. I try window.open(blob), also in js create and click and its not works in any browser. Any solution for this problem ?
Comment 4 karl 2021-06-13 17:48:42 PDT
This issue creates webcompat issues for Firefox on iOS. 

* https://github.com/webcompat/web-bugs/issues/75388
* https://github.com/webcompat/web-bugs/issues/75965

That would be great to fix it.
Comment 5 Gleb Khmyznikov 2021-09-29 05:46:06 PDT
We really miss this feature. It's a shame that Safari is always a step behind other browsers.
Comment 6 sh-a-v 2021-09-29 06:18:13 PDT
The same bug is now in the main Safari.
Comment 7 dmt021 2023-02-07 06:30:26 PST
Any plans to fix this?
The issue is getting worse as there are not really good scripts for saving files across different browsers, like https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js#L146-L147
Comment 8 Anne van Kesteren 2024-01-08 02:22:47 PST
When I try

<a download=test>test</a><script>
document.querySelector("a").href = URL.createObjectURL(new Blob());

on macOS and iOS Safari it downloads as expected.


What are the steps to reproduce?
Comment 9 Thomas Steiner 2024-01-08 02:30:06 PST
The problem occurred in `WKWebView`-based browsers like Chrome on iOS. I just tested on 17.3 beta, and it worked just fine. I'm marking this as RESOLVED. Not sure when this started working, but it does… :-)
Comment 10 Anne van Kesteren 2024-01-08 03:00:19 PST
CONFIGURATION CHANGED is used when it's unclear where the fix happened.

And note that comment 6 implied the problem was universal, though maybe it was at the time.
Comment 11 glebmatveev 2024-01-25 03:42:32 PST
Created attachment 469545 [details]
Comment 12 glebmatveev 2024-01-25 03:43:40 PST
The file is detected as Unknown and is not saved correctly.
Comment 13 glebmatveev 2024-01-25 03:46:20 PST
(In reply to Anne van Kesteren from comment #8)
> When I try
> <a download=test>test</a><script>
> document.querySelector("a").href = URL.createObjectURL(new Blob());
> </script>
> on macOS and iOS Safari it downloads as expected.
> https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!
> DOCTYPE%20html%3E%0A...
> %3Ca%20download%3Dtest%3Etest%3C%2Fa%3E%3Cscript%3E%0Adocument.
> querySelector(%22a%22).href%20%3D%20URL.
> createObjectURL(new%20Blob())%3B%0A%3C%2Fscript%3E
> What are the steps to reproduce?

Unfortunately, the problem is still relevant.
You can reproduce the problem in the Firefox browser on iOS with your example.
When I click on the link, a save file dialog box appears, but the file is detected as Unknown and is not saved correctly.


I set the Download attribute in the tag and in the code, but it doesn't work. The file is still defined as Annone.

However, the problem is not observed in Safari and Chrome.
Comment 14 Karl Dubost 2024-01-25 03:55:17 PST
Chrome on iOS and Firefox on iOS are basically using the same thing. So if there is a difference something is happening elsewhere.

It would be interesting to understand why there is a difference. 

Note that Firefox iOS has a specific repo for their own issue.