Can't get "DOMContentLoaded" event from iframe inside a Firefox tab (XUL and chrome:// document)

Paul Rouget paul at mozilla.com
Tue Aug 20 13:25:38 UTC 2013


A XUL document: chrome://browser/content/devtools/framework/toolbox-window.xul
It contains many iframes. We listen to the DOMContentLoaded event from these iframes.

> let iframe = document.createElement("iframe");
> iframe.addEventListener("DOMContentLoaded", callback);

Event is received if toolbox-window.xul lives in its own window.
Event is NOT received if toolbox-window.xul lives in a Firefox tab (inside <browser>).

----

Here is a way to see this behavior:

In a Firefox tab, open chrome://browser/content/devtools/framework/toolbox-window.xul
(page is grey, it's normal).

Open Scratchpad (Shift-F4), and run this code:

> let button = document.createElement("button");
> button.setAttribute("label", "CLICK");
> let iframe = document.createElement("iframe");
> iframe.setAttribute("src", "about:blank");
> 
> document.documentElement.appendChild(button);
> document.documentElement.appendChild(iframe);
> 
> button.addEventListener("click", function() {
>   iframe.addEventListener("DOMContentLoaded", function() {
>     alert(42);
>   } , true);
>   iframe.setAttribute("src", "chrome://browser/content/devtools/profiler.xul");
> }, true);

No alert.

If this code runs in a window and not a tab, we see the alert.

How can I get the window behavior inside a tab?

Thanks,

-- Paul



More information about the firefox-dev mailing list