Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private runWebViewJavaScriptInterfaceTest(done: DoneCallback, scriptCode: string, expected: T, msg: string) {
const webView = this.testView;
// >> webview-interface-tests
webView.on(WebViewExt.loadFinishedEvent, async (args: LoadEventData) => {
// >> (hide)
try {
TKUnit.assertNull(args.error, args.error);
TKUnit.assertDeepEqual(await webView.executeJavaScript(scriptCode), expected, msg);
done();
} catch (err) {
done(err);
}
// << (hide)
});
webView.src = javascriptCallsFile;
// << webview-interface-tests
}
public create(): WebViewExt {
// >> declare-webview
const webView = new WebViewExt();
webView.debugMode = true;
// << declare-webview
return webView;
}
if (isAndroid) {
webview.src = "http://10.0.2.2:8080";
} else {
webview.src = "http://localhost:8080";
}
webview.on(WebViewExt.shouldOverrideUrlLoadingEvent, (args: ShouldOverrideUrlLoadEventData) => {
console.log(args.url);
console.log(args.httpMethod);
if (args.url.indexOf("google.com") !== -1) {
args.cancel = true;
}
});
webview.on(WebViewExt.loadFinishedEvent, (args: LoadFinishedEventData) => {
console.log(`WebViewExt.loadFinishedEvent: ${args.url}`);
webview.loadStyleSheetFile("local-stylesheet.css", "~/assets/test-data/css/local-stylesheet.css", false);
});
webview.on("gotMessage", (msg) => {
gotMessageData = msg.data;
console.log(`webview.gotMessage: ${JSON.stringify(msg.data)} (${typeof msg})`);
});
}
export function webviewLoaded(args: LoadEventData) {
webview = args.object;
if (isAndroid) {
webview.src = "http://10.0.2.2:8080";
} else {
webview.src = "http://localhost:8080";
}
webview.on(WebViewExt.shouldOverrideUrlLoadingEvent, (args: ShouldOverrideUrlLoadEventData) => {
console.log(args.url);
console.log(args.httpMethod);
if (args.url.indexOf("google.com") !== -1) {
args.cancel = true;
}
});
webview.on(WebViewExt.loadFinishedEvent, (args: LoadFinishedEventData) => {
console.log(`WebViewExt.loadFinishedEvent: ${args.url}`);
webview.loadStyleSheetFile("local-stylesheet.css", "~/assets/test-data/css/local-stylesheet.css", false);
});
webview.on("gotMessage", (msg) => {
gotMessageData = msg.data;
console.log(`webview.gotMessage: ${JSON.stringify(msg.data)} (${typeof msg})`);
});