title: Immediate Disconnection using websocket in FireFox Addon
body: <p>I've been working on browser extensions that interact with a local application running a WebSocket server.
  Safari and Chrome Extensions were very easy to implement, and after some headache getting a feel for FF development, I thought I would be able to implement WebSockets as I had in the other browsers.  However I have had some issues.</p>
  
  <p>I understand that I can't directly create a WebSocket in the "main" js file, and so attempted to use workarounds I found on the internet:</p>
  
  <p><a href="https://github.com/canuckistani/Jetpack-Websocket-Example" rel="nofollow">https://github.com/canuckistani/Jetpack-Websocket-Example</a> uses a page-worker as a sort of proxy between main and the WebSocket code.  When I implement this code, my WebSocket connection immediately errors w/ {"isTrusted":true} as the only information.</p>
  
  <p>I also tried to use a hiddenframe as it appears this is how 1Password deals with websocket communication in their FF Addon, but this also results in the same immediate error.</p>
  
  <p>When I simply open a websocket connection to my server in my normal FF instance, it connects perfectly, but so far, I haven't gotten anything to work from addon.</p>
  
  <p>making pageWorker with:</p>
  
  <pre><code>var pw = pageWorker.Page({
      contentUrl: self.data.url('com.html'),
      contentScriptFile: self.data.url('com.js')
  })
  </code></pre>
  
  <p>com.html:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>com.js:</p>
  
  <pre><code>document.onready = launchCom();
  // Could this need to be on ready?
  
  function launchCom() {
      console.log("[com.js] launchCom Called");
      var wsAvailable = false;
      if ("WebSocket" in window) {
          console.log("[com.js] Detected Websocket in Window, attempting to open...");
          // WebSocket is supported.
          ws = new WebSocket('ws://localhost:9001');
          wsAvailable = true;
      } else {
          console.log("[com.js] Websocket is not supported, upgrade your browser!");
      }
  }
  
  ws.onmessage = function(event) {
    console.log(event.data);
  }
  
  ws.onopen = function(evt) {
      console.log("[com.js] ws opened. evt: " + evt);
  }
  
  ws.onerror = function(evt) {
      console.log("[com.js] ws error: " + JSON.stringify(evt));
  }
  </code></pre>
  
  <p>Running this results in:</p>
  
  <pre><code>console.log: xxx: [com.js] launchCom Called
  console.log: xxx: [com.js] Detected Websocket in Window, attempting to open...
  console.log: xxx: [com.js] ws error: {"isTrusted":true}
  console.log: xxx: [com.js] ws closed. evt: {"isTrusted":true}
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>