web-view icon indicating copy to clipboard operation
web-view copied to clipboard

is there a way to supress the console.log output?

Open ivanceras opened this issue 7 years ago • 6 comments
trafficstars

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.

ivanceras avatar Mar 06 '18 11:03 ivanceras

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.

L-as avatar Mar 09 '18 13:03 L-as

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.

ivanceras avatar Mar 09 '18 16:03 ivanceras

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.

ivanceras avatar Mar 09 '18 17:03 ivanceras

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..

Boscop avatar Mar 12 '18 01:03 Boscop

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.

OtterCode avatar Jul 19 '18 18:07 OtterCode

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.

kellpossible avatar Jul 13 '20 18:07 kellpossible