Showing console errors and alerts in a div inside the page

后端 未结 7 710
梦毁少年i
梦毁少年i 2020-12-02 09:10

I\'m building a debugging tool for my web app and I need to show console errors in a div. I know I can use my own made console like object and use it, but for future use I n

相关标签:
7条回答
  • 2020-12-02 09:48

    I created a zero-dependency npm module for this case: console-events (surely if you're okay to use nodejs :P)

    You can add event listener like that:

    const { console } = require('console-events');
    
    console.addEventListener('log', (e) => {
       e.preventDefault(); //if you need to prevent normal behaviour e.g. output to devtools console
       $('#debugDiv').append('<p>' + message + '</p>');
    })
    
    0 讨论(0)
提交回复
热议问题