Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
// iniitial logz
const { rawLogz } = this.props
// also listen
Hook(window.console, (log) => {
this.setState((state) => {
var logz = state.logs.slice()
logz.push(Decode(log))
return {
logs: logz
}
})
})
// replay initial logs
console.log(...rawLogz)
}
hookConsole = (console = window.console) => {
Hook(console, (log) => {
this.setState((prevState) => {
//preservelog
const nextState = update(prevState, {logs: {$push: [Decode(log)]}});
this.totalMatches = nextState.logs.length;
return nextState;
}
)
});
this.listener = listen(this.handleMessage);
};
const enableLogs = () => {
Hook(window.console, log => {
setLogs(logs => ([Decode(log), ...logs]))
})
}
useEffect(() => {
Hook(window.console, log => {
if (log[0].method !== "warn") {
setLogs(state => [...state, Decode(log)]);
}
});
}, []);
import loopProtect from 'loop-protect';
import { Hook } from 'console-feed';
window.loopProtect = loopProtect;
const consoleBuffer = [];
const LOGWAIT = 500;
Hook(window.console, (log) => {
consoleBuffer.push({
log,
source: 'sketch'
});
});
setInterval(() => {
if (consoleBuffer.length > 0) {
window.parent.postMessage(consoleBuffer, '*');
consoleBuffer.length = 0;
}
}, LOGWAIT);