I have a NS 8.6 Core application in which I have a screen where I host a WebView. The webview displays google.com. where the user can search for some term. I monitor the loadFinished event to capture the URL the user selected. This all works well in iOS, but in Android sometimes, if the user taps on a link inside the webview, the webview tries to navigate to a url of the following format:
file:///data/data/com.<app id>.<app id>/files/app/
My question is: is there a way to detect a URL that starts with 'file:///' and cancel the navigation?
I tried this in the onLoadStarted event handler:
if (isAndroid) {
if (e.url.startsWith('file:///')) {
wv.stopLoading();
if (wv.canGoBack) {
wv.goBack();
}
}
}
but this only causes it to bounce back and forth between the original url and 'file:///' one. If I just call stopLoading(), the webview displays a blank screen.
I also tried a few other plugins like nativescript-webview-ext, for example, that had what I am looking for, but I cannot make them even load in my app. Their repos are a few years old at least and do not seem to have any active support.
Is there a way to cancel a navigation before it starts? I am looking for something like the shouldOverrideUrlLoading event (available in nativescript-webview-ext) that provides the ability to cancel the navigation before it begins.
Thank you.