49

I have developed an Android Application which uses Webview Component. I have used following line into my code,

webViewScores.getSettings().setJavaScriptEnabled(true);

Due to this line it is showing Lint warning as Using setJavaScriptEnabled can introduce XSS vulnerabilities into you application, review carefully. Now I know that I can suppress this warning by writing this line @SuppressLint("SetJavaScriptEnabled") above my method or at class level. But my question is, Is there any alternate solution for this ? I means is there any other way we can set Java Script Enabled in Webview ?

Vigbyor
  • 2,334
  • 4
  • 18
  • 34

3 Answers3

34

you have to use it at Class Level like

@SuppressLint("SetJavaScriptEnabled")
public class MyActivity extends Activity
{
    ...
}

and according to me there is no other way to enable JavaScript in WebView and if your app really doesn’t require JavaScript usage within a WebView then don’t call setJavaScriptEnabled(true).

Neha Shukla
  • 3,334
  • 5
  • 35
  • 65
5

The warning tells You that enabling Javascript may be not secure. Just check if You absolutely need to enable Javascript and if You need it, suppress warning by

@SuppressLint("SetJavaScriptEnabled")
NoAngel
  • 810
  • 2
  • 15
  • 26
-1

You could alternatively implement a custom Javascript renderer or even better a full browser, after all, a browser only parses the html which is basically XML

user3343456
  • 103
  • 2
  • 9
  • 1
    Said implementation should definitely include liberal usage of regular expressions. It shall be called NIH-Browser. – Sogger Jan 20 '16 at 21:27