antonmedv/finder

root config doesn't allow Document

Opened this issue · 1 comments

For an embedded iframe, I defined root: body but this then fails if I try to find the body element since body.querySelectorAll('body') returns an empty array. This scenario seems to be handled for the default case since the ownerDocument is returned for the rootDocument instead of the body. It seems like the root config should allow both Document and Element. Then the default for root could be updated to document and I think findRootDocument could then be removed.

As a workaround, I am passing the ownerDocument and ignoring the TypeScript error.

I think what could be done here is to use the ParentNode interface, instead. That's the common interface that defines querySelector.

Then, a short-circuit when attempting to find the node that is the root would be to return the :root pseudo-class.