Skip to content

Commit

Permalink
core: support traces missing TracingStartedInBrowser (#7122)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and brendankenny committed Apr 29, 2019
1 parent 6fae88c commit a99ff82
Show file tree
Hide file tree
Showing 4 changed files with 2,262 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lighthouse-core/lib/traces/tracing-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,29 @@ class TraceProcessor {
}
}

// Support the case where everything else fails, see https://github.com/GoogleChrome/lighthouse/issues/7118.
// If we can't find either TracingStarted event, then we'll fallback to the first navStart that
// looks like it was loading the main frame with a real URL. Because the schema for this event
// has changed across Chrome versions, we'll be extra defensive about finding this case.
const navStartEvt = events.find(e => Boolean(e.name === 'navigationStart' && e.args &&
e.args.data && e.args.data.isLoadingMainFrame && e.args.data.documentLoaderURL));
// Find the first resource that was requested and make sure it agrees on the id.
const firstResourceSendEvt = events.find(e => e.name === 'ResourceSendRequest');
// We know that these properties exist if we found the events, but TSC doesn't.
if (navStartEvt && navStartEvt.args && navStartEvt.args.data &&
firstResourceSendEvt &&
firstResourceSendEvt.pid === navStartEvt.pid &&
firstResourceSendEvt.tid === navStartEvt.tid) {
const frameId = navStartEvt.args.frame;
if (frameId) {
return {
pid: navStartEvt.pid,
tid: navStartEvt.tid,
frameId,
};
}
}

throw new LHError(LHError.errors.NO_TRACING_STARTED);
}

Expand Down
7 changes: 7 additions & 0 deletions lighthouse-core/test/computed/trace-of-tab-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const assert = require('assert');
const fs = require('fs');
const badNavStartTrace = require('../fixtures/traces/bad-nav-start-ts.json');
const lateTracingStartedTrace = require('../fixtures/traces/tracingstarted-after-navstart.json');
const noTracingStartedTrace = require('../fixtures/traces/no-tracingstarted-m74.json');
const preactTrace = require('../fixtures/traces/preactjs.com_ts_of_undefined.json');
const noFMPtrace = require('../fixtures/traces/no_fmp_event.json');
const noFCPtrace = require('../fixtures/traces/airhorner_no_fcp.json');
Expand Down Expand Up @@ -162,6 +163,12 @@ describe('Trace of Tab computed artifact:', () => {
assert.equal(trace.navigationStartEvt.ts, 2193564790059);
});

it('handles no TracingStarted errors in m74+', async () => {
const trace = await TraceOfTab.compute_(noTracingStartedTrace);
expect(trace.mainFrameIds.frameId).toEqual('0E0B1AF0B1BA04676037345D18A71577');
expect(trace.firstContentfulPaintEvt.ts).toEqual(2610265036367);
});

it('stably sorts events', async () => {
const traceJson = fs.readFileSync(__dirname +
'/../fixtures/traces/tracingstarted-after-navstart.json', 'utf8');
Expand Down
Loading

0 comments on commit a99ff82

Please sign in to comment.