[go: nahoru, domu]

Skip to content
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(lightwallet): add firstPartyHostnames to budget.json #10324

Merged
merged 8 commits into from
Mar 3, 2020
Prev Previous commit
Next Next commit
Ignore non-network protocols
  • Loading branch information
khempenius committed Feb 27, 2020
commit 8a1b4af83df1dfdd57f52c7427133034547dbdd4
15 changes: 8 additions & 7 deletions lighthouse-core/computed/third-party-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ class ThirdPartySummary {
let count = 0;
let size = 0;
networkRecords.forEach((record) => {
const hostname = new URL(record.url).hostname;
// Ignore data URLs
if (hostname === '') {
return false;
const url = new URL(record.url);
// Removes trailing ":" from protocol
const protocol = url.protocol.slice(0, -1);
if (URL.NON_NETWORK_PROTOCOLS.includes(protocol)) {
return;
}
const isFirstParty = firstPartyHosts.find((hostExp) => {
const isFirstParty = firstPartyHosts.some((hostExp) => {
if (hostExp.startsWith('*.')) {
return hostname.endsWith(hostExp.slice(2));
return url.hostname.endsWith(hostExp.slice(2));
}
return hostname === hostExp;
return url.hostname === hostExp;
});
if (!isFirstParty) {
count += 1;
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/config/budget.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class Budget {
*/
static validateHostnames(hostnames) {
if (Array.isArray(hostnames) && hostnames.every(host => typeof host === 'string')) {
return hostnames.map(this.validateHostname);
return hostnames.map(Budget.validateHostname);
} else if (hostnames !== undefined) {
throw new Error(`firstPartyHostnames should be defined as an array of strings.`);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ class Budget {
const {firstPartyHostnames, ...invalidRest} = options;
Budget.assertNoExcessProperties(invalidRest, 'Options property');
budget.options = {};
budget.options.firstPartyHostnames = this.validateHostnames(firstPartyHostnames);
budget.options.firstPartyHostnames = Budget.validateHostnames(firstPartyHostnames);
} else if (options !== undefined) {
throw new Error(`Invalid options property in budget at index ${index}`);
}
Expand Down
9 changes: 3 additions & 6 deletions lighthouse-core/test/computed/third-party-summary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ describe('Third Party Summary computed', () => {
expect(result.count).toBe(0);
});

/**
* Data URLs should be ignored to avoid double counting.
* The filesize of a data URL is reflected in the filesize of the resource that contains it.
* A data URL does not result in a separate network request.
*/
it('ignores data URLs', async () => {
it('ignores records with non-network protocols', async () => {
context.settings.budgets = [{
path: '/',
options: {
Expand All @@ -158,6 +153,8 @@ describe('Third Party Summary computed', () => {
artifacts = mockArtifacts([
{url: 'http://example.com/file.html', resourceType: 'Document', transferSize: 30},
{url: 'data:image/png;base64,iVBORw0KGgoAA', resourceType: 'Image', transferSize: 10},
{url: 'blob:http://www.example.com/dflskdfjlkj', resourceType: 'Other', transferSize: 99},
{url: 'intent://example.com', resourceType: 'Other', transferSize: 1},
]);

const result = await ComputedThirdPartySummary.request(artifacts, context);
Expand Down
17 changes: 14 additions & 3 deletions proto/sample_v2_round_trip.json
Original file line number Diff line number Diff line change
Expand Up @@ -2233,9 +2233,8 @@
"sizeOverBudget": 7520.0
},
{
"countOverBudget": "1 request",
"label": "Third-party",
"requestCount": 2.0,
"requestCount": 1.0,
"resourceType": "third-party",
"size": 30174.0,
"sizeOverBudget": 4574.0
Expand Down Expand Up @@ -2427,6 +2426,12 @@
"resourceType": "script",
"size": 103675.0
},
{
"label": "Third-party",
"requestCount": 1.0,
"resourceType": "third-party",
"size": 30174.0
},
{
"label": "Image",
"requestCount": 2.0,
Expand Down Expand Up @@ -2465,7 +2470,7 @@
},
{
"label": "Third-party",
"requestCount": 2.0,
"requestCount": 1.0,
"resourceType": "third-party",
"size": 30174.0
}
Expand Down Expand Up @@ -4770,6 +4775,12 @@
"name": "lh:computed:ResourceSummary",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:ThirdPartySummary",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
Expand Down