forked from google/ios-webkit-debug-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwdp_client.html
104 lines (96 loc) · 2.6 KB
/
wdp_client.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!--
Google BSD license https://developers.google.com/google-bsd-license
Copyright 2012 Google Inc. [email protected]
An example browser-based client.
-->
<html><head><script type="text/javascript">
function onSubmit() {
if (!("WebSocket" in window)) {
alert("Your browser doesn't support WebSockets!");
return;
}
ol_clear("send_ol");
ol_clear("recv_ol");
var form = document.getElementById('f');
var port = form.elements["port"].value;
var page_num = form.elements["page_num"].value;
var url = "ws://localhost:"+port+"/devtools/page/"+page_num;
var text = document.getElementById('commands');
var lines = text.value.split("\n");
var commands = [];
for (var i = 0; i < lines.length; i++) {
line = lines[i].trim();
if (line && line.charAt(0) != '#') {
commands.push(line);
}
}
var count = 0;
ol_append("send_ol", "open "+url);
var ws = new WebSocket(url);
function send_next_command(in_msg) {
ol_append("recv_ol", in_msg);
if (count < commands.length) {
out_msg = commands[count++];
ol_append("send_ol", out_msg);
ws.send(out_msg);
} else if (count == commands.length) {
count++;
ol_append("send_ol", "close");
ws.close();
}
};
ws.onopen = function() {
send_next_command("opened "+url);
};
ws.onmessage = function(evt) {
send_next_command(evt.data);
};
ws.onclose = function() {
ol_append("recv_ol", "closed");
};
ws.onerror = function(e) {
ol_append("recv_ol", "error: "+e.data);
};
}
function ol_clear(id) {
var o_ol = document.getElementById(id);
while (o_ol.hasChildNodes()) {
o_ol.removeChild(o_ol.lastChild);
}
}
function ol_append(id, text) {
var o_ol = document.getElementById(id);
var o_li = document.createElement("li");
o_li.appendChild(document.createTextNode(text));
o_ol.appendChild(o_li);
}
</script>
<style type="text/css">
.top {
vertical-align:top;
}
.right {
text-align:right;
}
</style>
</head><body>
<form id="f">
Inspect localhost:
<input name="port" size="3" class="right" value="9222"
/><sup><a href="http://localhost:9221" target="_new">?</a></sup
>/devtools/page/<input name="page_num" class="right" size="5" value="1"
/><sup><a href="http://localhost:9222" target="_new">?</a></sup>
<input type="button" onclick="onSubmit()" value="run"/><p>
<textarea id="commands" rows="5" cols="80">
{"id":1,"method":"Page.navigate","params": {"url":"http://www.google.com/"}}
</textarea>
</form>
<table>
<tr><td width="50%" class="top">
<form onSubmit="return send();">
<ol id="send_ol"></ol>
<form>
</td><td class="top">
<ol id="recv_ol"></ol>
</td>
</body></html>