Skip to content

Commit

Permalink
fix: getRootNode() bug
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Jul 18, 2023
1 parent e8dc9de commit 25aea10
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion esm/interface/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,15 @@ export class Node extends EventTarget {
return this.parentNode;
}

/**
* Calling it on an element inside a standard web page will return an HTMLDocument object representing the entire page (or <iframe>).
* Calling it on an element inside a shadow DOM will return the associated ShadowRoot.
* @return {ShadowRoot | HTMLDocument}
*/
getRootNode() {
let root = this;
while (root.parentNode)
root = root.parentNode;
return root.nodeType === DOCUMENT_NODE ? root.documentElement : root;
return root;
}
}

0 comments on commit 25aea10

Please sign in to comment.