@@ -189,7 +189,7 @@ async function collectFeatureTraceEvents(browser) {
189
189
190
190
// Filter out all trace events that aren't 1. blink feature usage
191
191
// 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 ) ;
193
193
const events = trace . traceEvents . filter ( e => {
194
194
return e . cat === 'disabled-by-default-blink.feature_usage' &&
195
195
e . pid === traceStartEvent . pid && e . tid === traceStartEvent . tid ;
@@ -207,6 +207,37 @@ async function collectFeatureTraceEvents(browser) {
207
207
return events ;
208
208
}
209
209
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
+
210
241
/**
211
242
* @param {!Object } feature
212
243
*/
0 commit comments