Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit d3c68c8

Browse files
committed
Map response to goja
1 parent 2ed9de5 commit d3c68c8

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

browser/mapping.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ func mapBrowserToGoja(vu k6modules.VU) *goja.Object {
4040
return obj
4141
}
4242

43+
// mapResponse to the JS module.
44+
func mapResponse(rt *goja.Runtime, r api.Response) mapping {
45+
maps := mapping{
46+
"allHeaders": r.AllHeaders,
47+
"body": r.Body,
48+
"finished": r.Finished,
49+
"frame": func() *goja.Object {
50+
mf := mapFrame(rt, r.Frame())
51+
return rt.ToValue(mf).ToObject(rt)
52+
},
53+
"headerValue": r.HeaderValue,
54+
"headerValues": r.HeaderValues,
55+
"headers": r.Headers,
56+
"headersArray": r.HeadersArray,
57+
"jSON": r.JSON,
58+
"ok": r.Ok,
59+
"request": r.Request,
60+
"securityDetails": r.SecurityDetails,
61+
"serverAddr": r.ServerAddr,
62+
"size": r.Size,
63+
"status": r.Status,
64+
"statusText": r.StatusText,
65+
"url": r.URL,
66+
}
67+
68+
return maps
69+
}
70+
4371
// mapElementHandle to the JS module.
4472
func mapElementHandle(rt *goja.Runtime, eh api.ElementHandle) mapping {
4573
maps := mapping{
@@ -238,11 +266,14 @@ func mapPage(rt *goja.Runtime, p api.Page) mapping {
238266
mf := mapFrame(rt, p.MainFrame())
239267
return rt.ToValue(mf).ToObject(rt)
240268
},
241-
"opener": p.Opener,
242-
"pause": p.Pause,
243-
"pdf": p.Pdf,
244-
"press": p.Press,
245-
"reload": p.Reload,
269+
"opener": p.Opener,
270+
"pause": p.Pause,
271+
"pdf": p.Pdf,
272+
"press": p.Press,
273+
"reload": func(opts goja.Value) *goja.Object {
274+
r := mapResponse(rt, p.Reload(opts))
275+
return rt.ToValue(r).ToObject(rt)
276+
},
246277
"route": p.Route,
247278
"screenshot": p.Screenshot,
248279
"selectOption": p.SelectOption,

0 commit comments

Comments
 (0)