Skip to content

VirtualConsolePrinter.read()

David Ortner edited this page Jan 21, 2025 · 1 revision

Reads log entries from the console stream. This will clear the stream.

Signature

read(): IVirtualConsoleLogEntry[];

Returns

IVirtualConsoleLogEntry[]

Example

import { Window } from 'happy-dom';

const window = new Window();

window.console.log('Test', { test: true });

const entries = window.happyDOM.virtualConsolePrinter.read();
const log = entries.map(entry => entry.message.join(' ')).join('\n');

// Will output 'Test [object Object]' to the NodeJS console
global.console.log(log);
Clone this wiki locally