Skip to content

Instantly share code, notes, and snippets.

@jdfreder
Last active May 20, 2016 22:13
Show Gist options
  • Save jdfreder/2bfd8d739525ff56f267 to your computer and use it in GitHub Desktop.
Save jdfreder/2bfd8d739525ff56f267 to your computer and use it in GitHub Desktop.
Log websocket messages
// Dump this into your web console in a live notebook
function safeLog(type) {
try {
console.log.apply(console, arguments);
} catch(err) {
console.warn(type, 'could not print data');
}
}
var orig1 = Jupyter.notebook.kernel.ws.onmessage;
Jupyter.notebook.kernel.ws.onmessage = function() {
safeLog('recv', JSON.parse(arguments[0].data));
return orig1.apply(Jupyter.notebook.kernel.ws, arguments);
};
var orig2 = Jupyter.notebook.kernel.ws.send;
Jupyter.notebook.kernel.ws.send = function() {
safeLog('send', arguments);
return orig2.apply(Jupyter.notebook.kernel.ws, arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment