Created
December 27, 2011 22:42
-
-
Save also/1525391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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