forked from google/ios-webkit-debug-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwdp_client.js
executable file
·47 lines (42 loc) · 1.32 KB
/
wdp_client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
// Google BSD license http://code.google.com/google_bsd_license.html
// Copyright 2012 Google Inc. [email protected]
// Node.js example client
//
// Requires `npm install optimist ws`
var argv = require('optimist')
.default({ port: 9222, page: 1, url: 'http://www.google.com' })
.usage('Usage: $0 [OPTIONS]\n\nSends a Page.navigate command to the proxy.')
.boolean('help')
.check(function() { return !arguments[0].help; })
.argv
var url = 'ws://localhost:' + argv.port + '/devtools/page/' + argv.page
var commands = [
'{"id": 1, "method": "Page.navigate", "params":{"url": "' + argv.url + '"}}'
]
var WebSocket = require('ws');
console.log('open '+url);
var ws = new WebSocket(url)
var count = 0
ws.on('open', function() {
console.log('connected');
if (count < commands.length) {
console.log('send '+commands[count])
ws.send(commands[count++])
}
});
ws.on('close', function() {
console.log('disconnected');
ws.close()
});
ws.on('message', function(data, flags) {
console.log('recv %s', data)
if (count < commands.length) {
console.log('send '+commands[count])
ws.send(commands[count++])
} else {
// if we sent Page.enable, we could listen for Page.loadEventFired to
// see if our nav succeeded.
ws.close()
}
});