Firefox Addon SDK does not send open event to Popup window

I tried a sample in addon-sdk and found the following behaviour.

Main.js:

var windows = require(“sdk/windows”).browserWindows; for each (var window in windows) {

console.log(window.title);
} console.log(windows.length); windows.on(‘open’, function(window) {

console.log(windows.length+“open”);
});

Using the website http://www.yourhtmlsource.com/javascript/popupwindows.html to test. Go to the section containing the phrase “Try it here: » Pop it”, then click on “Pop it”, a new winfow is opened but the open event is not triggered (windows.on(‘open’…); is not called)

Since I am new to Firefox SDK development, could you help me. Thanks.

Does it work when you open a window by other methods?

Hi Lithopsian,

Both javascript:poptastic(’/examples/poppedexample.html’); and javascript:populace(’…/examples/poppedexample2.html’) cannot work.

I have a debug and find out that there is a consistency with isBrowser(window) in _onTrack and _onUntrack functions of SDK add-on. With the same HTML popup window as the sample page, but the isBrowser(window) return false in the _onTrack function and it skips the rest functions, including open event trigger but when I close the popup window, _onUntrack function is called, and the isBrowser(window) return true.

Here are the code get from sdk addon:

/**
* Internal listener which is called whenever new window gets open.
* Creates wrapper and adds to this list.
* @param {nsIWindow} chromeWindow
*/
_onTrack: function _onTrack(chromeWindow) {
if (!isBrowser(chromeWindow)) return;
let window = BrowserWindow({ window: chromeWindow });
this._add(window);
this._emit(‘open’, window);
},

/**
 * Internal listener which is called whenever window gets closed.
 * Cleans up references and removes wrapper from this list.
 * @param {nsIWindow} window
 */
_onUntrack: function _onUntrack(chromeWindow) {
  if (!isBrowser(chromeWindow)) return;
  let window = BrowserWindow({ window: chromeWindow });
  this._remove(window);
  this._emit('close', window);

  // Bug 724404: do not leak this module and linked windows:
  // We have to do it on untrack and not only when `_onUnload` is called
  // when windows are closed, otherwise, we will leak on addon disabling.
  window.destroy();
}

function isBrowser(window) {
    try {
      return window.document.documentElement.getAttribute("windowtype") === BROWSER; // BROWSER: "navigator:browser"
    }
    catch (e) {}
    return false;
};

Following is the value of innerHTML and outerHTML in window.document.documentElement of _onTrack and _onUntrack respectively

_onTrack:

innerHTML:"

Popped Example | example @import "/bubbleicious.css";
<style type="text/css">
<!--
body {margin: 3em; background-image: none; background-color: white; font-size: .8em; text-align: left; }
-->
</style>

Pop ya Collar


Hey great, it worked.

Now, window begone.

"

outerHTML:"

Popped Example | example @import "/bubbleicious.css";
<style type="text/css">
<!--
body {margin: 3em; background-image: none; background-color: white; font-size: .8em; text-align: left; }
-->
</style>

Pop ya Collar


Hey great, it worked.

Now, window begone.

"

_onUntrack:

innerHTML:"<script xmlns=“http://www.mozilla.org/keyma

outerHTML:"<script type=“application/javascript” src=“chro”

You really need to simplify this. Set up a test case that doesn’t involve going to an untested page full of all sorts of unknown javascript doing things you don’t really understand. For example, try a simple popup straight from your own addon. Which should work, or you have a bug. Then get more complex until you don’t get the open event. Try it with browser windows and non-browser windows. Otherwise you’re effectively debugging the website and not your own code.