Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] Document how to modify the WebViewClient #2751

Closed
nklayman opened this issue Apr 11, 2020 · 6 comments
Closed

[Documentation] Document how to modify the WebViewClient #2751

nklayman opened this issue Apr 11, 2020 · 6 comments

Comments

@nklayman
Copy link
Contributor

#2477 was merged without any documentation on how to modify the WebViewClient, making it difficult to use without a decent amount of Java/Android development experience. I want to enable self-signed https support like in #2271. The PR didn't get merged, instead I was pointed at #2230, which was fixed by #2477, yet no documentation was added (afaik) about how to use it. If someone could either document how to modify the webview or how I could specifically solve the https self-signed certificate problem that would be awesome.

@jcesarmobile
Copy link
Member

jcesarmobile commented Apr 13, 2020

Sorry but this is not a feature we want to "advertise", we mainly did because of you (quasar) were overriding the WebViewClient and breaking the plugins because of that.

For using it, instead of doing

public static void enable(WebView webview) {
    webview.setWebViewClient(new WebViewClient() {
      @Override
      public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
        handler.proceed();
      }
    });
  }
public static void enable(Bridge bridge) {
    bridge.getWebView().setWebViewClient(new BridgeWebViewClient(bridge) {
      @Override
      public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
        handler.proceed();
      }
    });
  }

and your EnableHttpsSelfSigned.enable(findViewById(R.id.webview)); to EnableHttpsSelfSigned.enable(this.bridge);

@nklayman
Copy link
Contributor Author

Thank you so much for the code snippet! It worked great, but I had to replace bridge.getWebView().setWebViewClient(new WebViewClient(bridge) { with bridge.getWebView().setWebViewClient(new WebViewClient() { (removed bridge arg).

@jcesarmobile
Copy link
Member

Sorry, should be BridgeWebViewClient, not WebViewClient, updated the comment.

@rstoenescu
Copy link

A big "thank you!" from Quasar team for guiding us!

@domoosterloo
Copy link

@jcesarmobile
Not sure this is the right place to ask this and whether this should be an feature request instead but where is the logical place to be overriding the WebViewClient in a default template app?

In the template app for android, MainActivity calls BridgeActivity.init(), which creates a new Bridge with new default BridgeWebViewClient. new Bridge() also calls load on the WebView, with the app url from config.

If custom WebViewClient is set before init it gets overwritten. If set after init, it doesn't get set until after the initial load request.

This is fine for events triggered on response from server, ie onReceivedSslError or shouldOverrideUrlLoading but not for ones called prior to request, ie shouldInterceptRequest.

Is there a better place to put this?
Options I see to fix are:

  1. separate init and load in MainActivity, so that any custom overrides can be applied after init and prior to load (preferred option)
  2. allow Plugins to override shouldInterceptRequest as per implementation of shouldOverrideUrlLoading

My use case is loading via server url to an authenticated server, and wanting to set custom Authorization header on request to specific urls.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants