html_ws-test-page.html (1634B)
1 <!-- Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ --> 3 <!doctype HTML> 4 <html> 5 <head> 6 <meta charset="utf-8"/> 7 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /> 8 <meta http-equiv="Pragma" content="no-cache" /> 9 <meta http-equiv="Expires" content="0" /> 10 <title>WebSocket Inspection Test Page</title> 11 </head> 12 <body> 13 <h1>WebSocket Inspection Test Page</h1> 14 <script type="text/javascript"> 15 /* exported openConnection, closeConnection, sendData, sendFrames */ 16 "use strict"; 17 18 let ws; 19 function openConnection(numFramesToSend) { 20 return new Promise(resolve => { 21 ws = new WebSocket( 22 "ws://mochi.test:8888/browser/devtools/client/netmonitor/test/file_ws_backend"); 23 24 ws.onopen = () => { 25 for (let i = 0; i < numFramesToSend; i++) { 26 ws.send("Payload " + i); 27 } 28 resolve(); 29 }; 30 }); 31 } 32 33 function sendFrames(numFramesToSend) { 34 return new Promise(resolve => { 35 for (let i = 0; i < numFramesToSend; i++) { 36 ws.send("Payload " + i); 37 } 38 resolve(); 39 }) 40 } 41 42 function closeConnection() { 43 return new Promise(resolve => { 44 ws.onclose = () => { 45 resolve(); 46 } 47 ws.close(); 48 }) 49 } 50 51 function sendData(payload, asBinary = false) { 52 ws.send( 53 asBinary ? Uint8Array.from(payload, c => c.charCodeAt(0)) : payload 54 ); 55 } 56 </script> 57 </body> 58 </html>