-
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
Merged
Fixes #1282 #1288
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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