@@ -540,10 +540,21 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, displayedFn) {
540540 // Zero-sized elements should still be considered to have positive size
541541 // if they have a child element or text node with positive size, unless
542542 // the element has an 'overflow' style of 'hidden'.
543+ // Note: Text nodes containing only structural whitespace (with newlines
544+ // or tabs) are ignored as they are likely just HTML formatting, not
545+ // visible content.
543546 return bot . dom . getEffectiveStyle ( e , 'overflow' ) != 'hidden' &&
544547 goog . array . some ( e . childNodes , function ( n ) {
545- return n . nodeType == goog . dom . NodeType . TEXT ||
546- ( bot . dom . isElement ( n ) && positiveSize ( n ) ) ;
548+ if ( n . nodeType == goog . dom . NodeType . TEXT ) {
549+ var text = n . nodeValue ;
550+ // Ignore text nodes that are purely structural whitespace
551+ // (contain newlines or tabs and nothing else besides spaces)
552+ if ( / ^ [ \s ] * $ / . test ( text ) && / [ \n \r \t ] / . test ( text ) ) {
553+ return false ;
554+ }
555+ return true ;
556+ }
557+ return bot . dom . isElement ( n ) && positiveSize ( n ) ;
547558 } ) ;
548559 }
549560 if ( ! positiveSize ( elem ) ) {
@@ -1412,9 +1423,13 @@ bot.dom.isNodeDistributedIntoShadowDom = function (node) {
14121423bot . dom . appendVisibleTextLinesFromElementInComposedDom_ = function (
14131424 elem , lines ) {
14141425 if ( elem . shadowRoot ) {
1426+ // Get the effective styles from the shadow host element for text nodes in shadow DOM
1427+ var whitespace = bot . dom . getEffectiveStyle ( elem , 'white-space' ) ;
1428+ var textTransform = bot . dom . getEffectiveStyle ( elem , 'text-transform' ) ;
1429+
14151430 goog . array . forEach ( elem . shadowRoot . childNodes , function ( node ) {
14161431 bot . dom . appendVisibleTextLinesFromNodeInComposedDom_ (
1417- node , lines , true , null , null ) ;
1432+ node , lines , true , whitespace , textTransform ) ;
14181433 } ) ;
14191434 }
14201435
0 commit comments