diff --git a/client/modules/IDE/components/PreviewFrame.js b/client/modules/IDE/components/PreviewFrame.js index 94d5d7ce..08b916c0 100644 --- a/client/modules/IDE/components/PreviewFrame.js +++ b/client/modules/IDE/components/PreviewFrame.js @@ -4,6 +4,8 @@ import ReactDOM from 'react-dom'; class PreviewFrame extends React.Component { componentDidMount() { + this.hijackConsole(); + if (this.props.isPlaying) { this.renderFrameContents(); } @@ -33,6 +35,25 @@ class PreviewFrame extends React.Component { doc.close(); } + hijackConsole() { + const iframeWindow = ReactDOM.findDOMNode(this).contentWindow; + const originalConsole = iframeWindow.console; + iframeWindow.console = {}; + + const methods = [ + 'debug', 'clear', 'error', 'info', 'log', 'warn' + ]; + + methods.forEach((method) => { + iframeWindow.console[method] = (...theArgs) => { + originalConsole[method].apply(originalConsole, theArgs); + + // TO DO: do something with the arguments + // window.alert(JSON.stringify(theArgs)); + }; + }); + } + renderSketch() { const doc = ReactDOM.findDOMNode(this).contentDocument; this.clearPreview();