xref: /aosp_15_r20/external/cronet/net/data/websocket/connect_to.html (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1<!DOCTYPE html>
2<html>
3<head>
4<title>test ws connection</title>
5<script type="text/javascript">
6
7var href = window.location.href;
8var queryBegin = href.indexOf('?url=');
9if (queryBegin == -1) {
10  console.log("Failed to find ?url= in URL");
11  document.title = 'FAIL';
12  throw "FAILURE";
13}
14var url = href.slice(queryBegin + 5);
15
16// Do connection test.
17var ws = new WebSocket(url);
18
19ws.onopen = function()
20{
21  // Set document title to 'PASS'. The test observer catches this title changes
22  // to know the result.
23  document.title = 'PASS';
24}
25
26ws.onclose = function()
27{
28  // Set document title to 'FAIL'.
29  document.title = 'FAIL';
30}
31
32ws.onmessage = function(evt)
33{
34  domAutomationController.send(evt.data);
35}
36
37ws.onerror = function(evt)
38{
39  console.error(`WebSocket error: '${JSON.stringify(evt, ["message", "arguments", "type", "name"])}'`);
40}
41
42</script>
43</head>
44</html>
45