-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Support custom scheme or domain for local content on Android #1004
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Google engineers have recommended to discourage custom schemes in Android apps in this ionic webview issue, so I don't think this is something we should do in cordova-android. But maybe, as ionic webview does, intercept the requests so they load as http/https urls. That should fix some of the mentioned problems. But even that, I don't think it should be in cordova-android for now, should start as a separate plugin as cordova-plugin-wkwebview-engine and if people uses it, integrate it in cordova-android later on. |
Ah, I see, interesting. It sounds like an alternative could be to host on a custom local domain, e.g. The real motivation here is to not use |
Or maybe use
Maybe use http scheme? |
A few notes:
|
A key detail is the webview should still think the page is in a secure context, since some features are gated behind that. I'm not sure if a URL like |
Just noting that a solution like this should solve #560 ... where the current workaround is to use the ionic webview. |
Note: this may also be necessary to support JavaScript Modules (#1142). |
This PR that uses the |
Is it possible to change app://localhost to http://localhost/ on Cordova ios >6. We are facing an issue with Cross Origin because app://localhost is not a valid domain. |
Short answer is this isn't possible. On iOS the WKURLSchemeHandler is the backing API and only allows you to use a scheme that is not already registered. This means that all well known standard schemes like On Android, the WebViewAssetLoader is the backing API and it only supports setting either Your backend must either enable all domains using a wildcard for the |
Yes, we can do this but PDF embed viewer does not work with Web view [Mobile browser] if we use from hosted URL. |
This doesn't sound like a CORS issue then. The scheme urls used by the webview is only accessible by that webview instance. So if the PDF viewer for example is either a third-party application OR a cordova plugin that attempts to use native APIs to fetch that resource (including native http APIs) then those requests aren't intercepted by the webview and you don't get access to your content. It sounds like your issue is this. If you're trying to expose a local app asset, you might be able to form a On Android it should be the same, as your If it isn't, or you still have trouble, it may be worth opening a discussion at https://github.com/apache/cordova/discussions for further support. I'll be locking this thread since it's now getting off-topic and I don't want to spam the OP. |
Feature Request
As of cordova-ios 6.0.0, you can use the following in config.xml:
Then the app runs on app://localhost instead of file://. This does not appear to work on Android though - having tried it the app still runs at a file:// URL.
Motivation Behind Feature
Running on file: brings a number of origin-related problems. Notably on file:, the browser treats every resource as a different origin, causing some features to be blocked. In particular,
fetch()
cannot be used at all, because it's actually written in to the specification that it can just throw on file: protocol and that's what Chromium chooses to do.Further, this will allow Cordova Android apps to more closely align their codebases with iOS, since in both cases it can be running on the same URL (app://localhost) with identical capabilities regarding the security origin, use of
fetch()
, etc.Alternatives or Workarounds
Right now we are forced to use cordova-plugin-file to read local files, and in many cases use some ugly code involving blobs and blob URLs to work around restrictions with file: URLs. We also have to maintain two significantly different codepaths, one using
fetch()
, the other using cordova-plugin-file methods.The text was updated successfully, but these errors were encountered: