title: WebSocket returns undefined in code but not in console
body: <p>I'm struggling to understand what's happening here...</p>
  
  <p>I have a websocket server on 192.168.1.64:81</p>
  
  <p>I need to send data to the socket from a web page using this javascript:</p>
  
  <pre><code>window.onload = function() {
      var connection = new WebSocket("ws://"+location.hostname+":81", ['arduino']);
      connection.onopen = function() {
          connection.send('Connect ' + new Date());
      };
      connection.onerror = function(error) {
          console.log('WebSocket Error ', error);
      };
      connection.onmessage = function(e) {
          console.log('Server: ', e.data);
      };
  
      function sendData() {
          var data="#"+joystick.deltaX()+","+joystick.deltaY();
          connection.send(data);
      }};
  </code></pre>
  
  <p>Now this is what happens: if I open the js console (in firefox) I see the "connection is undefined" error... but if I copy-paste to the console the line:</p>
  
  <pre><code>    var connection = new WebSocket("ws://"+location.hostname+":81", ['arduino']);
  </code></pre>
  
  <p>the socket gets defined correctly and the updater begins streaming data correctly through the socket!!</p>
  
  <p>What am I missing?
  Should I be aware of some well known issue?</p>