title: How to modify DOM in Android WebView?
body: <p>I need to modify pages DOM in Android WebView (hide some elements using id or classname and replace some default impls for functions or CSS styles). I've tried to inject javascript in <code>WebViewClient.onPageLoaded</code>:</p>
  
  <pre><code>webView.setWebViewClient(new WebViewClient() {
      @Override
      public void onPageFinished(WebView view, String url) {
          getSupportActionBar().setTitle("Finishing ");
          getSupportActionBar().setSubtitle(url);
          view.loadUrl("javascript:alert('hello world 2');");
          getSupportActionBar().setTitle("Finished");
      }
  });
  </code></pre>
  
  <p>(showing alert by js here instead of hiding actually). This is not what is desired actually because all the page is shown while it's not loaded.</p>
  
  <p>For some reason js loading in <code>onPageStarted</code> does not work - it prevents from loading original URL:</p>
  
  <pre><code>webView.setWebViewClient(new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
              getSupportActionBar().setTitle("Started ");
              getSupportActionBar().setSubtitle(url);
  
              webView.evaluateJavascript("alert('hello world 1');", null);
              // view.loadUrl("javascript:alert('hello world 1');") prevents too
          }
  </code></pre>
  
  <p>Is it possible to inject JS <strong>before</strong> the page start to load? Any tricks to have callbacks for DOM events in <code>WebView</code>?</p>