My extension creates hidden iframe and listen to DOMContentLoaded.
When the event is fired, I process the the parameter passed by the
event: aEvent. Here is my code:

var doc = aEvent.originalTarget;
var body = doc.getElementsByTagName("body")[0];

Thus I start to search from a certain element (assume that I know
index of target node beforehand) by this code:

var tmp = body.childNodes.item(x);
tmp = tmp.childNodes.item(y);

and so on...

It is so often that I cannot retrieve an element. The tmp is null.
But if I wait a bit using alert(....), the tmp will be always valid.
However body.innerHTML seems to be completed regardless of alert(...)
command.
I have tried to use setTimeout to make a delay instead of alert(...)
but I cannot find the exact amount of time that is needed for the
whole DOM content to be ready.

What's wrong with me code? Did I do something wrong.
Any recommendation?

Thanks in advance.