@@ -38,7 +38,7 @@ const yargsInput = yargs(hideBin(process.argv))
3838 } )
3939 . option ( 'test-target' , {
4040 describe : 'Which panel do you want to run the examples against?' ,
41- choices : [ 'elements' , 'performance' ] ,
41+ choices : [ 'elements' , 'performance-main-thread' , 'performance-insights '] ,
4242 demandOption : true ,
4343 } )
4444 . parseSync ( ) ;
@@ -314,12 +314,12 @@ class Example {
314314 * and explanation.
315315 * @param {puppeteer.Page } page - the target page
316316 * @param {puppeteer.Page } devtoolsPage - the DevTools page
317- * @returns {Promise<{idx: number, queries: string[], explanation: string, performanceAnnotation?: puppeteer.ElementHandle<HTMLElement>}> }
317+ * @returns {Promise<{idx: number, queries: string[], explanation: string, performanceAnnotation?: puppeteer.ElementHandle<HTMLElement>, rawComment: Record<string, string> }> }
318318 */
319319 async #generateMetadata( page , devtoolsPage ) {
320320 /** @type {puppeteer.ElementHandle<HTMLElement>|undefined } */
321321 let annotation = undefined ;
322- if ( userArgs . testTarget === 'performance' ) {
322+ if ( userArgs . testTarget === 'performance-main-thread ' ) {
323323 annotation = await this . #lookForAnnotatedPerformanceEvent( devtoolsPage ) ;
324324 }
325325
@@ -339,6 +339,7 @@ class Example {
339339 queries,
340340 explanation : comment . explanation ,
341341 performanceAnnotation : annotation ,
342+ rawComment : comment ,
342343 } ;
343344 }
344345
@@ -372,12 +373,13 @@ class Example {
372373 const devtoolsPage = await devtoolsTarget . asPage ( ) ;
373374 this . log ( '[Info]: Got devtools page' ) ;
374375
375- if ( userArgs . testTarget === 'performance' ) {
376+ if ( userArgs . testTarget === 'performance-main-thread' || userArgs . testTarget === 'performance-insights ') {
376377 const fileName = await TraceDownloader . run ( this , page ) ;
377378 await this . #loadPerformanceTrace( devtoolsPage , fileName ) ;
378379 }
379380
380- const { idx, queries, explanation, performanceAnnotation} = await this . #generateMetadata( page , devtoolsPage ) ;
381+ const { idx, queries, explanation, performanceAnnotation, rawComment} =
382+ await this . #generateMetadata( page , devtoolsPage ) ;
381383 this . log ( '[Info]: Running...' ) ;
382384 // Strip comments to prevent LLM from seeing it.
383385 await page . evaluate ( ( ) => {
@@ -419,7 +421,7 @@ class Example {
419421 await devtoolsPage . locator ( ':scope >>> #tab-elements' ) . click ( ) ;
420422 }
421423
422- if ( userArgs . testTarget === 'performance' && performanceAnnotation ) {
424+ if ( userArgs . testTarget === 'performance-main-thread ' && performanceAnnotation ) {
423425 this . log ( '[Info]: selecting event in the performance timeline' ) ;
424426 await devtoolsPage . locator ( ':scope >>> #tab-timeline' ) . setTimeout ( 5000 ) . click ( ) ;
425427 // Clicking on the annotation will also have the side-effect of selecting the event
@@ -430,10 +432,42 @@ class Example {
430432 ) ;
431433 }
432434
435+ if ( userArgs . testTarget === 'performance-insights' ) {
436+ const insight = rawComment . insight ;
437+ if ( ! insight ) {
438+ throw new Error ( 'Cannot execute performance-insights example without "Insight:" in example comment metadata.' ) ;
439+ }
440+
441+ this . log ( '[Info]: selecting insight in the performance panel' ) ;
442+ await devtoolsPage . locator ( ':scope >>> #tab-timeline' ) . setTimeout ( 5000 ) . click ( ) ;
443+
444+ // Ensure the sidebar is open. If this selector is not found then we assume the sidebar is already open.
445+ const sidebarButton = await devtoolsPage . $ ( 'aria/Show sidebar' ) ;
446+ if ( sidebarButton ) {
447+ await sidebarButton . click ( ) ;
448+ }
449+
450+ this . log ( `[Info]: expanding Insight "${ insight } "` ) ;
451+ // Now find the header for the right insight, and click to expand it.
452+ await devtoolsPage . locator ( `aria/View details for ${ insight } ` ) . setTimeout ( 5000 ) . click ( ) ;
453+ }
454+
433455 this . log ( '[Info]: Locating AI assistance tab' ) ;
434- await devtoolsPage . locator ( 'aria/Customize and control DevTools' ) . click ( ) ;
435- await devtoolsPage . locator ( 'aria/More tools' ) . click ( ) ;
436- await devtoolsPage . locator ( 'aria/AI assistance' ) . click ( ) ;
456+ // Because there are two Performance AI flows, to ensure we activate the
457+ // right one for Insights, we go via the "Ask AI" button in the Insights
458+ // sidebar directly to select the right insight.
459+ // For the other flows, we select the right context item in the right
460+ // panel, and then open the AI Assistance panel.
461+ if ( userArgs . testTarget === 'performance-insights' ) {
462+ // Now click the "Ask AI" button to open up the AI assistance panel
463+ await devtoolsPage . locator ( ':scope >>> devtools-button[data-ask-ai]' ) . setTimeout ( 5000 ) . click ( ) ;
464+ this . log ( '[Info]: Opened AI assistance tab' ) ;
465+ } else {
466+ await devtoolsPage . locator ( 'aria/Customize and control DevTools' ) . click ( ) ;
467+ await devtoolsPage . locator ( 'aria/More tools' ) . click ( ) ;
468+ await devtoolsPage . locator ( 'aria/AI assistance' ) . click ( ) ;
469+ }
470+
437471 this . log ( '[Info]: Opened AI assistance tab' ) ;
438472
439473 this . #page = page ;
@@ -463,10 +497,10 @@ class Example {
463497 switch ( userArgs . testTarget ) {
464498 case 'elements' :
465499 return 'aria/Ask a question about the selected element' ;
466- case 'performance' :
500+ case 'performance-main-thread ' :
467501 return 'aria/Ask a question about the selected item and its call tree' ;
468- default :
469- throw new Error ( `Unknown --test-target: ${ userArgs . testTarget } ` ) ;
502+ case 'performance-insights' :
503+ return 'aria/Ask a question about the selected performance insight' ;
470504 }
471505 }
472506
0 commit comments