Skip to content

Commit 2299f94

Browse files
ebidelbrendankenny
authored andcommitted
handle Date.now uses with call site URL (#1277)
1 parent ef95039 commit 2299f94

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lighthouse-core/audits/dobetterweb/no-datenow.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ class NoDateNowAudit extends Audit {
6363

6464
const pageHost = new URL(artifacts.URL.finalUrl).host;
6565
// Filter usage from other hosts and keep eval'd code.
66+
// If there is no .url in the violation, include it in the results because
67+
// we cannot determine if it was from the user's page or a third party.
68+
// TODO: better extendedInfo for violations with no URL.
69+
// https://github.com/GoogleChrome/lighthouse/issues/1263
6670
const results = artifacts.DateNowUse.usage.filter(err => {
67-
return err.isEval ? !!err.url : new URL(err.url).host === pageHost;
71+
if (err.isEval) {
72+
return !!err.url;
73+
}
74+
return err.url ? new URL(err.url).host === pageHost : true;
6875
}).map(err => {
6976
return Object.assign({
7077
label: `line: ${err.line}, col: ${err.col}`,

lighthouse-core/test/audits/dobetterweb/no-datenow-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,19 @@ describe('Page does not use Date.now()', () => {
9999
assert.equal(auditResult.rawValue, false);
100100
assert.equal(auditResult.extendedInfo.value.length, 3);
101101
});
102+
103+
it('includes results when there is no .url', () => {
104+
const auditResult = DateNowUseAudit.audit({
105+
DateNowUse: {
106+
usage: [
107+
{line: 10, col: 1},
108+
{line: 2, col: 22}
109+
]
110+
},
111+
URL: {finalUrl: URL},
112+
});
113+
114+
assert.equal(auditResult.rawValue, false);
115+
assert.equal(auditResult.extendedInfo.value.length, 2);
116+
});
102117
});

0 commit comments

Comments
 (0)