question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: setWebViewClient is not working

See original GitHub issue

Bug Report

Capacitor Version

   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 3.4.0
  @capacitor/core: 3.4.0
  @capacitor/android: 3.4.0
  @capacitor/ios: 3.4.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/core: 3.4.0
  @capacitor/cli: 3.4.0
  @capacitor/android: 3.4.0

[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

I need to use a custom WebViewClient. I coded a new one, extending BridgeWebViewClient and set it via customn Plugin using the this.bridge.setWebVielClient(new MyCustomWebViewClient(this.bridge)); method. The custom WebViewClient isn’t used by Capacitor.

Expected Behavior

My custom WebViewClient should be used instead the default one.

Code Reproduction

package com.example;

import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;

@CapacitorPlugin(name = "CustomWebViewClient")
public class CustomWebViewClient extends Plugin {

    @PluginMethod
    public void init(PluginCall call)
    {
        this.bridge.setWebViewClient(new MyCustomWebViewClient(this.bridge));

        call.resolve();
    }
}

Other Technical Details

npm --version output: 8.1.3

node --version output: v17.1.0

Additional Context

The reason for this issue is the setWebViewClient setter in Bridge.java. The new WebViewClient is only assigned to the Bridge but never set in the WebView itself. I added this to get it working here locally (needs to run in the main thread. Calling this from a plugin fails, because we are in the PluginThread):

    public void setWebViewClient(BridgeWebViewClient client) {
        this.webViewClient = client;

        Handler mainHandler = new Handler(this.getContext().getMainLooper());
        WebView webView = this.webView;
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                webView.setWebViewClient(client);
            }
        });
    }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jcesarmobilecommented, Sep 6, 2022

This is marked as a bug, see the type: bug label on it.

0reactions
ionitron-bot[bot]commented, Nov 10, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SetWebViewClient error - Stack Overflow
It says "change setWebViewClient to setWebChromeClient" but when I do that, it says "change setWebChromeClient to setWebViewClient". Any ...
Read more >
WebViewClient - Android Developers
If a WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the URL. If a...
Read more >
onReceivedError STILL does not receive HTTP Errors ...
Original text below: The WebViewClient class lets activities receive an onReceivedError callback when the WebView is unable to load a URL, but there...
Read more >
732244 - WebViewClient.doUpdateVisitedHistory - Monorail
Steps to reproduce the problem: 1. Use WebViewClient.doUpdateVisitedHistory to listen for and print out visited URLs
Read more >
Using WebViewRenderer and WebViewClient causes cancel ...
it is not working, the navigation goes on. Do I need another function in my WebViewClient or Renderer to check for cancel=true and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found