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-of-tab): only use navstart of chrome/http documents #5917

Merged
merged 8 commits into from
Aug 29, 2018
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: 14 additions & 1 deletion lighthouse-core/gather/computed/trace-of-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@ const TracingProcessor = require('../../lib/traces/tracing-processor');
const LHError = require('../../lib/errors');
const Sentry = require('../../lib/sentry');

const ACCEPTABLE_NAVIGATION_URL_REGEX = /^(chrome|https?):/;

class TraceOfTab extends ComputedArtifact {
get name() {
return 'TraceOfTab';
}

/**
* Returns true if the event is a navigation start event of a document whose URL seems valid.
*
* @param {LH.TraceEvent} event
*/
static isNavigationStartOfInterest(event) {
return event.name === 'navigationStart' &&
(!event.args.data || !event.args.data.documentLoaderURL ||
ACCEPTABLE_NAVIGATION_URL_REGEX.test(event.args.data.documentLoaderURL));
}

/**
* @param {LH.TraceEvent[]} traceEvents
* @param {(e: LH.TraceEvent) => boolean} filter
Expand Down Expand Up @@ -79,7 +92,7 @@ class TraceOfTab extends ComputedArtifact {
const frameEvents = keyEvents.filter(e => e.args.frame === frameId);

// Our navStart will be the last frame navigation in the trace
const navigationStart = frameEvents.filter(e => e.name === 'navigationStart').pop();
const navigationStart = frameEvents.filter(TraceOfTab.isNavigationStartOfInterest).pop();
if (!navigationStart) throw new LHError(LHError.errors.NO_NAVSTART);

// Find our first paint of this frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@
"frame": "0x25edaa521e58"
},
"tts": 826016
},
{
"pid": 6117,
"tid": 775,
"ts": 1805897263653,
"ph": "R",
"cat": "blink.user_timing",
"name": "navigationStart",
"args": {
"frame": "0x25edaa521e58",
"data": {"documentLoaderURL": "intent://this-one-should-be-ignored"}
},
"tts": 673412
},
{
"pid": 6117,
Expand Down
1 change: 1 addition & 0 deletions typings/externs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ declare global {
fileName?: string;
snapshot?: string;
data?: {
documentLoaderURL?: string;
frames?: {
frame: string;
parent?: string;
Expand Down