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(network-request): identify filesystem resources as non-network #12970

Merged
merged 4 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lighthouse-core/lib/network-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ class NetworkRequest {
*/
static isNonNetworkRequest(record) {
// The 'protocol' field in devtools a string more like a `scheme`
return URL.isNonNetworkProtocol(record.protocol);
return URL.isNonNetworkProtocol(record.protocol) ||
// But `protocol` can fail to be populated if the request fails, so fallback to scheme.
URL.isNonNetworkProtocol(record.parsedURL.scheme);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/url-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const allowedProtocols = [
const SECURE_SCHEMES = ['data', 'https', 'wss', 'blob', 'chrome', 'chrome-extension', 'about',
'filesystem'];
const SECURE_LOCALHOST_DOMAINS = ['localhost', '127.0.0.1'];
const NON_NETWORK_SCHEMES = ['blob', 'data', 'intent'];
const NON_NETWORK_SCHEMES = ['blob', 'data', 'intent', 'file'];

/**
* There is fancy URL rewriting logic for the chrome://settings page that we need to work around.
Expand Down
19 changes: 19 additions & 0 deletions lighthouse-core/test/lib/network-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,23 @@ describe('NetworkRequest', () => {
})).toBe(true);
});
});

describe('#isNonNetworkRequest', () => {
const isNonNetworkRequest = NetworkRequest.isNonNetworkRequest;

it('correctly identifies non-network records', () => {
// data protocol
expect(isNonNetworkRequest({protocol: 'data'})).toBe(true);

// filesystem scheme
expect(isNonNetworkRequest({protocol: '', parsedURL: {scheme: 'file'}})).toBe(true);
});

it('correctly identifies network records', () => {
expect(isNonNetworkRequest({
protocol: 'h2',
parsedURL: {scheme: 'http', host: 'google.com'},
})).toBe(false);
});
});
});