-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #1282 #1288
Fixes #1282 #1288
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,10 +61,25 @@ class NoConsoleTimeAudit extends Audit { | |
}); | ||
} | ||
|
||
let debugString; | ||
|
||
const pageHost = new URL(artifacts.URL.finalUrl).host; | ||
// Filter usage from other hosts and keep eval'd code. | ||
const results = artifacts.ConsoleTimeUsage.usage.filter(err => { | ||
return err.isEval ? !!err.url : new URL(err.url).host === pageHost; | ||
if (err.isEval) { | ||
return !!err.url; | ||
} | ||
|
||
// If the violation doesn't have a valid url, don't filter it out, but | ||
// warn the user that we don't know what the callsite is. | ||
try { | ||
return new URL(err.url).host === pageHost; | ||
} catch (e) { | ||
debugString = 'Lighthouse was unable to determine if some API uses ' + | ||
'were made by this page. It\'s possible a Chrome extension' + | ||
'content script or other eval\'d code is calling this API.'; | ||
} | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: move to inside catch block? feels a bit like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}).map(err => { | ||
return Object.assign({ | ||
label: `line: ${err.line}, col: ${err.col}` | ||
|
@@ -76,7 +91,8 @@ class NoConsoleTimeAudit extends Audit { | |
extendedInfo: { | ||
formatter: Formatter.SUPPORTED_FORMATS.URLLIST, | ||
value: results | ||
} | ||
}, | ||
debugString | ||
}); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,17 +61,25 @@ class NoDateNowAudit extends Audit { | |
}); | ||
} | ||
|
||
let debugString; | ||
|
||
const pageHost = new URL(artifacts.URL.finalUrl).host; | ||
// Filter usage from other hosts and keep eval'd code. | ||
// If there is no .url in the violation, include it in the results because | ||
// we cannot determine if it was from the user's page or a third party. | ||
// TODO: better extendedInfo for violations with no URL. | ||
// https://github.com/GoogleChrome/lighthouse/issues/1263 | ||
const results = artifacts.DateNowUse.usage.filter(err => { | ||
if (err.isEval) { | ||
return !!err.url; | ||
} | ||
return err.url ? new URL(err.url).host === pageHost : true; | ||
|
||
// If the violation doesn't have a valid url, don't filter it out, but | ||
// warn the user that we don't know what the callsite is. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one could argue this is ripe for a helper refactor, but we only have 2 atm. Don't think that warrants it just yet. |
||
try { | ||
return new URL(err.url).host === pageHost; | ||
} catch (e) { | ||
debugString = 'Lighthouse was unable to determine if some API uses ' + | ||
'were made by this page. It\'s possible a Chrome extension' + | ||
'content script or other eval\'d code is calling this API.'; | ||
} | ||
return true; | ||
}).map(err => { | ||
return Object.assign({ | ||
label: `line: ${err.line}, col: ${err.col}`, | ||
|
@@ -84,7 +92,8 @@ class NoDateNowAudit extends Audit { | |
extendedInfo: { | ||
formatter: Formatter.SUPPORTED_FORMATS.URLLIST, | ||
value: results | ||
} | ||
}, | ||
debugString | ||
}); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -702,7 +702,8 @@ class Driver { | |
'Driver failure: Expected evaluateAsync results to be an array ' + | ||
`but got "${JSON.stringify(result)}" instead.`); | ||
} | ||
return result; | ||
// Filter out usage from extension content scripts. | ||
return result.filter(item => !item.isExtension); | ||
}); | ||
}; | ||
|
||
|
@@ -738,24 +739,36 @@ function captureJSCallUsage(funcRef, set) { | |
// First frame is the function we injected (the one that just threw). | ||
// Second, is the actual callsite of the funcRef we're after. | ||
const callFrame = structStackTrace[1]; | ||
let url = callFrame.getFileName(); | ||
let url = callFrame.getFileName() || callFrame.getEvalOrigin(); | ||
const line = callFrame.getLineNumber(); | ||
const col = callFrame.getColumnNumber(); | ||
const isEval = callFrame.isEval(); | ||
let isExtension = false; | ||
const stackTrace = structStackTrace.slice(1).map(callsite => callsite.toString()); | ||
|
||
// If we don't have an URL, (e.g. eval'd code), use the last entry in the | ||
// stack trace to give some context: eval(<context>):<line>:<col> | ||
// If we don't have an URL, (e.g. eval'd code), use the 2nd entry in the | ||
// stack trace. First is eval context: eval(<context>):<line>:<col>. | ||
// Second is the callsite where eval was called. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice I like this improvement |
||
// See https://crbug.com/646849. | ||
if (!url) { | ||
if (isEval) { | ||
url = stackTrace[1]; | ||
} | ||
|
||
// Chrome extension content scripts can produce an empty .url and | ||
// "<anonymous>:line:col" for the first entry in the stack trace. | ||
if (stackTrace[0].startsWith('<anonymous>')) { | ||
// Note: Although captureFunctionCallSites filters out crx usage, | ||
// filling url here provides context. We may want to keep those results | ||
// some day. | ||
url = stackTrace[0]; | ||
isExtension = true; | ||
} | ||
|
||
// TODO: add back when we want stack traces. | ||
// Stack traces were removed from the return object in | ||
// https://github.com/GoogleChrome/lighthouse/issues/957 so callsites | ||
// would be unique. | ||
return {url, args, line, col, isEval}; // return value is e.stack | ||
return {url, args, line, col, isEval, isExtension}; // return value is e.stack | ||
}; | ||
const e = new __nativeError(`__called ${funcRef.name}__`); | ||
set.add(JSON.stringify(e.stack)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given our fail/no fail smoke tests right now, what benefit does this add? (seems like we'd be unable to catch
eval
not working here too actually)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much, just wanted to check that
Date.now()
outside of an inner function was also producing results. Until smokehouse audits number of violations, this won't do much other than a manual verify.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright just checking, sg