I had the same problem. I created an Office application in which I did not have a console for debugging or developer tools, so I could not find out where the errors occurred.
I created one component (es6 class) that hooked all the console messages, saved the message in a separate array, and called the "real" console function.
log(message) { const msg = new Log(message); this.pushMessage(msg); this._target.log(message); }
where Log is a simple wrapper with message and a type and this._target is a link to window.console . So I did the same with info , warn and error .
In addition, I created the handleThrownErrors(message, url, lineNumber) method to detect exceptions.
window.onerror = this.handleThrownErrors.bind(this);
At least I created an instance of the class (I named it LogCollector ) and added it to the window.
window.logCollector = new LogCollector();
Now I have created a reaction component that receives an instance of logCollector ( window.logCollector ) as a property. At regular intervals, the reacting component checks the collected messages and displays them on the screen.
componentDidMount() { this.setInterval(this._forceUpdate, 500); }, _forceUpdate() { this.setState({update: !this.state.update}); }
this.setInterval() is a native function that simply calls window.setInterval() .
And in the render() method:
return ( <div class="console"> {this.props.logCollector.getMessages().map(this.createConsoleMessage)} </div> );
NOTE It is important to include LogCollector before all other files.
NOTE The above solution is a very simplified version. For example: you can improve it by adding custom (message-) listeners or by catching 404 Not found errors (for js-scripts and css files).