diff --git a/cli/test/fixtures/font-size.html b/cli/test/fixtures/font-size.html index bec51c32bb6a..be095c5353b0 100644 --- a/cli/test/fixtures/font-size.html +++ b/cli/test/fixtures/font-size.html @@ -34,5 +34,10 @@
2
+ + +
+
Invisible
+
diff --git a/core/gather/gatherers/seo/font-size.js b/core/gather/gatherers/seo/font-size.js index de05af2bff26..4f33eb28741c 100644 --- a/core/gather/gatherers/seo/font-size.js +++ b/core/gather/gatherers/seo/font-size.js @@ -221,8 +221,9 @@ class FontSize extends BaseGatherer { const nodeIndex = doc.layout.nodeIndex[layoutIndex]; const styles = doc.layout.styles[layoutIndex]; - const [fontSizeStringId] = styles; + const [fontSizeStringId, visibilityStringId] = styles; const fontSize = getFloat(fontSizeStringId); + const visibility = getString(visibilityStringId); const parentIndex = nodes.parentIndex[nodeIndex]; const grandParentIndex = nodes.parentIndex[parentIndex]; @@ -234,6 +235,7 @@ class FontSize extends BaseGatherer { nodeIndex, backendNodeId: nodes.backendNodeId[nodeIndex], fontSize, + visibility, textLength: getTextLength(text), parentNode: { ...parentNode, @@ -257,17 +259,24 @@ class FontSize extends BaseGatherer { let failingTextLength = 0; for (const textNodeData of this.getTextNodesInLayoutFromSnapshot(snapshot)) { + if (textNodeData.visibility === 'hidden') { + continue; + } + totalTextLength += textNodeData.textLength; - if (textNodeData.fontSize < MINIMAL_LEGIBLE_FONT_SIZE_PX) { - // Once a bad TextNode is identified, its parent Node is needed. - failingTextLength += textNodeData.textLength; - failingNodes.push({ - nodeId: 0, // Set later in fetchFailingNodeSourceRules. - parentNode: textNodeData.parentNode, - textLength: textNodeData.textLength, - fontSize: textNodeData.fontSize, - }); + + if (textNodeData.fontSize >= MINIMAL_LEGIBLE_FONT_SIZE_PX) { + continue; } + + // Once a bad TextNode is identified, its parent Node is needed. + failingTextLength += textNodeData.textLength; + failingNodes.push({ + nodeId: 0, // Set later in fetchFailingNodeSourceRules. + parentNode: textNodeData.parentNode, + textLength: textNodeData.textLength, + fontSize: textNodeData.fontSize, + }); } return {totalTextLength, failingTextLength, failingNodes}; @@ -294,7 +303,7 @@ class FontSize extends BaseGatherer { // Get the computed font-size style of every node. const snapshot = await session.sendCommand('DOMSnapshot.captureSnapshot', { - computedStyles: ['font-size'], + computedStyles: ['font-size', 'visibility'], }); const {