From 1829cde717806ef94eb316559d930fe118a65b1d Mon Sep 17 00:00:00 2001 From: Antonio Pisano Date: Wed, 20 Mar 2024 14:02:06 +0100 Subject: [PATCH] HTMLMesh: do not render the script tag See https://github.com/mrdoob/three.js/pull/27953 --- src/HTMLMesh.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/HTMLMesh.js b/src/HTMLMesh.js index 378ff92..db44c78 100644 --- a/src/HTMLMesh.js +++ b/src/HTMLMesh.js @@ -247,6 +247,13 @@ function html2canvas( element ) { function drawElement( element, style ) { + // Do not render invisible elements, comments and scripts. + if ( element.nodeType === Node.COMMENT_NODE || element.nodeName === 'SCRIPT' || ( element.style && element.style.display === 'none' ) ) { + + return; + + } + let x = 0, y = 0, width = 0, height = 0; if ( element.nodeType === Node.TEXT_NODE ) { @@ -264,14 +271,9 @@ function html2canvas( element ) { drawText( style, x, y, element.nodeValue.trim() ); - } else if ( element.nodeType === Node.COMMENT_NODE ) { - - return; - } else if ( element instanceof HTMLCanvasElement ) { // Canvas element - if ( element.style.display === 'none' ) return; const rect = element.getBoundingClientRect(); @@ -286,8 +288,6 @@ function html2canvas( element ) { } else if ( element instanceof HTMLImageElement ) { - if ( element.style.display === 'none' ) return; - const rect = element.getBoundingClientRect(); x = rect.left - offset.left - 0.5; @@ -299,8 +299,6 @@ function html2canvas( element ) { } else { - if ( element.style.display === 'none' ) return; - const rect = element.getBoundingClientRect(); x = rect.left - offset.left - 0.5;