1

Parts of an Android webview url have already fired by the time onLoadResource is activated. The delay is minimal but can be clearly seen...

public void onLoadResource(WebView view, String url) {
  injectScriptFile(webview, "hello.js");
  super.onLoadResource(view, url);
}

Is there a way to inject javascript into the webview before anything in the body tag renders?

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
David
  • 12,731
  • 15
  • 43
  • 51

1 Answers1

0

if overriding the webViews shouldOverrideUrlLoading doesn't do the trick, i think the earliest way to inject javascript into your webView is by annotating an injecting method as a JavascriptInterface so it can be called from the website you are loading

Pynnie
  • 136
  • 11