@@ -24,7 +24,7 @@ import { isSessionClosedError } from './protocolError';
24
24
import * as rawInjectedScriptSource from '../generated/injectedScriptSource' ;
25
25
26
26
import type * as frames from './frames' ;
27
- import type { ElementState , HitTargetError , HitTargetInterceptionResult , InjectedScript , InjectedScriptOptions } from '@injected/injectedScript' ;
27
+ import type { ElementState , HitTargetInterceptionResult , InjectedScript , InjectedScriptOptions } from '@injected/injectedScript' ;
28
28
import type { CallMetadata } from './instrumentation' ;
29
29
import type { Page } from './page' ;
30
30
import type { Progress } from './progress' ;
@@ -39,7 +39,7 @@ export type InputFilesItems = {
39
39
} ;
40
40
41
41
type ActionName = 'click' | 'hover' | 'dblclick' | 'tap' | 'move and up' | 'move and down' ;
42
- type PerformActionResult = 'error:notvisible' | 'error:notconnected' | 'error:notinviewport' | 'error:optionsnotfound' | { missingState : ElementState } | HitTargetError | 'done' ;
42
+ type PerformActionResult = 'error:notvisible' | 'error:notconnected' | 'error:notinviewport' | 'error:optionsnotfound' | { missingState : ElementState } | { hitTargetDescription : string } | 'done' ;
43
43
44
44
export class NonRecoverableDOMError extends Error {
45
45
}
@@ -332,7 +332,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
332
332
} ;
333
333
}
334
334
335
- async _retryAction ( progress : Progress , actionName : string , action : ( ) => Promise < PerformActionResult > , options : { trial ?: boolean , force ?: boolean , skipActionPreChecks ?: boolean } ) : Promise < 'error:notconnected' | 'done' > {
335
+ async _retryAction ( progress : Progress , actionName : string , action : ( retry : number ) => Promise < PerformActionResult > , options : { trial ?: boolean , force ?: boolean , skipActionPreChecks ?: boolean } ) : Promise < 'error:notconnected' | 'done' > {
336
336
let retry = 0 ;
337
337
// We progressively wait longer between retries, up to 500ms.
338
338
const waitTime = [ 0 , 20 , 100 , 100 , 500 ] ;
@@ -352,7 +352,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
352
352
}
353
353
if ( ! options . skipActionPreChecks && ! options . force )
354
354
await this . _frame . _page . performActionPreChecks ( progress ) ;
355
- const result = await action ( ) ;
355
+ const result = await action ( retry ) ;
356
356
++ retry ;
357
357
if ( result === 'error:notvisible' ) {
358
358
if ( options . force )
@@ -387,25 +387,19 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
387
387
options : { waitAfter : boolean | 'disabled' } & types . PointerActionOptions & types . PointerActionWaitOptions ) : Promise < 'error:notconnected' | 'done' > {
388
388
// Note: do not perform locator handlers checkpoint to avoid moving the mouse in the middle of a drag operation.
389
389
const skipActionPreChecks = actionName === 'move and up' ;
390
- // By default, we scroll with protocol method to reveal the action point.
391
- // However, that might not work to scroll from under position:sticky and position:fixed elements
392
- // that overlay the target element. To fight this, we cycle through different
393
- // scroll alignments. This works in most scenarios.
394
- const scrollOptions : ( ScrollIntoViewOptions | undefined ) [ ] = [
395
- undefined ,
396
- { block : 'end' , inline : 'end' } ,
397
- { block : 'center' , inline : 'center' } ,
398
- { block : 'start' , inline : 'start' } ,
399
- ] ;
400
- let scrollOptionIndex = 0 ;
401
- return await this . _retryAction ( progress , actionName , async ( ) => {
402
- const forceScrollOptions = scrollOptions [ scrollOptionIndex % scrollOptions . length ] ;
403
- const result = await this . _performPointerAction ( progress , actionName , waitForEnabled , action , forceScrollOptions , options ) ;
404
- if ( typeof result === 'object' && 'hasPositionStickyOrFixed' in result && result . hasPositionStickyOrFixed )
405
- ++ scrollOptionIndex ;
406
- else
407
- scrollOptionIndex = 0 ;
408
- return result ;
390
+ return await this . _retryAction ( progress , actionName , async retry => {
391
+ // By default, we scroll with protocol method to reveal the action point.
392
+ // However, that might not work to scroll from under position:sticky elements
393
+ // that overlay the target element. To fight this, we cycle through different
394
+ // scroll alignments. This works in most scenarios.
395
+ const scrollOptions : ( ScrollIntoViewOptions | undefined ) [ ] = [
396
+ undefined ,
397
+ { block : 'end' , inline : 'end' } ,
398
+ { block : 'center' , inline : 'center' } ,
399
+ { block : 'start' , inline : 'start' } ,
400
+ ] ;
401
+ const forceScrollOptions = scrollOptions [ retry % scrollOptions . length ] ;
402
+ return await this . _performPointerAction ( progress , actionName , waitForEnabled , action , forceScrollOptions , options ) ;
409
403
} , { ...options , skipActionPreChecks } ) ;
410
404
}
411
405
@@ -488,7 +482,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
488
482
const error = handle . rawValue ( ) as string ;
489
483
if ( error === 'error:notconnected' )
490
484
return error ;
491
- return JSON . parse ( error ) as HitTargetError ; // It is safe to parse, because we evaluated in utility.
485
+ return { hitTargetDescription : error } ;
492
486
}
493
487
hitTargetInterceptionHandle = handle as any ;
494
488
progress . cleanupWhenAborted ( ( ) => {
@@ -917,7 +911,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
917
911
return this ;
918
912
}
919
913
920
- async _checkFrameIsHitTarget ( point : types . Point ) : Promise < { framePoint : types . Point | undefined } | 'error:notconnected' | HitTargetError > {
914
+ async _checkFrameIsHitTarget ( point : types . Point ) : Promise < { framePoint : types . Point | undefined } | 'error:notconnected' | { hitTargetDescription : string } > {
921
915
let frame = this . _frame ;
922
916
const data : { frame : frames . Frame , frameElement : ElementHandle < Element > | null , pointInFrame : types . Point } [ ] = [ ] ;
923
917
while ( frame . parentFrame ( ) ) {
0 commit comments