code: function getDocument(rootNode) {
      // Only real documents have a null ownerDocument
      if (rootNode.ownerDocument === null) return rootNode;
  
      else {
          let document = rootNode.ownerDocument;
  
          var documentMethods = [
              'compatMode',
              'createTextNode',
              'createComment',
              'createDocumentFragment',
              'createProcessingInstruction',
              'createElement',
              'createElementNS',
              'createEvent',
              'createTreeWalker',
              'createNodeIterator',
              'location',
              'title',
              'onabort',
              'onreadystatechange',
              'onerror',
              'onload',
          ];
  
          documentMethods.forEach((propertyName) => {
              var property = document[propertyName];
              if (typeof(property) === 'function') property = property.bind(document);
              rootNode[propertyName] = property;
          });
  
          return rootNode;
      }
  }
docs: If rootNode is not a real document (e.g. while rendering a fragment), then some methods such as
  createElement are not available. This method ensures you have a document equivalent object: if
  you call normal document methods on it (createElement, querySelector, etc) you'll get what you
  expect.
  
  That means methods independent of page hierarchy, especially those that are only present on
  the true document object (createElement), should be called on the real document, and methods that
  care about document hierarchy (querySelectorAll, getElementById) should be scope to the given node.