0

So SDK has this function that checks if window is loading, the code for that is below.

My question is what if an innerHTML or appendChild or something to change html happens? Does that bring back loadContext? I want to know if the DOM in a window is fully done parsing, or in progress of parsing, is this possible with this method?

edit: actually this is the code to see if document is loaded:

const isInteractive = window =>
  window.document.readyState === "interactive" ||
  isDocumentLoaded(window) ||
  // XUL documents stays '"uninitialized"' until it's `readyState` becomes
  // `"complete"`.
  isXULDocumentWindow(window) && window.document.readyState === "interactive";
exports.isInteractive = isInteractive;

const isXULDocumentWindow = ({document}) =>
  document.documentElement &&
  document.documentElement.namespaceURI === XUL_NS;

/**
* Check if the given window is completely loaded.
* i.e. if its "load" event has already been fired and all possible DOM content
* is done loading (the whole DOM document, images content, ...)
* @params {nsIDOMWindow} window
*/
function isDocumentLoaded(window) {
  return window.document.readyState == "complete";
}
exports.isDocumentLoaded = isDocumentLoaded;

but does readyState go to interactive when innerHTML is being parsed? i want to know when page is fully rendered.

Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

1

Dynamic HTML changes don't affect the document.readyState property, it is a one-way street. The value is "loading" while the document is being parsed, "interactive" once parsing is done and only things like images need to load (DOMContentLoaded event fired) and "complete" once everything is done (load event fired). It no longer changes after that.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Ah drats, how much time do you think it takes for the dom parser to render stuff like appendChild and innerHTML updates? There's no paint complete event fired? – Noitidart Mar 05 '14 at 04:43
  • 1
    @Noitidart: Rendering happens asynchronously, only the DOM changes are synchronous. `innerHTML` can take a while, depending on how complex the HTML code is. `appendChild` on the other hand is pretty fast - no parsing involved here. There is [`MozAfterPaint` event](https://developer.mozilla.org/en-US/docs/Web/Reference/Events/MozAfterPaint) but you cannot know which one is the "final" paint event. – Wladimir Palant Mar 05 '14 at 08:01
  • Ahhh drats so close thanks for that MozAfterPaint I knew I remembered something like that but couldn't find it. Ok thanks Wlad! – Noitidart Mar 05 '14 at 09:46