-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
core(entity-classification): classify chrome extensions into separate entities #15017
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dfb949c
core(entity-classification): classify chrome extensions into its own …
alexnj 2671ab8
add tests
alexnj 3796d7a
Merge branch 'main' into chrome-extensions-classification
alexnj 10cf5a6
Review changes
alexnj 98615d3
Upgrade to Level 2 classification - resolve each extension to their e…
alexnj ed16c1d
Merge remote-tracking branch 'origin/main' into chrome-extensions-cla…
alexnj 40d8880
Merge remote-tracking branch 'origin/main' into chrome-extensions-cla…
alexnj 0661062
Recognize unknown chrome extensions + refactor.
alexnj 8f97e1b
Merge remote-tracking branch 'origin/main' into chrome-extensions-cla…
alexnj dbd9600
fix some typos + comment for the node url parser spec difference
alexnj aef3345
Merge branch 'main' into chrome-extensions-classification
alexnj f366795
private fn name changes
alexnj 15f7fc7
fn name
alexnj 3b44036
Merge branch 'main' into chrome-extensions-classification
alexnj 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,51 @@ import thirdPartyWeb from '../lib/third-party-web.js'; | |
/** @typedef {Map<string, LH.Artifacts.Entity>} EntityCache */ | ||
|
||
class EntityClassification { | ||
/** | ||
* @param {EntityCache} entityCache | ||
* @param {string} url | ||
* @param {string=} optionalName | ||
* @return {LH.Artifacts.Entity} | ||
*/ | ||
static makupChromeExtensionEntity(entityCache, url, optionalName) { | ||
const origin = Util.getChromeExtensionOrigin(url); | ||
const host = new URL(origin).host; | ||
const name = optionalName || host; | ||
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. I'm defaulting unknown chrome extensions' names to the |
||
|
||
const cachedEntity = entityCache.get(origin); | ||
if (cachedEntity) return cachedEntity; | ||
|
||
const chromeExtensionEntity = { | ||
name, | ||
company: name, | ||
category: 'Chrome Extension', | ||
homepage: 'https://chromewebstore.google.com/detail/' + host, | ||
categories: [], | ||
domains: [], | ||
averageExecutionTime: 0, | ||
totalExecutionTime: 0, | ||
totalOccurrences: 0, | ||
}; | ||
|
||
entityCache.set(origin, chromeExtensionEntity); | ||
return chromeExtensionEntity; | ||
} | ||
|
||
/** | ||
* @param {EntityCache} entityCache | ||
* @param {string} url | ||
* @return {LH.Artifacts.Entity | undefined} | ||
*/ | ||
static makeUpAnEntity(entityCache, url) { | ||
if (!UrlUtils.isValid(url)) return; | ||
// We can make up an entity only for those URLs with a valid domain attached. | ||
// So we further restrict from allowed URLs to (http/https). | ||
if (!Util.createOrReturnURL(url).protocol.startsWith('http')) return; | ||
|
||
const parsedUrl = Util.createOrReturnURL(url); | ||
if (parsedUrl.protocol === 'chrome-extension:') { | ||
return EntityClassification.makupChromeExtensionEntity(entityCache, url); | ||
} | ||
|
||
// Make up an entity only for valid http/https URLs. | ||
if (!parsedUrl.protocol.startsWith('http')) return; | ||
|
||
const rootDomain = Util.getRootDomain(url); | ||
if (!rootDomain) return; | ||
|
@@ -43,6 +78,24 @@ class EntityClassification { | |
return unrecognizedEntity; | ||
} | ||
|
||
/** | ||
* Preload Chrome extensions found in the devtoolsLog into cache. | ||
* @param {EntityCache} entityCache | ||
* @param {LH.DevtoolsLog} devtoolsLog | ||
*/ | ||
static preloadChromeExtensionsToCache_(entityCache, devtoolsLog) { | ||
for (const entry of devtoolsLog.values()) { | ||
if (entry.method !== 'Runtime.executionContextCreated') continue; | ||
|
||
const origin = entry.params.context.origin; | ||
if (!origin.startsWith('chrome-extension:')) continue; | ||
if (entityCache.has(origin)) continue; | ||
|
||
EntityClassification.makupChromeExtensionEntity(entityCache, origin, | ||
entry.params.context.name); | ||
} | ||
} | ||
|
||
/** | ||
* @param {{URL: LH.Artifacts['URL'], devtoolsLog: LH.DevtoolsLog}} data | ||
* @param {LH.Artifacts.ComputedContext} context | ||
|
@@ -57,6 +110,8 @@ class EntityClassification { | |
/** @type {Map<LH.Artifacts.Entity, Set<string>>} */ | ||
const urlsByEntity = new Map(); | ||
|
||
EntityClassification.preloadChromeExtensionsToCache_(madeUpEntityCache, data.devtoolsLog); | ||
|
||
for (const record of networkRecords) { | ||
const {url} = record; | ||
if (entityByUrl.has(url)) continue; | ||
|
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
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
Oops, something went wrong.
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.
nit