Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions client/utils/hookConsoleSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import parse from 'console-feed/lib/Hook/parse';
import methods from 'console-feed/lib/definitions/Methods';
import { Encode } from 'console-feed';

/**
* Synchronous replacement for console-feed's Hook. Encodes function
* arguments immediately, so the values of mutable arguments are
* captured accurately.
*
* (See https://github.com/samdenty/console-feed/pull/77.)
*/
export default function hookConsoleSync(targetConsole, callback) {
methods.forEach((method) => {
const native = targetConsole[method];
targetConsole[method] = function patched(...args) {
native.apply(this, args);
const parsed = parse(method, args);
if (parsed) callback(Encode(parsed));
};
});
}
5 changes: 3 additions & 2 deletions client/utils/previewEntry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Hook, Decode, Encode } from 'console-feed';
import { Decode, Encode } from 'console-feed';
import StackTrace from 'stacktrace-js';
import { evaluateExpression } from './evaluateExpression';
import hookConsoleSync from './hookConsoleSync';

// should postMessage user the dispatcher? does the parent window need to
// be registered as a frame? or a just a listener?
Expand Down Expand Up @@ -56,7 +57,7 @@ window.loopProtect = {

const consoleBuffer = [];
const LOGWAIT = 500;
Hook(window.console, (log) => {
hookConsoleSync(window.console, (log) => {
consoleBuffer.push({
log
});
Expand Down