Hello,
I am modifying the default Chromium webview test and I am trying to inject some javascript code before a page is loaded. I have tried to override some methods from the AwContentsClient and execute evaluateJavaScript.
AwContentsClient awContentsClient = new NullContentsClient() {
private View mCustomView;
@Override
public void onPageStarted(String url) {
System.out.println("VRWebGL: onPageStarted url = " + url);
mAwTestContainerView.getAwContents().evaluateJavaScript(jsCode, null);
}
@Override
public void onLoadResource(String url) {
System.out.println("VRWebGL: onLoadResource url = " + url);
if (url.equals(AwShellActivity.this.url))
{
mAwTestContainerView.getAwContents().evaluateJavaScript(jsCode, null);
}
}
...
This code works and I am able to see a console.log command in the jsCode being executed. But is I define a global variable in window in the jsCode (just for testing purposes) when the page is loaded, the injected code is wiped out. Is there a way inject code right before the page is loaded but the code stays within the page? Any other method in any other interface or something?
Just for reference purposes, the Crosswalk project (based on chromium) has a similar resource client interface to know when a resource is being loaded (the page) and it's evaluateJavaScript works.
Any help would be much appreciated.
Thank you in advance.
Regards,
Iker