From 3b1ec70e8f22703ffbaa1c2efe85c03154668e95 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 15 May 2018 13:22:49 -0700 Subject: [PATCH 1/3] core(violation-audit): de-dupe items by URL and label --- lighthouse-core/audits/violation-audit.js | 11 ++++++++++- .../dobetterweb/uses-passive-event-listeners-test.js | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lighthouse-core/audits/violation-audit.js b/lighthouse-core/audits/violation-audit.js index 2060520045fc..55a0dfc49555 100644 --- a/lighthouse-core/audits/violation-audit.js +++ b/lighthouse-core/audits/violation-audit.js @@ -14,10 +14,19 @@ class ViolationAudit extends Audit { * @return {Array} */ static getViolationResults(artifacts, pattern) { + const seen = new Set(); return artifacts.ChromeConsoleMessages .map(message => message.entry) .filter(entry => entry.url && entry.source === 'violation' && pattern.test(entry.text)) - .map(entry => Object.assign({label: `line: ${entry.lineNumber}`}, entry)); + .map(entry => Object.assign({label: `line: ${entry.lineNumber}`}, entry)) + .filter(entry => { + // Filter out duplicate entries by URL/label since they are not differentiable to the user + // @see https://github.com/GoogleChrome/lighthouse/issues/5218 + const key = `${entry.url}!${entry.label}`; + if (seen.has(key)) return false; + seen.add(key); + return true; + }); } } diff --git a/lighthouse-core/test/audits/dobetterweb/uses-passive-event-listeners-test.js b/lighthouse-core/test/audits/dobetterweb/uses-passive-event-listeners-test.js index 0a8c3d734ff1..1b7d4c4c8556 100644 --- a/lighthouse-core/test/audits/dobetterweb/uses-passive-event-listeners-test.js +++ b/lighthouse-core/test/audits/dobetterweb/uses-passive-event-listeners-test.js @@ -18,6 +18,7 @@ describe('Page uses passive events listeners where applicable', () => { ChromeConsoleMessages: [ {entry: {source: 'violation', url: 'https://example.com/', text}}, {entry: {source: 'violation', url: 'https://example2.com/two', text}}, + {entry: {source: 'violation', url: 'https://example2.com/two', text}}, // duplicate {entry: {source: 'violation', url: 'http://abc.com/', text: 'No document.write'}}, {entry: {source: 'deprecation', url: 'https://example.com/two'}}, ], From dcca4ecc890d36c186aaa0bab3bd5d524b25a5c4 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 15 May 2018 13:43:23 -0700 Subject: [PATCH 2/3] remove unnecessary properties --- lighthouse-core/audits/violation-audit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lighthouse-core/audits/violation-audit.js b/lighthouse-core/audits/violation-audit.js index 55a0dfc49555..b259537eeddf 100644 --- a/lighthouse-core/audits/violation-audit.js +++ b/lighthouse-core/audits/violation-audit.js @@ -11,14 +11,14 @@ class ViolationAudit extends Audit { /** * @param {LH.Artifacts} artifacts * @param {RegExp} pattern - * @return {Array} + * @return {Array<{label: string, url?: string}>} */ static getViolationResults(artifacts, pattern) { const seen = new Set(); return artifacts.ChromeConsoleMessages .map(message => message.entry) .filter(entry => entry.url && entry.source === 'violation' && pattern.test(entry.text)) - .map(entry => Object.assign({label: `line: ${entry.lineNumber}`}, entry)) + .map(entry => ({label: `line: ${entry.lineNumber}`, url: entry.url})) .filter(entry => { // Filter out duplicate entries by URL/label since they are not differentiable to the user // @see https://github.com/GoogleChrome/lighthouse/issues/5218 From 1060df5b074f27661d385be89213575858e1fa5a Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 15 May 2018 13:43:46 -0700 Subject: [PATCH 3/3] golden lhr --- lighthouse-core/test/results/sample_v2.json | 225 +------------------- 1 file changed, 9 insertions(+), 216 deletions(-) diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json index e342928edad1..5625ff0bd0b3 100644 --- a/lighthouse-core/test/results/sample_v2.json +++ b/lighthouse-core/test/results/sample_v2.json @@ -2314,57 +2314,11 @@ "items": [ { "label": "line: 277", - "source": "violation", - "level": "verbose", - "text": "Only request geolocation information in response to a user gesture.", - "timestamp": 1519974785839.5, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 277, - "stackTrace": { - "callFrames": [ - { - "functionName": "geolocationOnStartTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 277, - "columnNumber": 24 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 345, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" }, { "label": "line: 281", - "source": "violation", - "level": "verbose", - "text": "Only request geolocation information in response to a user gesture.", - "timestamp": 1519974785840.8, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 281, - "stackTrace": { - "callFrames": [ - { - "functionName": "geolocationOnStartTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 281, - "columnNumber": 40 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 345, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" } ] } @@ -2393,84 +2347,15 @@ "items": [ { "label": "line: 178", - "source": "violation", - "level": "verbose", - "text": "Avoid using document.write().", - "timestamp": 1519974785808.58, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 178, - "stackTrace": { - "callFrames": [ - { - "functionName": "documentWriteTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 178, - "columnNumber": 11 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 339, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" }, { "label": "line: 179", - "source": "violation", - "level": "verbose", - "text": "Avoid using document.write().", - "timestamp": 1519974785809.4, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 179, - "stackTrace": { - "callFrames": [ - { - "functionName": "documentWriteTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 179, - "columnNumber": 11 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 339, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" }, { "label": "line: 180", - "source": "violation", - "level": "verbose", - "text": "Avoid using document.write().", - "timestamp": 1519974785810.25, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 180, - "stackTrace": { - "callFrames": [ - { - "functionName": "documentWriteTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 180, - "columnNumber": 11 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 339, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" } ] } @@ -2632,30 +2517,7 @@ "items": [ { "label": "line: 287", - "source": "violation", - "level": "verbose", - "text": "Only request notification permission in response to a user gesture.", - "timestamp": 1519974785841.72, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 287, - "stackTrace": { - "callFrames": [ - { - "functionName": "notificationOnStartTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 287, - "columnNumber": 15 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 346, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" } ] } @@ -2802,84 +2664,15 @@ "items": [ { "label": "line: 26", - "source": "violation", - "level": "verbose", - "text": "Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952", - "timestamp": 1519974785779.5, - "url": "http://localhost:10200/dobetterweb/dbw_tester.js", - "lineNumber": 26, - "stackTrace": { - "callFrames": [ - { - "functionName": "", - "scriptId": "25", - "url": "http://localhost:10200/dobetterweb/dbw_tester.js", - "lineNumber": 26, - "columnNumber": 11 - }, - { - "functionName": "", - "scriptId": "25", - "url": "http://localhost:10200/dobetterweb/dbw_tester.js", - "lineNumber": 39, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.js" }, { "label": "line: 222", - "source": "violation", - "level": "verbose", - "text": "Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952", - "timestamp": 1519974785837.14, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 222, - "stackTrace": { - "callFrames": [ - { - "functionName": "passiveEventsListenerTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 222, - "columnNumber": 9 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 344, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" }, { "label": "line: 248", - "source": "violation", - "level": "verbose", - "text": "Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952", - "timestamp": 1519974785837.83, - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 248, - "stackTrace": { - "callFrames": [ - { - "functionName": "passiveEventsListenerTest", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 248, - "columnNumber": 5 - }, - { - "functionName": "", - "scriptId": "29", - "url": "http://localhost:10200/dobetterweb/dbw_tester.html", - "lineNumber": 344, - "columnNumber": 2 - } - ] - } + "url": "http://localhost:10200/dobetterweb/dbw_tester.html" } ] }