-
Notifications
You must be signed in to change notification settings - Fork 1k
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
bug: setWebViewClient is not working #5419
Comments
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue. Please see the Contributing Guide for how to create a Code Reproduction. Thanks! |
https://github.com/astrocreep/capacitor-setWebViewClient After starting this one on Android. You should see a log message:
Without the fix, you only see the second line... |
So this was thought in a way that the WebViewClient was set by the users on the bridge initialization, so it would use the users client from the beginning, instead of swapping it after initialization, in that case your code modification is not needed. But with the Capacitor 3 refactor maybe things work in a different order and that doesn't work as expected, will look into it. If done after the initialization, it should be done like this by the user/plugin:
Or at least that's what I answered on an issue long ago #2751 (comment) |
Can you provide an example how to setup a custom WebViewClient without a plugin? I'n my linked example I tried this:
No plugin, just a minimal MainActivity. The WebView is already set up here and the client isn't changeable. Where else could I hook in? |
It's working from plugins but not from MainActivity.java As workaround you can use |
Yes, this is what I'm doing now and it's working
But having a setter that does nothing once the initialization is complete still bothers me. Imho this is not a good design choice. If there is stuff that needs to be set up before init, better have an settings object or whatever. |
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. |
Bug Report
Capacitor Version
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 thethis.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
Other Technical Details
npm --version
output: 8.1.3node --version
output: v17.1.0Additional Context
The reason for this issue is the
setWebViewClient
setter inBridge.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):The text was updated successfully, but these errors were encountered: