fix: potential invalid html

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

View File

@ -46,7 +46,10 @@ export class JSDomControl extends AsyncService {
if (options?.withShadowDom && snapshot.shadowExpanded) {
sourceHTML = snapshot.shadowExpanded;
}
const jsdom = this.linkedom.parseHTML(sourceHTML);
let jsdom = this.linkedom.parseHTML(sourceHTML);
if (!jsdom.window.document.documentElement) {
jsdom = this.linkedom.parseHTML(`<html><body>${sourceHTML}</body></html>`);
}
const allNodes: Node[] = [];
jsdom.window.document.querySelectorAll('svg').forEach((x) => x.innerHTML = '');
if (options?.withIframe) {