Bug 12320 - JavascriptInterfaceAttribute required for Android 4.2 WebView Javascript Interfacing
Summary: JavascriptInterfaceAttribute required for Android 4.2 WebView Javascript Inte...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.7.x
Hardware: PC Mac OS
: Highest critical
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2013-05-21 08:30 UTC by Chris Hardy [MSFT]
Modified: 2013-05-21 10:51 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chris Hardy [MSFT] 2013-05-21 08:30:04 UTC
As of Android 4.2 and higher, setting the target framework to level 17 requires a @JavascriptInterface annotation to be added to use a JavaScript interface in your WebView. The caution can be found in orange on http://developer.android.com/guide/webapps/webview.html#BindingJavaScript and is as follows: 

"If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available to your JavaScript (the method must also be public). If you do not provide the annotation, the method is not accessible by your web page when running on Android 4.2 or higher."

Since Xamarin.Android has no way of annotating this, this functionality is not currently possible on Android 4.2.
Comment 3 Atsushi Eno 2013-05-21 09:56:30 UTC
Android.Webkit.JavaScriptInterfaceAttribute should be usable for that purpose. So it should be examined using that attribute first.

I figured that it's missing from our androidapi.xamarin.com.
Comment 4 Chris Hardy [MSFT] 2013-05-21 10:09:25 UTC
Yes, adding JavaScriptInterface works as expected (making sure the Target Framework is set to Level 17), thanks Atsushi!

Is this part of our 4.6.6 release (I tested this works on Version: 4.7.4)?
Comment 5 Atsushi Eno 2013-05-21 10:51:09 UTC
I believe we haven't changed anything with related to this, so this would have worked even in earlier version of bs1.