Is it possible to execute an arbitrary JavaScript function against a WebView-loaded URL?
For example:
WebView vhrWebView = this.findById(R.id.vhr_web_view);
vhrWebView.getSettings().setJavaScriptEnabled(true);
vhrWebView.setWebChromeClient(new WebChromeClient());
vhrWebView.evaluateJavascript("function() {alert('It works!');}();", null);
vhrWebView.loadUrl("http://www.google.com");
I realize that the example does not make a lot of sense but what I would like to do is auto-populate a web-page (that I don't control) with credentials I do have through Javascript. However, I cannot seem to get even the most basic JavaScript to function with the URL loaded and this was the best example I could come up with: popping up a JavaScript dialog box when the Google website is loaded within a WebView.
Is what I want to do possible?
alert()to have an impact beyond logging to LogCat, you will need to have your own real actual honest-to-goodnessWebChromeClientsubclass, overridingonJsAlert(), rather than the do-nothing implementation that you have now. Or, test using something else, like modifying the DOM. Also, bear in mind that you may not be able to evaluate any JavaScript until the page is loaded, and you certainly cannot modify the DOM of a page until it is loaded.