diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp index 68c59c8e4a63..dd95d17848e5 100644 --- a/accessible/generic/DocAccessible.cpp +++ b/accessible/generic/DocAccessible.cpp @@ -1215,12 +1215,12 @@ Accessible* DocAccessible::GetAccessibleOrDescendant(nsINode* aNode) const { Accessible* acc = GetAccessible(aNode); if (acc) return acc; - acc = GetContainerAccessible(aNode); - if (acc == this && aNode == mContent) { - // The body node is the doc's content node. - return acc; + if (aNode == mContent || aNode == mDocumentNode->GetRootElement()) { + // If the node is the doc's body or root element, return the doc accessible. + return const_cast(this); } + acc = GetContainerAccessible(aNode); if (acc) { // We access the `mChildren` array directly so that we don't access // lazily created children in places like `XULTreeAccessible` and