views:

33

answers:

0

Hi all, my task is to get (updating) data from a GMail page with Greasemonkey's injected scripts. I want to get each object of HTMLHtmlElement (<html>) type from an opened page.

What is a best way to enumerate all <something>.document instances existing in Firefox's currently open tab? Greasemonkey has unsafeWindow, but don't know what lies beneath that API (it is not well-documented), there are also window.frames.

This is an enumerator function from Chickenfoot, seemingly missing some page objects, when invoked as:

docs = getAllVisibleFrameDocuments(document);

function getAllVisibleFrameDocuments(/*Document*/ doc) {
 var docs = [];
 traverseDoc(doc);
 return docs;

 function traverseDoc(/*Document*/ doc) {
  if (!doc) return;
  docs.push(doc);
  traverseFrames(doc.getElementsByTagName("frame"));
  traverseFrames(doc.getElementsByTagName("iframe"));
 }
 function traverseFrames(/*FrameNode[]*/ frames) {
  for (var i = 0; i < frames.length; ++i) {    
   traverseDoc(frames[i].contentDocument);
  }
 }
}

So, I think it has both document and document.frames; any thoughts how to collect more data window from Firefox objects? If there is no way - well, there is no way.

P.S. A known working gmailish solution with addEventListener for JS events is not accepted here, as the problem is buggy enumeration and not the task of accessing mail - which can be done with addEventListener for GMail data loading, IMAP and so on.

Also, good old

window.addEventListener(
    'load', 
    function() { },
    true);

is not a choice here, some pages aren't going to give me this event, either.