For those who use flutter, I get the same error on webview_flutter
, flutter_inappwebview
and flutter_webview_plugin
which I thought its from the package so I tried different things. However, in my case I was trying to open customer scheme URL to use it to open the app which is something like appname://code=xxx...
and the WKWebView
won't allow you to open it, but on Android it will be opened but you'll get some error message.
It was working fine on flutter_webview_plugin
cause it does provider onUrlChange
listener which will intercept the call before loading it and allow you to do what you want with it... for me, I closed the webview and used url_luncher
.
To do the same thing on webview_flutter
you should use the navigationDelegate
option to allow opening the URL or not, as follows:
WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: url,
navigationDelegate: (x) {
if(x.url.toString().toLowerCase().startsWith('appname://')){
//close webview and do something
// prevent open the url
return NavigationDecision.prevent;
}
else return NavigationDecision.navigate;
},
For flutter_inappwebview
there is an option they mention on the official doc
... I didn't try it cause webview_flutter
did work... but I suppose it does the same thing
resourceCustomSchemes: List of custom schemes that the WebView must handle. Use the WebView.onLoadResourceCustomScheme event to intercept resource requests with custom scheme.