bug: setWebViewClient is not working
See original GitHub issueBug 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:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is marked as a bug, see the type: bug label on it.
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.