OLD | NEW |
---|---|
(Empty) | |
1 <script src='websocket_connection.js'></script> | |
2 <script> | |
3 // Listens for 'onmessage' or 'onclose' messages from the websocket, and sends | |
4 // them to the test fixture. | |
5 function connectionListener(e) { | |
6 if (e.data == 'onmessage') { | |
7 window.domAutomationController.send(true); | |
8 } else if (e.data == 'onclose') { | |
9 window.domAutomationController.send(false); | |
10 } | |
11 } | |
12 | |
13 // This page has two modes, one where the websocket connection lives in the | |
14 // document context, and one where it lives in a worker. This is encoded by the | |
15 // extra 'inWorker' url param. | |
engedy
2017/03/06 16:31:01
nit: presence (or absence) of an URL param named `
Charlie Harrison
2017/03/06 19:22:11
Done.
| |
16 var url = new URL(location); | |
17 if (url.searchParams.get('inWorker')) { | |
18 var worker = new Worker('websocket_connection.js'); | |
19 worker.addEventListener('message', connectionListener); | |
20 | |
21 // Redefine connectWebSocket to instead post a message to start the worker. | |
22 connectWebSocket = function(url) { | |
23 worker.postMessage({url: url}); | |
24 } | |
25 } else { | |
26 addEventListener('message', connectionListener); | |
27 } | |
28 </script> | |
OLD | NEW |