diff --git a/lighthouse-core/lib/page-functions.js b/lighthouse-core/lib/page-functions.js index 3bc0df208474..5b2ccb4c0364 100644 --- a/lighthouse-core/lib/page-functions.js +++ b/lighthouse-core/lib/page-functions.js @@ -375,7 +375,7 @@ function getNodeLabel(node) { if (str.length <= maxLength) { return str; } - return str.slice(0, maxLength - 1) + 'โ€ฆ'; + return Array.from(str).slice(0, maxLength - 1).join('') + 'โ€ฆ'; } const tagName = node.tagName.toLowerCase(); // html and body content is too broad to be useful, since they contain all page content diff --git a/lighthouse-core/test/lib/page-functions-test.js b/lighthouse-core/test/lib/page-functions-test.js index 90e8be1c2b25..24b6a3212116 100644 --- a/lighthouse-core/test/lib/page-functions-test.js +++ b/lighthouse-core/test/lib/page-functions-test.js @@ -116,6 +116,12 @@ describe('Page Functions', () => { assert.equal(pageFunctions.getNodeLabel(el).length, 80); }); + it('Truncates long text containing unicode surrogate pairs', () => { + const el = dom.createElement('div'); + el.innerText = Array(78).fill('a').join('') + '๐Ÿ’ก๐Ÿ’ก๐Ÿ’ก'; + assert.equal(pageFunctions.getNodeLabel(el), Array(78).fill('a').join('') + '๐Ÿ’กโ€ฆ'); + }); + it('Uses tag name for html tags', () => { const el = dom.createElement('html'); assert.equal(pageFunctions.getNodeLabel(el), 'html');