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>
Status: RESOLVED CONFIGURATION CHANGED    
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:    
Attachments:
Description Flags
screenshot none

Thomas Steiner
Reported 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/.
Attachments
screenshot (60.35 KB, image/jpeg)
2024-01-25 03:42 PST, glebmatveev
no flags
Radar WebKit Bug Importer
Comment 1 2020-09-24 05:22:14 PDT
youenn fablet
Comment 2 2021-01-08 07:12:59 PST
*** Bug 220461 has been marked as a duplicate of this bug. ***
felek.000
Comment 3 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 ?
karl
Comment 4 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.
Gleb Khmyznikov
Comment 5 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.
sh-a-v
Comment 6 2021-09-29 06:18:13 PDT
The same bug is now in the main Safari.
dmt021
Comment 7 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
Anne van Kesteren
Comment 8 2024-01-08 02:22:47 PST
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?
Thomas Steiner
Comment 9 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… :-)
Anne van Kesteren
Comment 10 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.
glebmatveev
Comment 11 2024-01-25 03:42:32 PST
Created attachment 469545 [details] screenshot
glebmatveev
Comment 12 2024-01-25 03:43:40 PST
The file is detected as Unknown and is not saved correctly.
glebmatveev
Comment 13 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. https://prnt.sc/pusMQfiLEgWz 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.
Karl Dubost
Comment 14 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. https://github.com/mozilla-mobile/firefox-ios/issues
Note You need to log in before you can comment on or make changes to this bug.