title: Android WebView Inject Javascript before html loaded
body: <p>I am using Android WebView to load some web pages. I need insert a piece of Javascript code to all the pages before they loaded.</p>
  
  <p>I am trying to inject them on WebViewClient onPageStart callback.</p>
  
  <pre><code>mWebView.getSettings().setJavaScriptEnabled(true);
  mWebView.setWebViewClient(new WebViewClient(){
  
      @Override
      public void onPageStarted(WebView view, String url, Bitmap favicon) {
          loadUrl("javascript:var output='test string';");
          }
  })
  
  mWebView.loadUrl("xxx.html");
  </code></pre>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;script&gt;document.write(output);&lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I expected My Js code loaded before HTML. But sometimes the JS code loaded after HTML.</p>
  
  <p>Is there any way could solve my issue?</p>