[TIMOB-27159] iOS: Ti.UI.WebView cannot load html files from cache
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-01-30T21:11:45.000+0000 |
Affected Version/s | Release 8.0.0 |
Fix Version/s | Release 9.0.0 |
Components | iOS |
Labels | 8.0.0, engSchedule, ios, webview |
Reporter | Nikos Poulios |
Assignee | Vijay Singh |
Created | 2019-05-09T09:18:49.000+0000 |
Updated | 2020-01-30T21:11:45.000+0000 |
Description
*Note: Issue can be reproduced only on device, webview works as expected on simulator*
New WebView fails to load html files stored in the app with the error:
default 11:34:49.407006 +0300 com.apple.WebKit.Networking 0x1075e8000 - NetworkResourceLoader::startNetworkLoad: (pageID = 5, frameID = 1, resourceID = 1, isMainResource = 1, isSynchronous = 0)
default 11:34:49.407054 +0300 com.apple.WebKit.Networking Task <0AF948FB-871A-4EDD-A632-D67CBB10B3BC>.<1> resuming, QOS(0x19)
default 11:34:49.407103 +0300 com.apple.WebKit.Networking [Telemetry]: Activity <nw_activity 16:2 [3A7E50A1-6DED-43AC-8750-A3865F7FCB48] (reporting strategy default)> on Task <0AF948FB-871A-4EDD-A632-D67CBB10B3BC>.<1> was not selected for reporting
error 11:34:49.407332 +0300 kernel Sandbox: com.apple.WebKit(10340) deny(1) file-read-data /private/var/mobile/Containers/Data/Application/B7D5C2EF-634E-4F7E-A7EC-BAB4DDF48868/Library/Caches/307/platform_article_1112110663/article.html
default 11:34:49.407402 +0300 com.apple.WebKit.Networking 0x1075e8000 - NetworkResourceLoader::startNetworkLoad: (pageID = 5, frameID = 1, resourceID = 1, description = LocalDataTask <0AF948FB-871A-4EDD-A632-D67CBB10B3BC>.<1>)
error 11:34:49.407557 +0300 com.apple.WebKit.Networking Task <0AF948FB-871A-4EDD-A632-D67CBB10B3BC>.<1> finished with error - code: 1
error 11:34:49.407608 +0300 com.apple.WebKit.Networking Task <0AF948FB-871A-4EDD-A632-D67CBB10B3BC>.<1> load failed with error Error Domain=kCFErrorDomainCFNetwork Code=1 UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=<private>, _NSURLErrorFailingURLSessionTaskErrorKey=<private>} [1]
default 11:34:49.408142 +0300 com.apple.WebKit.Networking 0x1075e8000 - NetworkResourceLoader::didFailLoading: (pageID = 5, frameID = 1, resourceID = 1, isTimeout = 0, isCancellation = 0, isAccessControl = 0, errCode = 1)
Reading iOS documentation I noticed that local files should be loaded using *loadFileURL* method as in https://github.com/appcelerator-modules/Ti.WKWebView/blob/master/ios/Classes/TiWkwebviewWebView.m#L198 but I don't see that in https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiUIWebView.m#L664
Attachments
File | Date | Size |
---|---|---|
Resources.zip | 2019-06-10T13:03:35.000+0000 | 2259 |
[~nipoul] Can you give a test case for mentioned issue? Thanks!
Hi, Sorry for the delay, I uploaded a test case. It turns out issue exists when trying to access a file stored in app's Cache directory. As you can see I have 3 cases:
When html and css file are on resources everything is ok, setting url to a path under Cache fails, and setHtml using file.read from cache works but again css fails to load. Again the only workaround working is using setHtml and referring to css by absolute path in resources. Is this an iOS restriction? Is there any workaround to have html in cache and use relative paths for css files? I tried using the code below in the SDK and it works but again allowingReadAccessToURL is fixed so it's not proper solution, ideally it would be set similarly to baseURL param in setHtml
Thank you in advance
Thanks for test case [~nipoul]. Webkit has restricted more on local file loading via WKWebView. Apple has given new API in WKWebView as mentioned in above comment [- (WKNavigation *)loadFileURL:(NSURL *)URL allowingReadAccessToURL:(NSURL *)readAccessURL](https://developer.apple.com/documentation/webkit/wkwebview/1414973-loadfileurl?language=objc). I think we should expose new API for local file Urls- setFileUrl({ url: "local file url", readAccessUrl: "read access file url" }) [~jquick] What you think? Thanks!
[~vijaysingh], this sounds like a security feature on Apple's end. Particularly for MacOS where they don't want some rogue local HTML file having full filesystem access via a file:// scheme... and iOS inherited it. Android's
WebView
doesn't have an equivalent to theallowingReadAccessToURL
API. Do we need to add a new API? What if we were to automatically assign theallowingReadAccessToURL
to the given HTML file's directory path?If possible It would be nice to be able to set allowingReadAccessToURL actually, so that assets like css files can be shared between files in cache using relative paths
https://github.com/appcelerator/titanium_mobile/pull/10976 Test Case -
FR passed.please provide PR for 8_3_X
While the FR may have passed, the unit tests for WebView are repeatedly failing for this PR. As such, I've bumped that back to failed QE/review. 4 WebView tests are timing out on this PR, and have been after several builds on Jenkins.
It looks like iOS 13 broken WKWebView's API - (nullable WKNavigation *)loadFileURL:(NSURL *)URL allowingReadAccessToURL:(NSURL *)readAccessURL. See discussion https://forums.developer.apple.com/thread/120566 In iOS 12 it is working fine.
PR - https://github.com/appcelerator/titanium_mobile/pull/11431
FR Passed, Waiting on Jenkins build
merged to master for 9.0.0
Verified the fix with SDK 9.0.0.v20200130075800. Closing.