web-view
web-view copied to clipboard
is there a way to supress the console.log output?
Whenever console.log is called in my javascript, the whole html document is printed before the console.log output. Maybe the intention was to log the url of where the debugging info comes from, but using a data/html url with the inlined html would take up all the screen.
I think the only thing you can do is monkey patch console.log to do nothing, although I think disabling debug mode (parameter passed to run) also disables console.log output.
Is the code in the rust code, or in the webkit-gtk which is a standard debian package. I'm not sure if will work, editing the include files of libwebkit-gtk-dev.
Update: it looks like commenting out this line of code prevents it the console output from showing which is also equivalent to setting debug to false.
if (w->debug) {
WebKitSettings *settings =
webkit_web_view_get_settings(WEBKIT_WEB_VIEW(w->priv.webview));
//webkit_settings_set_enable_write_console_messages_to_stdout(settings, true);
webkit_settings_set_enable_developer_extras(settings, true);
}
I need to look for the granular settings like the console messages format to not include the source url. This is a deep rabbit hole and i thought it is.
I think you can just set debug to false or do console.log = function() {};
See also my issue here: https://github.com/zserge/webview/issues/75
The best way seems to be to use RPC and log from the Rust code..
So, I'm having trouble because intercepting console.error isn't working. My current solution has been:
console.log = console.info = console.error = (str) => {
const consoleElem = document.getElementById('console');
const out = typeof str === "string" ? str : JSON.stringify(str)
consoleElem.appendChild(document.createElement('li')).textContent = out;
if (consoleElem.childNodes.length > 1000) {
consoleElem.firstChild.remove();
}
consoleElem.scrollTop = consoleElem.scrollHeight;
}
It works perfectly for normal logging, giving console output in the window itself. The result for errors is the usual impossibly large tty spam on the command line. The whole index.html is prepended as a data url.
Whenever console.log is called in my javascript, the whole html document is printed before the console.log output.
I'm getting the same problem, I want to inline a bunch of code, and it's printing the entire document, which is just silly. But disabling debug mode means I lose access to the developer tools. There needs to be a way to control this.