bug: Blob downloads don't work on iOS & Android
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #5498 来自 @gwdp —— 已关闭,未合并
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- java, swift, typescript
- 领域
- mobile-dev
调研方向
从 issue 中描述的 WebViewDelegationHandler 入口点开始,并在 iOS 和 Android 上运行链接的 Capacitor-Blob-Download-Issue 复现。比较 blob: 导航处理方式和平台特定的下载回调,包括 iOS 14.5 的可用性边界。完成标准是:blob 下载在报告的 iOS 和 Android 版本上正常工作,并且无错误地保存到标准目录。
由索引模型根据 Issue 内容生成。
描述
Bug Report
Capacitor Version
Latest Dependencies:
@capacitor/cli: 3.4.1
@capacitor/core: 3.4.1
@capacitor/android: 3.4.1
@capacitor/ios: 3.4.1
Installed Dependencies:
@capacitor/cli: 3.4.1
@capacitor/core: 3.4.1
@capacitor/android: 3.4.1
@capacitor/ios: 3.4.1
[success] iOS looking great! 👌
[success] Android looking great! 👌
Platform(s)
- iOS (Tested on iOS 13.x, 14.x and 15.2 )
- Android (tested on Android 11, API 29)
Current Behavior
iOS 15>= (tested on few 15.x different versions)
Whenever browser is asked to navigate to a URL such as blob:capacitor://localhost/ee26ec26-911c-461e-b01e-dd715c99e54a something like:
XX XXXX V1.1[59585:3775699] [Process] 0x15684b018 - [pageProxyID=5, webPageID=6, PID=59586] WebPageProxy::didFailProvisionalLoadForFrame: frameID = 3, domain = WebKitErrorDomain, code = 102
is printed out and nothing happens.
iOS 13.2.2, 13.0, 14.0.1 & 14.5 - (safe to assume this for 14.5 =<)
Error is different:
Failed to open URL blob:https://jimmywarting.github.io/29dbf607-c3d4-49a3-baa2-977d71cb3b80: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=247, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
Android
Nothing happens, more investigation is needed to see technical details of the implementation.
Expected Behavior
Allow that blob to be downloaded without errors into a standard download directory (as Safari does).
Maybe, an even better solution would be asking the user where to save it. (optionally)
By RFC these URLs should be handled and downloaded by the browser. More details at: https://w3c.github.io/FileAPI/#url-intro
Code Reproduction
iOS
- Download from repo and install deps: https://github.com/ikon-integration/Capacitor-Blob-Download-Issue
- Open on Xcode
npx capacitor open ios, run from there - After the app is loaded, click on the start button. (careful, button on this sample seems pretty small on the simulator, so better to zoom on the webview)
- Error should be printed on the console
Alternatively: (with any Capacitor app you might have around)
- Set your
capacitor.config.jsonserver.url tohttps://jimmywarting.github.io/StreamSaver.js/examples/saving-multiple-files.html(example) - Zoom in to be able to see the
startbutton, and click on it. - Error should be available on the console
Android
Same from iOS, however, no error is displayed and the file is not visible anywhere else on the system.
Other Technical Details
iOS
I believe this is not related to any versioning-related problem as it seems iOS 15 significantly improved the support of download/blob on the WKWebViewDelegate.
With some tweaks on the WebViewDelegationHandler, I was able to make it work and download to the downloads or documents folder seamlessly.
Android
Still, more investigation is needed on the Android side, but RFC described behaviour should also be
Additional Context
By RCF blob: URL schema should trigger the download of the URL being provided. I believe this will enhance Capacitor support to already existing apps as developers expect the same behaviour to be followed.
Possible fix
Changes on theWebViewDelegationHandler like the one below will handle it for iOS > 14.5, however still unsure where it should be saved as a default and how to allow developers to overwrite this behaviour. Another important factor is the attempt of making it to work with previous iOS versions for sure.
Creating a PR soon and linking into this issue. (Changes will be certainly be needed)
...minor changes above...
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
// post a notification for any listeners
NotificationCenter.default.post(name: .capacitorDecidePolicyForNavigationAction, object: navigationAction)
if #available(iOS 14.5, *) {
if (navigationAction.shouldPerformDownload) {
print("Is download");
decisionHandler(.download)
return;
}
}
.....
}
@available(iOS 14.5, *)
func webView(_ webView: WKWebView, navigationAction: WKNavigationAction, didBecome download: WKDownload) {
download.delegate = self;
}
@available(iOS 14.5, *)
func webView(_ webView: WKWebView, navigationResponse: WKNavigationResponse, didBecome download: WKDownload) {
download.delegate = self;
}
public func download(_ download: WKDownload, decideDestinationUsing response: URLResponse, suggestedFilename: String, completionHandler: @escaping (URL?) -> Void) {
print("decide destination", suggestedFilename);
let documentsURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let documentURL = documentsURL.appendingPathComponent(suggestedFilename, isDirectory: false)
print(documentURL.absoluteString)
completionHandler(documentURL);
}
....minor changes below....
Edited to Improve issue with reproducible code, android behaviour and other small improvements
- 主要语言
- TypeScript
- 星标
- 17.1k
- 派生
- 1.3k
- 平均合并
- 1 天 22 小时
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/capacitor 的其他 Issue
-
triage
难度 2/5 1-3 小时 新手友好度 76/100
ionic-team/capacitor#8759 ·
维护者通常 1 天内回复
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updated可能已有人在做 @MateStrysewske 于 71 天前认领。 未关闭triage
难度 2/5 1-3 小时 新手友好度 84/100
ionic-team/capacitor#8616 ·
维护者通常 1 天内回复
-
help wanted
难度 2/5 1-3 小时 新手友好度 68/100
ionic-team/capacitor#8574 · 3 条评论 ·
维护者通常 1 天内回复
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)可能已有人在做 @kttalley 于 62 天前认领。 未关闭triage
难度 2/5 1-3 小时 新手友好度 78/100
ionic-team/capacitor#8530 · 2 条评论 ·
维护者通常 1 天内回复
-
fix(android): remove unchecked Java compilation warnings可能已有人在做 @Ajamuar 于 15 天前认领。 未关闭triage
难度 2/5 1-3 小时 新手友好度 78/100
ionic-team/capacitor#8529 · 1 条评论 ·
维护者通常 1 天内回复
查看 ionic-team/capacitor 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
prio:low scope:world
难度 2/5 1-3 小时 新手友好度 83/100
OliverRomhagen/vrigstad-joyride#849 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
genfeedai/genfeed.ai#11916 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
erkamyaman/rust-anything#1153 ·
维护者通常 1 天内回复
-
The Phase 5 report says 0.3.0 waits for the live check可能已有人在做 @fzn0x 今天认领。 未关闭documentation
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复