Skip to content

Commit

Permalink
polish: do not fail loadfast4pwa for internal redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed May 17, 2017
1 parent aebc9bd commit 0340807
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lighthouse-core/audits/load-fast-enough-for-pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const Formatter = require('../report/formatter');
// https://developers.google.com/web/progressive-web-apps/checklist
const MAXIMUM_TTFI = 10 * 1000;

const WHITELISTED_STATUS_CODES = [307];

class LoadFastEnough4Pwa extends Audit {
/**
* @return {!AuditMeta}
Expand All @@ -55,11 +57,12 @@ class LoadFastEnough4Pwa extends Audit {
return artifacts.requestNetworkRecords(devtoolsLogs).then(networkRecords => {
const firstRequestLatenciesByOrigin = new Map();
networkRecords.forEach(record => {
// Ignore requests that don't have valid origin, timing data, came from the cache, or are
// not finished.
// Ignore requests that don't have valid origin, timing data, came from the cache, were
// redirected by Chrome without going to the network, or are not finished.
const fromCache = record._fromDiskCache || record._fromMemoryCache;
const origin = URL.getOrigin(record._url);
if (!origin || !record._timing || fromCache || !record.finished) {
if (!origin || !record._timing || fromCache ||
WHITELISTED_STATUS_CODES.includes(record.statusCode) || !record.finished) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions lighthouse-core/test/audits/load-fast-enough-for-pwa-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,17 @@ describe('PWA: load-fast-enough-for-pwa audit', () => {
// latencies are very long
const urlA = 'https://google.com';
const urlB = 'https://example.com';
const urlC = 'https://example-c.com';
const mockNetworkRecords = [
{_timing: {sendEnd: 0, receiveHeadersEnd: 250}, finished: true, _url: urlA, _startTime: 0},
{_timing: {sendEnd: 0, receiveHeadersEnd: 250}, finished: true, _url: urlB},
// ignored for not having timing
{ },
// ignored for not being the first of the origin
{_timing: {sendEnd: 0, receiveHeadersEnd: 100}, finished: true, _url: urlA, _startTime: 100},
// ignored for being redirected internally
{_timing: {sendEnd: 0, receiveHeadersEnd: 100}, finished: true, _url: urlC, _startTime: 0,
statusCode: 307},
// ignored for not finishing
{_timing: {sendEnd: 0, receiveHeadersEnd: -1}, finished: false},
];
Expand Down

0 comments on commit 0340807

Please sign in to comment.