From 31d065ff1e53d65981916152084814e21ccd108d Mon Sep 17 00:00:00 2001 From: ankur22 Date: Tue, 21 May 2024 16:07:35 +0100 Subject: [PATCH 1/6] Update request.allHeaders to async --- browser/request_mapping.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/browser/request_mapping.go b/browser/request_mapping.go index 7932c4646..963d17c23 100644 --- a/browser/request_mapping.go +++ b/browser/request_mapping.go @@ -4,13 +4,18 @@ import ( "github.com/dop251/goja" "github.com/grafana/xk6-browser/common" + "github.com/grafana/xk6-browser/k6ext" ) // mapRequest to the JS module. func mapRequest(vu moduleVU, r *common.Request) mapping { rt := vu.Runtime() maps := mapping{ - "allHeaders": r.AllHeaders, + "allHeaders": func() *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return r.AllHeaders(), nil + }) + }, "frame": func() *goja.Object { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) From a90855fdde33a2bd44606e8abe10d866df3635a7 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 24 May 2024 15:00:01 +0100 Subject: [PATCH 2/6] Update request.headValue to async --- browser/request_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/request_mapping.go b/browser/request_mapping.go index 963d17c23..c1e166e84 100644 --- a/browser/request_mapping.go +++ b/browser/request_mapping.go @@ -20,7 +20,11 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) }, - "headerValue": r.HeaderValue, + "headerValue": func(name string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return r.HeaderValue(name), nil + }) + }, "headers": r.Headers, "headersArray": r.HeadersArray, "isNavigationRequest": r.IsNavigationRequest, From 9b5abcd41e01c829cd8d2387d6535326f09d7f65 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 24 May 2024 15:05:46 +0100 Subject: [PATCH 3/6] Update request.headers to async --- browser/request_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/request_mapping.go b/browser/request_mapping.go index c1e166e84..64ffa7aee 100644 --- a/browser/request_mapping.go +++ b/browser/request_mapping.go @@ -25,7 +25,11 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { return r.HeaderValue(name), nil }) }, - "headers": r.Headers, + "headers": func(name string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return r.Headers(), nil + }) + }, "headersArray": r.HeadersArray, "isNavigationRequest": r.IsNavigationRequest, "method": r.Method, From aa9ba9fb7481be05f0532a18fad7d20b77812c5c Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 24 May 2024 15:08:55 +0100 Subject: [PATCH 4/6] Update request.headersArray to async --- browser/request_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/request_mapping.go b/browser/request_mapping.go index 64ffa7aee..a69b3bb94 100644 --- a/browser/request_mapping.go +++ b/browser/request_mapping.go @@ -30,7 +30,11 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { return r.Headers(), nil }) }, - "headersArray": r.HeadersArray, + "headersArray": func(name string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return r.HeadersArray(), nil + }) + }, "isNavigationRequest": r.IsNavigationRequest, "method": r.Method, "postData": r.PostData, From c88c2b053f6f621b6d50b2fc0d892038c2fdbe0f Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 24 May 2024 15:39:00 +0100 Subject: [PATCH 5/6] Update request.response to async --- browser/request_mapping.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/browser/request_mapping.go b/browser/request_mapping.go index a69b3bb94..d0ba3ec59 100644 --- a/browser/request_mapping.go +++ b/browser/request_mapping.go @@ -40,9 +40,14 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { "postData": r.PostData, "postDataBuffer": r.PostDataBuffer, "resourceType": r.ResourceType, - "response": func() *goja.Object { - mr := mapResponse(vu, r.Response()) - return rt.ToValue(mr).ToObject(rt) + "response": func(name string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + resp := r.Response() + if resp == nil { + return nil, nil + } + return mapResponse(vu, resp), nil + }) }, "size": r.Size, "timing": r.Timing, From 4c8a753876595db36784bd10f430fd1dbcf64da8 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 24 May 2024 15:44:33 +0100 Subject: [PATCH 6/6] Update request.size to async --- browser/request_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/request_mapping.go b/browser/request_mapping.go index d0ba3ec59..d7c94cc8a 100644 --- a/browser/request_mapping.go +++ b/browser/request_mapping.go @@ -49,7 +49,11 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { return mapResponse(vu, resp), nil }) }, - "size": r.Size, + "size": func(name string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return r.Size(), nil + }) + }, "timing": r.Timing, "url": r.URL, }