Skip to content

Commit

Permalink
core(trace-of-tab): only use navstart of chrome/http documents (#5917)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored Aug 29, 2018
1 parent 686afac commit 24a855d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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

0 comments on commit 24a855d

Please sign in to comment.