Skip to content

Commit 850be1f

Browse files
mkamakuraebidel
authored andcommitted
Change how to find the trace start event (#21)
* feat(google_search_feature.js): change how to find the trace start event * chore(google_search_features.js): remove trailing comma
1 parent 93cf709 commit 850be1f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

google_search_features.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async function collectFeatureTraceEvents(browser) {
189189

190190
// Filter out all trace events that aren't 1. blink feature usage
191191
// and 2. from the same process/thread id as our test page's main thread.
192-
const traceStartEvent = trace.traceEvents.find(e => e.name === 'TracingStartedInPage');
192+
const traceStartEvent = findTraceStartEvent(trace.traceEvents);
193193
const events = trace.traceEvents.filter(e => {
194194
return e.cat === 'disabled-by-default-blink.feature_usage' &&
195195
e.pid === traceStartEvent.pid && e.tid === traceStartEvent.tid;
@@ -207,6 +207,37 @@ async function collectFeatureTraceEvents(browser) {
207207
return events;
208208
}
209209

210+
/**
211+
* @param {Array} events
212+
* @return {Object}
213+
*/
214+
function findTraceStartEvent(events) {
215+
const startedInBrowserEvt = events.find(e => e.name === 'TracingStartedInBrowser');
216+
if (startedInBrowserEvt && startedInBrowserEvt.args.data && startedInBrowserEvt.args.data.frames) {
217+
const mainFrame = startedInBrowserEvt.args.data.frames.find(frame => !frame.parent);
218+
const pid = mainFrame && mainFrame.processId;
219+
const threadNameEvt = events.find(e => e.pid === pid && e.ph === 'M' &&
220+
e.cat === '__metadata' && e.name === 'thread_name' && e.args.name === 'CrRendererMain');
221+
222+
const tid = threadNameEvt && threadNameEvt.tid;
223+
if (pid && tid) {
224+
return {
225+
pid,
226+
tid
227+
};
228+
}
229+
}
230+
231+
// // Support legacy browser versions
232+
const startedInPageEvt = events.find(e => e.name === 'TracingStartedInPage');
233+
if (startedInPageEvt && startedInPageEvt.args && startedInPageEvt.args.data) {
234+
return {
235+
pid: startedInPageEvt.pid,
236+
tid: startedInPageEvt.tid
237+
};
238+
}
239+
}
240+
210241
/**
211242
* @param {!Object} feature
212243
*/

0 commit comments

Comments
 (0)