xref: /aosp_15_r20/external/cronet/net/data/websocket/close_observer.html (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1<!doctype html>
2<title>Observe the connection from a closed tab "Going Away"</title>
3<script>
4'use strict';
5
6let protocol = location.protocol.replace('http', 'ws');
7let url = protocol + '//' + location.host + '/close-observer?role=observer';
8
9// Do connection test.
10let ws = new WebSocket(url);
11
12const id = setTimeout(() => {
13  console.log('close_observer.html had timeout');
14  document.title = 'FAIL';
15}, 3000);
16
17ws.onmessage = e => {
18  clearTimeout(id);
19  console.log('close_observer.html got message: ' + e.data);
20  document.title = (e.data === 'OK' ? 'PASS' : 'FAIL');
21  ws.onclose = null;
22}
23
24ws.onclose = () => {
25  clearTimeout(id);
26  console.log('close_observer.html saw close with no message');
27  document.title = 'FAIL';
28}
29
30</script>
31