console: hijack iframe console messages
This commit is contained in:
parent
e06c821923
commit
14ede1388b
1 changed files with 21 additions and 0 deletions
|
@ -4,6 +4,8 @@ import ReactDOM from 'react-dom';
|
||||||
class PreviewFrame extends React.Component {
|
class PreviewFrame extends React.Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
this.hijackConsole();
|
||||||
|
|
||||||
if (this.props.isPlaying) {
|
if (this.props.isPlaying) {
|
||||||
this.renderFrameContents();
|
this.renderFrameContents();
|
||||||
}
|
}
|
||||||
|
@ -33,6 +35,25 @@ class PreviewFrame extends React.Component {
|
||||||
doc.close();
|
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() {
|
renderSketch() {
|
||||||
const doc = ReactDOM.findDOMNode(this).contentDocument;
|
const doc = ReactDOM.findDOMNode(this).contentDocument;
|
||||||
this.clearPreview();
|
this.clearPreview();
|
||||||
|
|
Loading…
Reference in a new issue