function getParentNode(node) {
    var parent = node.parentNode

    if (node.nodeType == /* DOCUMENT */ 9 && node != document) {
      // If this node is a document node, look for the embedding frame.
      return getFrameElement(node)
    }

    // If the parent has element that is assigned through shadow root slot
    if (parent && parent.assignedSlot) {
      parent = parent.assignedSlot.parentNode
    }

    if (parent && parent.nodeType == 11 && parent.host) {
      // If the parent is a shadow root, return the host element.
      return parent.host
    }

    return parent
  }
Gets the parent node of an element or its host element if the parent node
is a shadow root.
@param {Node} node The node whose parent to get.
@return {Node|null} The parent node or null if no parent exists.