Skip to content

Instantly share code, notes, and snippets.

@also
Created December 27, 2011 22:42
Show Gist options
  • Save also/1525391 to your computer and use it in GitHub Desktop.
Save also/1525391 to your computer and use it in GitHub Desktop.
var host = "localhost:9999"
var page = 1
var ws = new WebSocket("ws://" + host + "/devtools/page/" + page)
ws.onmessage = function(m) {console.log(m.data)}
var counter = 0
var send = function (method, params) {
ws.send(JSON.stringify({id: counter++, 'method': method, 'params': params}))
}
ws.onopen = function() {
send('Runtime.evaluate', {expression: 'alert("hello from remote debugger")'})
send('Runtime.evaluate', {expression: '5+5'})
}
import json
import socket
from websocket import WebSocket
ws = WebSocket()
# if ipv6
ws.io_sock = ws.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
ws.connect("ws://localhost:9999/devtools/page/1")
counter = 0
def send(method, params):
global counter
counter += 1
# separators is important, you'll get "Message should be in JSON format." otherwise
message = json.dumps({"id": counter, "method": method, "params": params}, separators=(',', ':'))
print "> %s" % (message,)
ws.send(message)
def recv():
result = ws.recv()
print "< %s" % (result,)
send('Runtime.evaluate', {'expression': 'alert("hello from python")'})
recv()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment