Cannot use custom URL scheme in embedded Web view
- Dominant language
- JavaScript
- Stars
- 2.2k
- Forks
- 1k
- Avg merge
- 12h 11m
- Merged PRs (30d)
- 18
Description
cordova-ios 6.2.0
I followed the instructions at (https://cordova.apache.org/docs/en/11.x/guide/platforms/ios/webview.html) on embedding a Cordova Web view into a Swift project. I used Carthage, and added the xcframework to my project. It all works, but with the default file protocol. I need the secure context, though, so I tried adding a custom scheme to the config.xml:
```
```
This results in a blank screen, with about:blank as the location.
My view controller doesn't do anything special, it just inherits CDVViewController.
```
class CordovaWebViewController: CDVViewController {
}
```
So I stepped through the `CDVWebViewEngine` code, and found that the URL being loaded is app://localhost/index.html. So far so good, but we never actually load that URL. Eventually we get to `CDVWebViewEngine.decidePolicyForNavigationAction`, which ultimately sends a `CDVPluginHandleOpenURLNotification`. This is handled by the `CDVHandleOpenURL` plugin, which wasn't being loaded automatically. This was suspicious - am I on the wrong track?
Anyway, I added it to the config.xml manually, and added some NSLogs to that plugin to make sure it loads. The logs revealed that the plugin's `applicationLaunchedWithUrl` is being called (with the correct URL), but it does nothing because `self.pageLoaded` is `NO`. At this point I'm a bit lost, because I don't understand how we expect the page to be loaded when we're in the process of loading it.
Any help would be appreciated. Thanks.
Contributor guide
Research direction
Start by reproducing the embedded Web view setup from the issue, then trace CDVWebViewEngine.decidePolicyForNavigationAction and the CDVHandleOpenURL applicationLaunchedWithUrl path. Check config.xml and CDVViewController initialization to understand the custom scheme lifecycle; done means the app://localhost/index.html page loads instead of showing a blank about:blank view.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, javascript, objective-c, swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100