@@ -10,7 +10,7 @@ import type { WebDriverCommands } from '@wdio/protocols'
1010import { SessionCapturer } from './session.js'
1111import { TestReporter } from './reporter.js'
1212import { DevToolsAppLauncher } from './launcher.js'
13- import { getBrowserObject } from './utils.ts'
13+ import { getBrowserObject , isUserCommand } from './utils.ts'
1414import { parse } from 'stack-trace'
1515import { type TraceLog , TraceType } from './types.ts'
1616
@@ -156,25 +156,20 @@ export default class DevToolsHookService implements Services.ServiceInstance {
156156 * Smart stack filtering to detect top-level user commands
157157 */
158158 const stack = parse ( new Error ( '' ) )
159- const source = stack . find ( ( frame ) =>
160- Boolean ( frame . getFileName ( ) ) &&
161- ! frame . getFileName ( ) ?. includes ( 'node_modules' )
162- )
163159
164- // If the command is a selector command, we don't want to capture it
165- // as it is not a top-level user command.
166- const isSelectorCommand = command . startsWith ( '$' ) || command . includes ( 'LocateNodes' )
167-
168- if ( source && this . #commandStack. length === 0 && ! isSelectorCommand ) {
160+ if ( isUserCommand ( command , stack ) && this . #commandStack. length === 0 ) {
161+ const topFrame = stack . find ( f =>
162+ f . getFileName ( ) && ! f . getFileName ( ) ! . includes ( 'node_modules' )
163+ )
169164 const cmdSig = JSON . stringify ( {
170- command,
171- args,
172- src : source . getFileName ( ) + ':' + source . getLineNumber ( )
173- } ) ;
165+ command,
166+ args,
167+ src : topFrame ? .getFileName ( ) + ':' + topFrame ? .getLineNumber ( )
168+ } )
174169
175170 if ( this . #lastCommandSig !== cmdSig ) {
176- this . #commandStack. push ( command ) ;
177- this . #lastCommandSig = cmdSig ;
171+ this . #commandStack. push ( command )
172+ this . #lastCommandSig = cmdSig
178173 }
179174 }
180175 }
0 commit comments