Skip to content

Instantly share code, notes, and snippets.

@bnookala
Created July 8, 2012 04:34
Show Gist options
  • Save bnookala/3069351 to your computer and use it in GitHub Desktop.
Save bnookala/3069351 to your computer and use it in GitHub Desktop.
Remote Debugging: Interpreting JS, remotely!
var request = require('request');
var WebSocketClient = require('websocket').client;
request('http://localhost:9000/json', function (err, response, body) {
// Read in the body contents as JSON
var response = JSON.parse(body);
// for some reason the following doesn't include the host name!
var ws_uri = response[0]['webSocketDebuggerUrl'];
// so we have to fix it...
var ws_uri = [ws_uri.slice(0,5), 'localhost:9000', ws_uri.slice(5, ws_uri.length)].join('')
var socket = new WebSocketClient();
socket.connect(ws_uri);
socket.on('connect', function (connection) {
console.log('connected');
// onMessage handler for the socket connection
connection.on('message', function (message) {
console.log(message);
});
// Error handler for the socket connection
connection.on('error', function () {
console.log(error);
});
// Send a 'test' message
function sendTestPackage () {
// This message should make the remote interpreter perform an alert
var json_pkg = {
"id": 1,
"method": "Runtime.evaluate",
"params": {
"expression": "alert('omg');",
},
};
var json_string = JSON.stringify(json_pkg);
connection.sendUTF(json_string);
};
// Actually send the 'test' message
sendTestPackage();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment