crosswalk-project / crosswalk-ios

Crosswalk Project for iOS
https://crosswalk-project.org/
BSD 3-Clause "New" or "Revised" License
117 stars 77 forks source link

CORS - XMLHttpRequest cannot load file:/// URIs #69

Open rayshan opened 8 years ago

rayshan commented 8 years ago

大家好,

Seems like WKWebView in iOS 8 doesn't support loading content via XMLHttpRequest due to CORS enforcement. In iOS 9 maybe [WKWebView loadFileURL:allowingReadAccessToURL:] can work (reference). I just tried crosswalk-ios 1.2 in iOS 9 and hit this error. Any ideas of how to load local files via files:/// protocol?

jondong commented 8 years ago

@rayshan Thanks for trying Crosswalk. The implementation of [XWalkView loadFileURL:allowingReadAccessToURL:] in iOS 9 is to hook up WKWebView's same api, so it should behave the same as WKWebView. Would you please elaborate or paste your error log here for us to identify the issue? That would be really helpful.

Meanwhile, according to http://www.w3.org/TR/url/#concept-url-scheme, the scheme files:/// is not supported, is it a typo?

rayshan commented 8 years ago

My pleasure! No files:/// isn't a typo. This is the error message:

XMLHttpRequest cannot load file:///Users/rayshan/Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/crosswalk.app/www/package.json. Cross origin requests are only supported for HTTP.

I think this is a known issue with WKWebView, and the only workaround I can find is to spin up a local server to serve local resources via http. I believe it's the same issue as these: https://github.com/Telerik-Verified-Plugins/WKWebView/issues/149 https://issues.apache.org/jira/browse/CB-10143