ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.21k stars 1.01k forks source link

[iOS|Android] WebView events delegation #1298

Open sandervandenbrink opened 5 years ago

sandervandenbrink commented 5 years ago

In Android the Bridge class and in iOS the Bridge View Controller don't delegate the WebView events. I'm using Capacitor to fetch the web app remotely and if loading of the client fails (e.g. timeout or host not found) then there is no way to handle this with for example a screen that informs the user.

Perhaps an idea would be to have a listener/delegate property available in the Android Bridge class and the iOS CAPBridgeViewController that can optionally be set before the webview is being loaded.

Additionally I noticed that the WKWebView reload won't work if the initial load of the web client failed (because the url will be nil) so it would be convenient if the CAPBridgeViewController has a public load/reload method that uses the url from the config.

I don't have any other use cases than the error methods webView(_:didFailProvisionalNavigation:withError:) and onReceivedError (Note that this one is deprecated since API 23), so I'm not sure whether it's necessary to delegate more or all the webview events.

mlynch commented 5 years ago

Makes sense. We can add this to our list of tasks for making Capacitor work well embedded in existing native apps (where you're managing the instance of the bridge)