简体   繁体   中英

How can I capture stdout and stderr in the browser?

I'm trying to figure out how to capture stderr and stdout in the browser from the currently executing javascript.

This will be for a live code editor.

JS has no stdout or stderr - it just has the console .

It is possible to override console.log() with your own function that does whatever processing you want, and ideally then pass the log message to the original console.log function. Ditto for console.error .

For example:

(function() {
    const log_orig = console.log;

    console.log = function() {
        log_orig.call(console, 'log called with ' arguments.length + ' parameters');
        log_orig.apply(console, arguments);
    }
})();  // IIFE

You can't.

Any output and errors that browser outputs are not exposed to JS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM