From a08218506e3aa25ee8b6de734b89532a8b84400e Mon Sep 17 00:00:00 2001 From: "yanlong.wang" Date: Wed, 31 Jul 2024 13:12:57 +0800 Subject: [PATCH] fix: truncate svg in jsdom --- backend/functions/src/services/jsdom.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/functions/src/services/jsdom.ts b/backend/functions/src/services/jsdom.ts index 0924c1e..42b9de9 100644 --- a/backend/functions/src/services/jsdom.ts +++ b/backend/functions/src/services/jsdom.ts @@ -39,6 +39,7 @@ export class JSDomControl extends AsyncService { const t0 = Date.now(); const jsdom = new JSDOM(snapshot.html, { url: snapshot.href, virtualConsole }); const allNodes: Node[] = []; + jsdom.window.document.querySelectorAll('svg').forEach((x) => x.innerHTML = ''); if (options?.withIframe) { jsdom.window.document.querySelectorAll('iframe[src],frame[src]').forEach((x) => { const src = x.getAttribute('src'); @@ -151,6 +152,7 @@ export class JSDomControl extends AsyncService { const extendedSnapshot = { ...snapshot } as ExtendedSnapshot; try { const jsdom = new JSDOM(snapshot.html, { url: snapshot.href, virtualConsole }); + jsdom.window.document.querySelectorAll('svg').forEach((x) => x.innerHTML = ''); const links = Array.from(jsdom.window.document.querySelectorAll('a[href]')) .map((x: any) => [x.getAttribute('href'), x.textContent.replace(/\s+/g, ' ').trim()]) .map(([href, text]) => {