@@ -6,6 +6,7 @@ import type * as puppeteer from 'puppeteer-core';
66
77import { AsyncScope } from '../../conductor/async-scope.js' ;
88import { installPageErrorHandlers } from '../../conductor/events.js' ;
9+ import { TestConfig } from '../../conductor/test_config.js' ;
910
1011import { PageWrapper } from './page-wrapper.js' ;
1112
@@ -26,6 +27,8 @@ type DeducedElementType<ElementType extends Element|null, Selector extends strin
2627 ElementType extends null ? puppeteer . NodeFor < Selector > : ElementType ;
2728
2829export class DevToolsPage extends PageWrapper {
30+ #currentHighlightedElement?: HighlightedElement ;
31+
2932 async setExperimentEnabled ( experiment : string , enabled : boolean ) {
3033 await this . evaluate ( `(async () => {
3134 const Root = await import('./core/root/root.js');
@@ -112,9 +115,24 @@ export class DevToolsPage extends PageWrapper {
112115 const rootElement = root ? root : this . page ;
113116 const element = await rootElement . $ ( `${ handler } /${ selector } ` ) as
114117 puppeteer . ElementHandle < DeducedElementType < ElementType , Selector > > ;
118+ await this . #maybeHighlight( element ) ;
115119 return element ;
116120 }
117121
122+ async #maybeHighlight( element : puppeteer . ElementHandle ) {
123+ if ( ! TestConfig . debug ) {
124+ return ;
125+ }
126+ if ( ! element ) {
127+ return ;
128+ }
129+ if ( this . #currentHighlightedElement) {
130+ await this . #currentHighlightedElement. reset ( ) ;
131+ }
132+ this . #currentHighlightedElement = new HighlightedElement ( element ) ;
133+ await this . #currentHighlightedElement. highlight ( ) ;
134+ }
135+
118136 async performActionOnSelector ( selector : string , options : { root ?: puppeteer . ElementHandle } , action : Action ) :
119137 Promise < puppeteer . ElementHandle > {
120138 // TODO(crbug.com/1410168): we should refactor waitFor to be compatible with
@@ -296,3 +314,24 @@ export async function setupDevToolsPage(context: puppeteer.BrowserContext, setti
296314 await devToolsPage . setDockingSide ( settings . dockingMode ) ;
297315 return devToolsPage ;
298316}
317+
318+ class HighlightedElement {
319+ constructor ( readonly element : puppeteer . ElementHandle ) {
320+ }
321+
322+ async reset ( ) {
323+ await this . element . evaluate ( el => {
324+ if ( el instanceof HTMLElement ) {
325+ el . style . outline = '' ;
326+ }
327+ } ) ;
328+ }
329+
330+ async highlight ( ) {
331+ await this . element . evaluate ( el => {
332+ if ( el instanceof HTMLElement ) {
333+ el . style . outline = '2px solid red' ;
334+ }
335+ } ) ;
336+ }
337+ }
0 commit comments