> Instead of using the observer service, use the window watcher's
> registerNotification listener? The window watcher is available on the Services
> object (
https://developer.mozilla.org/en/JavaScript_code_modules/Services.jsm ),
> should be easy to find. That should work, I believe...
>
> Note also that idl types which have the 'function' keyword defined, like
> nsIObserver, can be represented by a single function in JS. So both for the
> observer service and for window watcher's registerNotification method, you can
> just pass a JS function, you don't need to wrap it in an object with a
> QueryInterface method etc.
>
> HTH,
> Gijs
Thanks, now the method is smaller but there is still the same problem. win.location.href outputs chrome://browser/content/browser.xul instead of chrome://global/content/viewSource.xul :o/
Services.ww.registerNotification(function onWindow(aSubject, aTopic) {
let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
win.addEventListener("load", function windowLoad() {
win.removeEventListener("load", windowLoad);
// The following line outputs chrome://browser/content/browser.xul
// instead of chrome://global/content/viewSource.xul
info(win.location.href);
Services.ww.unregisterNotification(onWindow);
});
});
// Open view source window by clicking a link
EventUtils.synthesizeMouseAtCenter(link, { }, contentWindow);