@@ -100,7 +100,7 @@ export class FrameManager {
100
100
}
101
101
}
102
102
103
- async waitForNavigationsCreatedBy < T > ( action : ( ) => Promise < T > , options ?: types . ActionWaitOptionsNoWaitFor ) : Promise < T > {
103
+ async waitForNavigationsCreatedBy < T > ( action : ( ) => Promise < T > , options ?: types . NavigatingActionWaitOptions ) : Promise < T > {
104
104
if ( options && options . waitUntil === 'nowait' )
105
105
return action ( ) ;
106
106
const barrier = new PendingNavigationBarrier ( options ) ;
@@ -583,10 +583,20 @@ export class Frame {
583
583
async waitForSelector ( selector : string , options ?: types . WaitForElementOptions ) : Promise < dom . ElementHandle < Element > | null > {
584
584
if ( options && ( options as any ) . visibility )
585
585
throw new Error ( 'options.visibility is not supported, did you mean options.waitFor?' ) ;
586
- const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
586
+ const { timeout = this . _page . _timeoutSettings . timeout ( ) , waitFor = 'attached' } = ( options || { } ) ;
587
+ if ( ! [ 'attached' , 'detached' , 'visible' , 'hidden' ] . includes ( waitFor ) )
588
+ throw new Error ( `Unsupported waitFor option "${ waitFor } "` ) ;
589
+
590
+ const task = dom . waitForSelectorTask ( selector , waitFor , timeout ) ;
591
+ const result = await this . _scheduleRerunnableTask ( task , 'utility' , timeout , `selector "${ selectorToString ( selector , waitFor ) } "` ) ;
592
+ if ( ! result . asElement ( ) ) {
593
+ result . dispose ( ) ;
594
+ return null ;
595
+ }
596
+ const handle = result . asElement ( ) as dom . ElementHandle < Element > ;
587
597
const mainContext = await this . _mainContext ( ) ;
588
598
if ( handle && handle . _context !== mainContext ) {
589
- const adopted = this . _page . _delegate . adoptElementHandle ( handle , mainContext ) ;
599
+ const adopted = await this . _page . _delegate . adoptElementHandle ( handle , mainContext ) ;
590
600
handle . dispose ( ) ;
591
601
return adopted ;
592
602
}
@@ -801,69 +811,69 @@ export class Frame {
801
811
return result ! ;
802
812
}
803
813
804
- async click ( selector : string , options ?: dom . ClickOptions & types . ActionWaitOptions ) {
805
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
814
+ async click ( selector : string , options ?: dom . ClickOptions & types . PointerActionWaitOptions & types . NavigatingActionWaitOptions ) {
815
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
806
816
await handle . click ( options ) ;
807
817
handle . dispose ( ) ;
808
818
}
809
819
810
- async dblclick ( selector : string , options ?: dom . MultiClickOptions & types . ActionWaitOptions ) {
811
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
820
+ async dblclick ( selector : string , options ?: dom . MultiClickOptions & types . PointerActionWaitOptions & types . NavigatingActionWaitOptions ) {
821
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
812
822
await handle . dblclick ( options ) ;
813
823
handle . dispose ( ) ;
814
824
}
815
825
816
- async tripleclick ( selector : string , options ?: dom . MultiClickOptions & types . ActionWaitOptions ) {
817
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
826
+ async tripleclick ( selector : string , options ?: dom . MultiClickOptions & types . PointerActionWaitOptions & types . NavigatingActionWaitOptions ) {
827
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
818
828
await handle . tripleclick ( options ) ;
819
829
handle . dispose ( ) ;
820
830
}
821
831
822
- async fill ( selector : string , value : string , options ?: types . ActionWaitOptions ) {
823
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
832
+ async fill ( selector : string , value : string , options ?: types . NavigatingActionWaitOptions ) {
833
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
824
834
await handle . fill ( value , options ) ;
825
835
handle . dispose ( ) ;
826
836
}
827
837
828
- async focus ( selector : string , options ?: types . ActionWaitOptionsNoNavigation ) {
829
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
838
+ async focus ( selector : string , options ?: types . TimeoutOptions ) {
839
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
830
840
await handle . focus ( ) ;
831
841
handle . dispose ( ) ;
832
842
}
833
843
834
- async hover ( selector : string , options ?: dom . PointerActionOptions & types . ActionWaitOptionsNoNavigation ) {
835
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
844
+ async hover ( selector : string , options ?: dom . PointerActionOptions & types . PointerActionWaitOptions ) {
845
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
836
846
await handle . hover ( options ) ;
837
847
handle . dispose ( ) ;
838
848
}
839
849
840
- async select ( selector : string , values : string | dom . ElementHandle | types . SelectOption | string [ ] | dom . ElementHandle [ ] | types . SelectOption [ ] , options ?: types . ActionWaitOptions ) : Promise < string [ ] > {
841
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
850
+ async select ( selector : string , values : string | dom . ElementHandle | types . SelectOption | string [ ] | dom . ElementHandle [ ] | types . SelectOption [ ] , options ?: types . NavigatingActionWaitOptions ) : Promise < string [ ] > {
851
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
842
852
const result = await handle . select ( values , options ) ;
843
853
handle . dispose ( ) ;
844
854
return result ;
845
855
}
846
856
847
- async type ( selector : string , text : string , options ?: { delay ?: number } & types . ActionWaitOptions ) {
848
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
857
+ async type ( selector : string , text : string , options ?: { delay ?: number } & types . NavigatingActionWaitOptions ) {
858
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
849
859
await handle . type ( text , options ) ;
850
860
handle . dispose ( ) ;
851
861
}
852
862
853
- async press ( selector : string , key : string , options ?: { delay ?: number , text ?: string } & types . ActionWaitOptions ) {
854
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
863
+ async press ( selector : string , key : string , options ?: { delay ?: number , text ?: string } & types . NavigatingActionWaitOptions ) {
864
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
855
865
await handle . press ( key , options ) ;
856
866
handle . dispose ( ) ;
857
867
}
858
868
859
- async check ( selector : string , options ?: types . ActionWaitOptions ) {
860
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
869
+ async check ( selector : string , options ?: types . PointerActionWaitOptions & types . NavigatingActionWaitOptions ) {
870
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
861
871
await handle . check ( options ) ;
862
872
handle . dispose ( ) ;
863
873
}
864
874
865
- async uncheck ( selector : string , options ?: types . ActionWaitOptions ) {
866
- const handle = await this . _optionallyWaitForSelectorInUtilityContext ( selector , options ) ;
875
+ async uncheck ( selector : string , options ?: types . PointerActionWaitOptions & types . NavigatingActionWaitOptions ) {
876
+ const handle = await this . _waitForSelectorInUtilityContext ( selector , options ) ;
867
877
await handle . uncheck ( options ) ;
868
878
handle . dispose ( ) ;
869
879
}
@@ -878,35 +888,10 @@ export class Frame {
878
888
return Promise . reject ( new Error ( 'Unsupported target type: ' + ( typeof selectorOrFunctionOrTimeout ) ) ) ;
879
889
}
880
890
881
- private async _optionallyWaitForSelectorInUtilityContext ( selector : string , options : types . ActionWaitOptions | undefined ) : Promise < dom . ElementHandle < Element > > {
882
- const { timeout = this . _page . _timeoutSettings . timeout ( ) , waitFor = true } = ( options || { } ) ;
883
- if ( ! helper . isBoolean ( waitFor ) )
884
- throw new Error ( 'waitFor option should be a boolean, got "' + ( typeof waitFor ) + '"' ) ;
885
- let handle : dom . ElementHandle < Element > ;
886
- if ( waitFor ) {
887
- const maybeHandle = await this . _waitForSelectorInUtilityContext ( selector , { timeout, waitFor : 'attached' } ) ;
888
- if ( ! maybeHandle )
889
- throw new Error ( 'No node found for selector: ' + selectorToString ( selector , 'attached' ) ) ;
890
- handle = maybeHandle ;
891
- } else {
892
- const context = await this . _context ( 'utility' ) ;
893
- const maybeHandle = await context . _$ ( selector ) ;
894
- assert ( maybeHandle , 'No node found for selector: ' + selector ) ;
895
- handle = maybeHandle ;
896
- }
897
- return handle ;
898
- }
899
-
900
- private async _waitForSelectorInUtilityContext ( selector : string , options ?: types . WaitForElementOptions ) : Promise < dom . ElementHandle < Element > | null > {
891
+ private async _waitForSelectorInUtilityContext ( selector : string , options ?: types . WaitForElementOptions ) : Promise < dom . ElementHandle < Element > > {
901
892
const { timeout = this . _page . _timeoutSettings . timeout ( ) , waitFor = 'attached' } = ( options || { } ) ;
902
- if ( ! [ 'attached' , 'detached' , 'visible' , 'hidden' ] . includes ( waitFor ) )
903
- throw new Error ( `Unsupported waitFor option "${ waitFor } "` ) ;
904
893
const task = dom . waitForSelectorTask ( selector , waitFor , timeout ) ;
905
894
const result = await this . _scheduleRerunnableTask ( task , 'utility' , timeout , `selector "${ selectorToString ( selector , waitFor ) } "` ) ;
906
- if ( ! result . asElement ( ) ) {
907
- result . dispose ( ) ;
908
- return null ;
909
- }
910
895
return result . asElement ( ) as dom . ElementHandle < Element > ;
911
896
}
912
897
@@ -1099,12 +1084,12 @@ function selectorToString(selector: string, waitFor: 'attached' | 'detached' | '
1099
1084
1100
1085
class PendingNavigationBarrier {
1101
1086
private _frameIds = new Map < string , number > ( ) ;
1102
- private _options : types . ActionWaitOptionsNoWaitFor | undefined ;
1087
+ private _options : types . NavigatingActionWaitOptions | undefined ;
1103
1088
private _protectCount = 0 ;
1104
1089
private _promise : Promise < void > ;
1105
1090
private _promiseCallback = ( ) => { } ;
1106
1091
1107
- constructor ( options : types . ActionWaitOptionsNoWaitFor | undefined ) {
1092
+ constructor ( options : types . NavigatingActionWaitOptions | undefined ) {
1108
1093
this . _options = options ;
1109
1094
this . _promise = new Promise ( f => this . _promiseCallback = f ) ;
1110
1095
this . retain ( ) ;
0 commit comments