Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternate Solution for setJavaScriptEnabled(true);

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 ?

like image 223
Vigbyor Avatar asked Nov 22 '13 06:11

Vigbyor


3 Answers

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).

like image 131
Neha Shukla Avatar answered Nov 18 '22 11:11

Neha Shukla


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")
like image 23
NoAngel Avatar answered Nov 18 '22 10:11

NoAngel


Be warned that setting setJavaScriptEnabled to true may result in refusal of your application submission on the Google Play Store, or if it's already there it may result in its removal.

https://support.google.com/faqs/answer/7668153?hl=en

like image 4
M.Ed Avatar answered Nov 18 '22 11:11

M.Ed