code: function onDocumentState (doc, stateFn, callback) {
    let ready = stateFn(doc)
  
    if (ready) {
      callback(doc)
  
      return
    }
  
    const readyListener = () => {
      if (!stateFn(doc)) {
        return
      }
  
      if (!ready) {
        ready = true
        callback(doc)
      }
  
      doc.removeEventListener('readystatechange', readyListener)
    }
  
    doc.addEventListener('readystatechange', readyListener)
  }
docs: Calls the callback when document's state satisfies the stateFn.
  
  @param {!Document} doc
  @param {(doc: Document) => boolean} stateFn
  @param {(doc: Document) => void} callback