我使用webivew
在电子应用程序中显示不同的网页。但是我想在webview
控制台中捕获所有传入的输入。
我已在documentation中为此指定了事件监听器console-message
,但似乎并没有捕获以下错误异常:
Failed to load resource: the server responded with a status of 502 (Bad Gateway)
这是我在官方文档中使用的示例。没有发现错误。
const webview = document.querySelector('webview');
webview.addEventListener('console-message', event =>
trackLogs(`WEBVIEW_LOG_EVENT: ${event.message}`)
);
这是我尝试注入代码的示例,但似乎在调用注入脚本之前就已捕获了错误。
const webview = document.querySelector('webview');
function contentload() {
webview.executeJavaScript(`
window.onerror = function(error, url, line) {
`trackErrors({acc:'error',` data:'ERR:'+error+' URL:'+url+' L:'+line});
};
`);
}
webview.addEventListener('did-start-loading', contentload);
如何从webview
控制台捕获此类输入并将其发送到我的记录器服务?