Trying to create a demo app using the VAST Client JS library in my Android Project.
For this, I have downloaded the library's pre-bundled version
and put it in the assets folder.
Besides that, I've also created an HTML file that basically calls the JS functions of the library.
< !DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script src='file:///android_asset/vast-client-browser-min.js'></script>
<script>
// Get the VAST Url from the Java class
const tagURL = window.MyHandler.getVASTUrl();
const vastClient = new VAST.VASTClient();
vastClient.get(tagURL)
.then(res => {
// notify my Java class
window.MyHandler.onResponse('hey');
}).catch(err => {
// notify my Java class
window.MyHandler.onError('heyy');
});
</script>
</head>
<html>
<body>
</body>
</html>
On the Java side, I call my HTML file
// initialize webview
WebView.setWebContentsDebuggingEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
// add javascript interface to notify my java class from the JS side.
webView.addJavascriptInterface(new JavaScriptInterface(this, webView), "MyHandler");
// Load the HTML file
webView.loadUrl("file:///android_asset/vast_client_handler.html");
However, when I run the app, I get this;
I/chromium: [INFO:CONSOLE(17)] "Uncaught ReferenceError: VASTClient is not defined", source: file:///android_asset/vast_client_handler.html (17)
what could I be missing? Thanks
Your whole HTML document is wrong.
<html> tag and not the <head> tag.< !DOCTYPE html> has a space after the first < character so it doesn't get parsed properlybody so that you won't have race conditions (<head> content loads before the <body>)