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(trace-processor): ignore navigationStart with falsy document url #13848

Merged
merged 7 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 10 additions & 5 deletions lighthouse-core/lib/tracehouse/trace-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ class TraceProcessor {
* Returns true if the event is a navigation start event of a document whose URL seems valid.
*
* @param {LH.TraceEvent} event
* @return {boolean}
*/
static _isNavigationStartOfInterest(event) {
return event.name === 'navigationStart' &&
(!event.args.data || !event.args.data.documentLoaderURL ||
adamraine marked this conversation as resolved.
Show resolved Hide resolved
ACCEPTABLE_NAVIGATION_URL_REGEX.test(event.args.data.documentLoaderURL));
if (event.name !== 'navigationStart') return false;
// COMPAT: support pre-m67 test traces before `args.data` added to all navStart events.
// TODO: remove next line when old test traces (e.g. progressive-app-m60.json) are updated.
if (event.args.data?.documentLoaderURL === undefined) return true;
if (!event.args.data?.documentLoaderURL) return false;
Copy link
Member

Choose a reason for hiding this comment

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

maybe some variation on

Suggested change
if (!event.args.data?.documentLoaderURL) return false;
// COMPAT: support pre-m67 test traces before `args.data` added to all navStart events.
// TODO: remove next line when old test traces (progressive-app-m60.json) are updated.
if (!event.args.data) return true;
if (!event.args.data?.documentLoaderURL) return false;

?

I'm 100% good with updating well past m60 for a test trace, but we could fix the test failure to unblock CI and then update the tests? Maybe it would be a trivial update, but we'd want to make sure it exercises the same execution paths, and it's currently used in at least 227 tests, probably more that just aren't currently failing with NO_NAVSTART.

Copy link
Member

Choose a reason for hiding this comment

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

for future reference, CL from @deepanjanroy that added args.data to all navStart events: https://chromium-review.googlesource.com/975986

Copy link
Member Author

Choose a reason for hiding this comment

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

Ope I just thought that the unit failures were all #13846. Didn't think to check.

Copy link
Member Author

@adamraine adamraine Apr 13, 2022

Choose a reason for hiding this comment

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

There were some test traces with event.args.data but no documentLoaderURL. I updated this to check if documentLoaderURL is specifically undefined.

Copy link
Member

Choose a reason for hiding this comment

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

haha, ok then, so when we need to update the trace tests just removing that one line will be where to start

return ACCEPTABLE_NAVIGATION_URL_REGEX.test(event.args.data.documentLoaderURL);
}

/**
Expand Down Expand Up @@ -462,8 +466,9 @@ class TraceProcessor {
// 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?.data?.isLoadingMainFrame && e.args.data.documentLoaderURL));
const navStartEvt = events.find(e =>
this._isNavigationStartOfInterest(e) && e.args.data?.isLoadingMainFrame
);
// 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.
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/create-test-trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function createTestTrace(options) {
cat: 'blink.user_timing',
args: {
frame: rootFrame,
data: {documentLoaderURL: ''},
data: {documentLoaderURL: 'https://example.com/'},
},
}, {
name: 'TracingStartedInBrowser',
Expand Down