Nativescript: onReceivedSslError in Android WebView doesn't works

Created on 12 Jun 2020  路  7Comments  路  Source: NativeScript/NativeScript

Environment

  • CLI: 6.5.0
  • Cross-platform modules: 6.5.1
  • Android Runtime: 6.5.0
  • iOS Runtime: 6.5.0
  • Plugin(s): -
  • Node.js: v12.16.1

Describe the bug

onReceivedSslError on WebClient implementation was not fired.

I got some experience about this issue, and results I can't understand.

  1. I use WebClientSSLImplementation which extends WebClient, overwriting onReceivedSslError. repos
export class WebViewClientSslImpl extends android.webkit.WebViewClient {

    constructor(public owner: any) {
        super();
        return global.__native(this);
    }
    // ...
    public onReceivedSslError(view: any, handler: any, error: any) {
        handler.proceed();
        console.log('ssl error')
    }
};
export function onWebViewLoaded(args: EventData) {
    let wv = <WebView>args.object;
    const clientWithSsl = new WebViewClientSslImpl(wv);
    const androidWebView = <android.webkit.WebView>wv.android;
    androidWebView.setWebViewClient(clientWithSsl);
}



md5-88b037f472ac8fc799179b43de267b5a



Webpack compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (android)
Start sending initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-....).
Successfully sent initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-....).
LOG from device Galaxy A8 Star: HMR: Hot Module Replacement Enabled. Waiting for signal.
LOG from device Galaxy A8 Star: https://192.168.0.6:50468
LOG from device Galaxy A8 Star: ssl error
LOG from device Galaxy A8 Star: https://192.168.0.6:9999
LOG from device Galaxy A8 Star: ssl error
LOG from device Galaxy A8 Star: ssl error



md5-d709d4a98e8c73ab23e85e66c015167a



Preparing project...
Project successfully prepared (android)
Start sending initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-....).
Successfully sent initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-....).
LOG from device Galaxy A8 Star: HMR: Hot Module Replacement Enabled. Waiting for signal.
LOG from device Galaxy A8 Star: https://192.168.0.8:9999
LOG from device Galaxy A8 Star: https://192.168.0.8:50468



md5-059ccb628b9abbf6d8451f78e5143607



An uncaught Exception occurred on "main" thread.
Calling js method onReceivedError failed
Error: JNI Exception occurred (SIGABRT).
=======
Check the 'adb logcat' for additional information about the error.
=======


StackTrace:
module.exports.push../web-view.ts.WebViewClientSslImpl.onReceivedError(file:///data/data/org.nativescript.remoteextendswebviewclient/files/app/bundle.js:334:46)
    at com.tns.Runtime.callJSMethodNative(Native Method)
    at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
    at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
    at com.tns.Runtime.callJSMethod(Runtime.java:1160)
    at com.tns.Runtime.callJSMethod(Runtime.java:1138)
    at com.tns.Runtime.callJSMethod(Runtime.java:1134)
    at com.tns.gen.android.webkit.WebViewClient_bundle_297_28_WebViewClientSslImpl.onReceivedError(WebViewClient_bundle_297_28_WebViewClientSslImpl.java:72)
    at Ox0.handleMessage(chromium-Monochrome.aab-stable-410410173:134)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)



md5-2d4a85fe052f623d887379e2c3aab9e5



import { WebViewClientSslImpl } from "./web-view";

export class HelloWorldModel extends Observable {
    public webviewclient: WebViewClientSslImpl;
    // ...



md5-b17fd6defde3d4503304df438d829239



export function onWebViewLoaded(args: EventData) {
    let wv = <WebView>args.object;
    const context = wv.page.bindingContext
    const clientWithSsl = new WebViewClientSslImpl(wv);
    context.set('webviewclient', clientWithSsl)

    const androidWebView = <android.webkit.WebView>wv.android;
    androidWebView.setWebViewClient(context.webviewclient);
}



md5-bb64b38ac4c2cdb858f01c99c04ede10



Webpack compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (android)
Start sending initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-....).
Successfully sent initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-....).
LOG from device Galaxy A8 Star: https://www.naver.com
LOG from device Galaxy A8 Star: https://192.168.0.6:50468
LOG from device Galaxy A8 Star: ssl error



md5-b17fd6defde3d4503304df438d829239



Webpack compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (android)
Start sending initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-33b010505c29).
Successfully sent initial files for device Galaxy A8 Star (7e85afcb-....-463a-b991-33b010505c29).
LOG from device Galaxy A8 Star: https://www.naver.com
LOG from device Galaxy A8 Star: https://192.168.0.8:50468

what should I have to do to figure this out?

To Reproduce

tns preview or
tns build android

Expected behavior

onReceivedSslError should be fired.

Sample project

repos

Additional context

I build with nativescript-remote-builds.

_Originally posted by @cybaj in https://github.com/NativeScript/NativeScript/issues/3998#issuecomment-643160476_

Most helpful comment

Hi @cybaj
Thank you for reporting this issue.
I am going to try and replicate this case on my end and will confirm if onReceivedSslError in Android WebView doesn't works.
We will research what is causing this issue and will provide the needed fix. For further info, you could keep track the issue.

All 7 comments

Hi @cybaj
Thank you for reporting this issue.
I am going to try and replicate this case on my end and will confirm if onReceivedSslError in Android WebView doesn't works.
We will research what is causing this issue and will provide the needed fix. For further info, you could keep track the issue.

Is this related to not being able to open notion.so on Android?

@diegovincent I don't know.

  1. not being able to open notion.so on Android Webview
  2. but I think there must be some valid certificate at notion.so
    ... is anyone who guess what's going on?

My best guess was that, due to marketing purposes, they put an iframe in their page that gets information from another domain, and they send some HTTP headers that do not like that behavior.

Because on Android, for security, they block those kind of requests. And I鈥檝e even seen people on Android forums intercepting the request and patching the header out, but I am confident there must be something that can be done.

I had some information stored, ironically, in Notion. I can post it here in a few days.

We managed to fix the Notion "bug" on Android. Our solution is based on using theloaded event to enable dom storage manually when using Android.

<WebView (loaded)="onLoaded($event)"></WebView>
function onLoaded($event): void {
  const webview: WebView = <WebView>$event.object;
  if(isAndroid){
    WebSettings settings = webView.getSettings();
    settings.setDomStorageEnabled(true);
  }
}

See:

@diegovincent That seems very useful. Thank you!
about onReceivedSslError, maybe I need to create _Implemented Webview_ more _natively_.

@cybaj were you able to fix this problem?

Was this page helpful?
0 / 5 - 0 ratings