@@ -110,6 +110,8 @@ func mapResponse(rt *goja.Runtime, r api.Response) mapping {
110
110
}
111
111
112
112
// mapElementHandle to the JS module.
113
+ //
114
+ //nolint:funlen
113
115
func mapElementHandle (rt * goja.Runtime , eh api.ElementHandle ) mapping {
114
116
maps := mapping {
115
117
"asElement" : func () * goja.Object {
@@ -168,6 +170,22 @@ func mapElementHandle(rt *goja.Runtime, eh api.ElementHandle) mapping {
168
170
return rt .ToValue (ehm ).ToObject (rt )
169
171
},
170
172
}
173
+ maps ["$" ] = func (selector string ) * goja.Object {
174
+ eh := eh .Query (selector )
175
+ ehm := mapElementHandle (rt , eh )
176
+ return rt .ToValue (ehm ).ToObject (rt )
177
+ }
178
+ maps ["$$" ] = func (selector string ) * goja.Object {
179
+ var (
180
+ mehs []mapping
181
+ ehs = eh .QueryAll (selector )
182
+ )
183
+ for _ , eh := range ehs {
184
+ ehm := mapElementHandle (rt , eh )
185
+ mehs = append (mehs , ehm )
186
+ }
187
+ return rt .ToValue (mehs ).ToObject (rt )
188
+ }
171
189
172
190
return maps
173
191
}
@@ -247,6 +265,22 @@ func mapFrame(rt *goja.Runtime, f api.Frame) mapping {
247
265
},
248
266
"waitForTimeout" : f .WaitForTimeout ,
249
267
}
268
+ maps ["$" ] = func (selector string ) * goja.Object {
269
+ eh := f .Query (selector )
270
+ ehm := mapElementHandle (rt , eh )
271
+ return rt .ToValue (ehm ).ToObject (rt )
272
+ }
273
+ maps ["$$" ] = func (selector string ) * goja.Object {
274
+ var (
275
+ mehs []mapping
276
+ ehs = f .QueryAll (selector )
277
+ )
278
+ for _ , eh := range ehs {
279
+ ehm := mapElementHandle (rt , eh )
280
+ mehs = append (mehs , ehm )
281
+ }
282
+ return rt .ToValue (mehs ).ToObject (rt )
283
+ }
250
284
251
285
return maps
252
286
}
@@ -343,6 +377,22 @@ func mapPage(rt *goja.Runtime, p api.Page) mapping {
343
377
"waitForTimeout" : p .WaitForTimeout ,
344
378
"workers" : p .Workers ,
345
379
}
380
+ maps ["$" ] = func (selector string ) * goja.Object {
381
+ eh := p .Query (selector )
382
+ ehm := mapElementHandle (rt , eh )
383
+ return rt .ToValue (ehm ).ToObject (rt )
384
+ }
385
+ maps ["$$" ] = func (selector string ) * goja.Object {
386
+ var (
387
+ mehs []mapping
388
+ ehs = p .QueryAll (selector )
389
+ )
390
+ for _ , eh := range ehs {
391
+ ehm := mapElementHandle (rt , eh )
392
+ mehs = append (mehs , ehm )
393
+ }
394
+ return rt .ToValue (mehs ).ToObject (rt )
395
+ }
346
396
347
397
return maps
348
398
}
0 commit comments