Issue with JavaScript Interface in Android WebView

221 views
Skip to first unread message

MohammadReza Iranmanesh

unread,
Nov 4, 2024, 11:06:16 AM11/4/24
to android-webview-dev, ali.del...@gmail.com

Dear android-webview-dev,

We added a Javascript interface to our webview to interact web and android and opened webview in initial screen (first tab of bottom-nav).

We have observed that the interface does not initialize properly in certain scenarios, although we have not been able to consistently reproduce this issue during our testing. However, it has been identified through user logs, indicating that the problem is affecting real-world use. This issue predominantly occurs before the user interacts with the application, and it spans across various OS versions and WebView versions, notably from Chrome version 129 and higher.

Thank you for your attention to this matter. I look forward to your response and help.

Best regards,
MamRez

Nate Fischer

unread,
Nov 4, 2024, 1:54:09 PM11/4/24
to MohammadReza Iranmanesh, android-webview-dev, ali.del...@gmail.com
First question would be: do you add the interface before you start loading the web page? This is what we always recommend, but we know a lot of developers add the interface sometime after page loading has started. If you're doing this during onPageStarted() or something like that then you're going to get a race condition where sometimes the page finishes loading before the interface is actually added to the page. This would match the description of not having a consistent reproduction of the problem.

Check out https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String). Take a look at the part about "Note that injected objects will not appear in JavaScript until the page is next (re)loaded..."

I assume you're talking about addJavascriptInterface() because you used the term "interface," but if you actually mean a different WebView API then please clarify so we can advise properly.

Nate Fischer | Software Engineer | ntf...@google.com



--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/6e84d9af-36c5-4a6d-83af-f5b43c177a49n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages