title: CustomEvent() to an XUL tab - Firefox addon
body: <p>For many reasons, I have to open up XUL in a tab, instead of using a standard window. I wish to send <a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent" rel="nofollow noreferrer">custom events</a> to this tab, and here's how my code looks like : </p>
  
  <p>myextension.js :</p>
  
  <pre><code>  .. 
    var pTab = window.gBrowser.loadOneTab("chrome://myextension/path/options.xul", 
                    {inBackground: false});
    var pWin = window; 
    var event = new pWin.CustomEvent("prefwindow-event");
    pWin.dispatchEvent(event);
    ..
  </code></pre>
  
  <p>options.xul code:</p>
  
  <pre><code> window.addEventListener("load", init, false); 
   window.addEventListener("prefwindow-event", myevent, false, true);
   .. 
   myevent: function(e) {
        dump("My event : " + e.details ); 
   },
   ..
  </code></pre>
  
  <p>However, I don't get the event. I have tried all possible options. Enabled/Disabled <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener#Syntax" rel="nofollow noreferrer"><code>useCapture</code></a> and <code>wantsUntrusted</code> of addEventListener(). After realizing that there are restrictions in sending custom events between windows, I also tried dispatching event with the tab element, like this : </p>
  
  <pre><code>pTab.dispatchEvent(event);
  </code></pre>
  
  <p>That wouldn't work either. 1) The event dispatch would work <a href="https://stackoverflow.com/questions/22502868/dispatch-customevent-to-prefwindow-firefox-addon">perfectly fine</a> if I use a dialog window instead of a tab (<code>openDialog</code> instead of <code>loadOneTab</code>). 2) The tab element <a href="https://developer.mozilla.org/en-US/docs/XUL/tab#Methods" rel="nofollow noreferrer">only inherits</a> <code>dispatchEvent</code> and not a <code>CustomEvent</code></p>
  
  <p>So the question is, is there a way to send custom events and have it received in a tab?</p>