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(tracing): support missing TracingStartedInBrowser #7122

Merged
merged 6 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
21 changes: 21 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,27 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

back in 2016, we used a diff hack.. which thread had the most events: 1c62db3#diff-a6b18ac2e75e02d6c1e53d586a319643R101
(it could be improved now to just consider renderer threads).

Since this is an uber-fallback case, I wonder if we should try that instead?

@aslushnikov points out that corp managed chrome's that have required chrome apps probably have very active extension threads. might mess this up. also agrees that "most active" is gross. :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an uber-fallback case, I wonder if we should try that instead?

Instead of instead, double check it with most events? :)

// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏆

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.tid === navStartEvt.tid) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tid's for renderer are usually the same, so you gotta compare pids as well.

oh, assuming navstart is sent on the same pid? is it? ugh i love this shit. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, love is a..... word, haha lovehate? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. early on the approval.

we gotta check pids here.

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