0

I am debugging a web application which dumps big messages in using console.log, the messages are quite long (easily exceeding 30K characters). When I open devTools console, all these messages are trimmed to 5025 characters - in order to see the complete messages, I need to click 'Show more' on each one of them. If I don't do 'Show more' and just save the log, the messages will be dumped in the trimmed form as they are shown.

I wonder if there is a way to save everything that was dumped to console.log to a file without clicking on every message.

Note, I have tried running chrome with --enable-logging --v=1 as suggested here, but I don't see the console messages from javascript there.

Serge
  • 1,027
  • 14
  • 21
  • Does this answer your question? [How to write console.log to a file instead](https://stackoverflow.com/questions/54654946/how-to-write-console-log-to-a-file-instead) – Milan Lakhani Nov 17 '22 at 17:11
  • Not quite - I cannot really override or replace `console.log` - I am debugging web assembly, so it is emscripten-generated code that redirects `std::cout` to `console.log` – Serge Nov 17 '22 at 17:29
  • 1
    Ideally "Save as" command in the console context menu would do it, but it cuts the text just the same, which I consider a bug in devtools. Meanwhile the workaround would be to find some chrome extension for debugging that writes complete text. Another method is to extract the text using devtools-on-devtools, see these [examples](https://stackoverflow.com/search?q=user%3A3959875+%22devtools-on-devtools%22). – wOxxOm Nov 17 '22 at 17:49
  • @Serge Have you actually tried that? Changing `performance.now` easily hacks into WASM time calculations – Dimava Nov 17 '22 at 19:37
  • copy(....code....) in console copies the output to clipboard – Muhammad Umer Dec 15 '22 at 15:28

1 Answers1

0

Thanks to the comment from @wOxxOm and this post the answer is devtools on devtools:

  1. In the now detached devtools press Ctrl+Shift+i or ⌘+Shift+i on MacOS,which will open devtools-on-devtools in a new window
  2. In the console paste the following code:

    {
        let content = '';
        for(const msg of UI.panels.console.childrenInternal[0].consoleMessages)
        {
            if(msg.message.messageText.startsWith('====')) {        // filtering only the messages I need
                content += msg.message.messageText + '\n';
            }
        }
        const a = document.createElement('a');
        const url = URL.createObjectURL(new Blob([content], {type: 'text/plain'}));
        a.href = url;
        a.download = 'message.log';
        a.dispatchEvent(new MouseEvent('click'));
        console.log(name + '...');
        await new Promise(resolve => setTimeout(resolve, 150));
        URL.revokeObjectURL(url);
    }

Serge
  • 1,027
  • 14
  • 21