code: function init(msg) {
        function iFrameLoaded() {
          trigger('iFrame.onload', msg, iframe, undefined, true)
          checkReset()
        }
  
        function createDestroyObserver(MutationObserver) {
          if (!iframe.parentNode) {
            return
          }
  
          var destroyObserver = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
              var removedNodes = Array.prototype.slice.call(mutation.removedNodes) // Transform NodeList into an Array
              removedNodes.forEach(function(removedNode) {
                if (removedNode === iframe) {
                  closeIFrame(iframe)
                }
              })
            })
          })
          destroyObserver.observe(iframe.parentNode, {
            childList: true
          })
        }
  
        var MutationObserver = getMutationObserver()
        if (MutationObserver) {
          createDestroyObserver(MutationObserver)
        }
  
        addEventListener(iframe, 'load', iFrameLoaded)
        trigger('init', msg, iframe, undefined, true)
      }
docs: We have to call trigger twice, as we can not be sure if all iframes have completed loading when this code runs. The event listener also catches the page changing in the iFrame.