fix: there may be invalid root doc

This commit is contained in:
Yanlong Wang 2024-11-13 00:32:48 +08:00
parent 68c4df2df3
commit be993c2cb1
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -111,9 +111,9 @@ export class JSDomControl extends AsyncService {
}
const textNodes: HTMLElement[] = [];
let rootDoc: Document;
if (allNodes.length === 1 && allNodes[0].nodeName === '#document') {
if (allNodes.length === 1 && allNodes[0].nodeName === '#document' && (allNodes[0] as any).documentElement) {
rootDoc = allNodes[0] as any;
if (rootDoc.documentElement && rootDoc.body?.innerText) {
if (rootDoc.body?.innerText) {
textNodes.push(rootDoc.body);
}
} else {