File tree 7 files changed +54
-20
lines changed
packages/playwright-core/src/server
utils/generate_types/test 7 files changed +54
-20
lines changed Original file line number Diff line number Diff line change 58
58
"@babel/preset-react" : " ^7.18.6" ,
59
59
"@types/codemirror" : " ^5.60.5" ,
60
60
"@types/formidable" : " ^2.0.4" ,
61
- "@types/node" : " =14.18.24 " ,
61
+ "@types/node" : " =14.18.34 " ,
62
62
"@types/react" : " ^18.0.12" ,
63
63
"@types/react-dom" : " ^18.0.5" ,
64
64
"@types/resize-observer-browser" : " ^0.1.7" ,
94
94
"rimraf" : " ^3.0.2" ,
95
95
"socksv5" : " 0.0.6" ,
96
96
"ssim.js" : " ^3.5.0" ,
97
- "typescript" : " ^4.7 .3" ,
97
+ "typescript" : " ^4.9 .3" ,
98
98
"vite" : " ^3.2.1" ,
99
99
"ws" : " ^8.5.0" ,
100
100
"xml2js" : " ^0.4.23" ,
Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
120
120
}
121
121
122
122
export class ElementHandle < T extends Node = Node > extends js . JSHandle < T > {
123
+ __elementhandle : T = true as any ;
123
124
declare readonly _context : FrameExecutionContext ;
124
125
readonly _page : Page ;
125
126
declare readonly _objectId : string ;
Original file line number Diff line number Diff line change @@ -27,10 +27,16 @@ export type RemoteObject = {
27
27
value ?: any
28
28
} ;
29
29
30
- type NoHandles < Arg > = Arg extends JSHandle ? never : ( Arg extends object ? { [ Key in keyof Arg ] : NoHandles < Arg [ Key ] > } : Arg ) ;
30
+ interface TaggedAsJSHandle < T > {
31
+ __jshandle : T ;
32
+ }
33
+ interface TaggedAsElementHandle < T > {
34
+ __elementhandle : T ;
35
+ }
36
+ type NoHandles < Arg > = Arg extends TaggedAsJSHandle < any > ? never : ( Arg extends object ? { [ Key in keyof Arg ] : NoHandles < Arg [ Key ] > } : Arg ) ;
31
37
type Unboxed < Arg > =
32
- Arg extends dom . ElementHandle < infer T > ? T :
33
- Arg extends JSHandle < infer T > ? T :
38
+ Arg extends TaggedAsElementHandle < infer T > ? T :
39
+ Arg extends TaggedAsJSHandle < infer T > ? T :
34
40
Arg extends NoHandles < Arg > ? Arg :
35
41
Arg extends [ infer A0 ] ? [ Unboxed < A0 > ] :
36
42
Arg extends [ infer A0 , infer A1 ] ? [ Unboxed < A0 > , Unboxed < A1 > ] :
@@ -129,6 +135,7 @@ export class ExecutionContext extends SdkObject {
129
135
}
130
136
131
137
export class JSHandle < T = any > extends SdkObject {
138
+ __jshandle : T = true as any ;
132
139
readonly _context : ExecutionContext ;
133
140
_disposed = false ;
134
141
readonly _objectId : ObjectId | undefined ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export async function queryObjectCount(type: Function): Promise<number> {
29
29
prototypeObjectId : constructorFunction . objectId
30
30
} , ( _ , result ) => f ( result ) ) ) as any ;
31
31
32
- const { result : { value } } = await new Promise ( f => session . post ( 'Runtime.callFunctionOn' , {
32
+ const { result : { value } } = await new Promise < any > ( f => session . post ( 'Runtime.callFunctionOn' , {
33
33
functionDeclaration : 'function (arr) { return this.length; }' ,
34
34
objectId : instanceArray . objectId ,
35
35
arguments : [ { objectId : instanceArray . objectId } ] ,
Original file line number Diff line number Diff line change @@ -657,8 +657,7 @@ async function captureLastKeydown(page) {
657
657
lastEvent . key = e . key ;
658
658
lastEvent . code = e . code ;
659
659
lastEvent . metaKey = e . metaKey ;
660
- // keyIdentifier only exists in WebKit, and isn't in TypeScript's lib.
661
- lastEvent . keyIdentifier = 'keyIdentifier' in e && e [ 'keyIdentifier' ] ;
660
+ lastEvent . keyIdentifier = 'keyIdentifier' in e && typeof e [ 'keyIdentifier' ] === 'string' && e [ 'keyIdentifier' ] ;
662
661
} , true ) ;
663
662
return lastEvent ;
664
663
} ) ;
Original file line number Diff line number Diff line change @@ -567,6 +567,23 @@ playwright.chromium.launch().then(async browser => {
567
567
const value = await handle . jsonValue ( ) ;
568
568
const assertion : AssertType < number , typeof value > = true ;
569
569
}
570
+ {
571
+ const handle = await page . evaluateHandle ( ( ) => document . body ) ;
572
+ const tuple = { s : '' , n : 23 , h : handle } ;
573
+ const value = await page . evaluate ( ( [ { s, n, h } ] ) => {
574
+ return parseInt ( s ) + n + parseInt ( h . nodeName ) ;
575
+ } , [ tuple ] ) ;
576
+ const assertion : AssertType < number , typeof value > = true ;
577
+ }
578
+ {
579
+ type T = ( { s : string } | playwright . ElementHandle ) [ ] ;
580
+ const handle = await page . evaluateHandle ( ( ) => document . body ) ;
581
+ const tuple : T = [ { s : '' } , handle ] ;
582
+ const value = await page . evaluate ( ( [ a , b ] ) => {
583
+ return ( a instanceof Node ? a . nodeName : a . s ) + ( b instanceof Node ? b . nodeName : b . s ) ;
584
+ } , tuple ) ;
585
+ const assertion : AssertType < string , typeof value > = true ;
586
+ }
570
587
571
588
{
572
589
const handle = await page . evaluateHandle ( ( ) => document . createElement ( 'body' ) ) ;
@@ -861,3 +878,4 @@ import {
861
878
Geolocation ,
862
879
HTTPCredentials ,
863
880
} from 'playwright' ;
881
+
You can’t perform that action at this time.
0 commit comments