node-monkey icon indicating copy to clipboard operation
node-monkey copied to clipboard

Is there any way to post console output on the html page instead of the console?

Open supreen opened this issue 3 years ago • 2 comments

I had searched for it in the documentation but I can not find it.

Is there any function or way that start showing the terminal output in some

of index.htm, instead of the console in inspection.?

supreen avatar Mar 07 '21 23:03 supreen

Just found it. If anyone is looking for it

<html>
<body>
<pre id="log"></pre>
</body>
<script>

(function () {
    if (!console) {
        console = {};
    }
    var old = console.log 
    var logger = document.getElementById('log');
    console.log = function (message) {
        if (typeof message == 'object') {
            logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : String(message))+ '<br>';
        } else {
            logger.innerHTML += message+ '<br>';
        }
    }
})();


</script>
</html>

supreen avatar Mar 09 '21 20:03 supreen

I need to look around and see if there's a good existing library for displaying interactive objects logged to the console in the document itself.

When I started this project there were a bunch of attempts people made but they all fell short of the actual browser built-in devtools and I wanted something that would just use the built-in tools so it wasn't making app debugging harder than it needs to be. It would be a nice additional option for simple use cases though.

jwarkentin avatar Mar 20 '21 04:03 jwarkentin