From 69cfffee945c3aabc09aa875a29d81868a747c28 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Tue, 12 Dec 2023 11:49:44 +0000 Subject: [PATCH] Add parse function for an array This allows the remote object to be parsed into an array if that is what it is instead of an object where the keys are index values. --- common/remote_object.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/common/remote_object.go b/common/remote_object.go index 6f8559f80..c63dd1e03 100644 --- a/common/remote_object.go +++ b/common/remote_object.go @@ -248,6 +248,25 @@ func parseConsoleRemoteObjectPreview(logger *log.Logger, op *cdpruntime.ObjectPr return string(bb) } +func parseConsoleRemoteArrayPreview(logger *log.Logger, op *cdpruntime.ObjectPreview) string { + arr := make([]any, 0) + if op.Overflow { + logger.Warnf("parseConsoleRemoteArrayPreview", "array is too large and will be parsed partially") + } + + for _, p := range op.Properties { + val := parseConsoleRemoteObjectValue(logger, p.Type, p.Subtype, p.Value, p.ValuePreview) + arr = append(arr, val) + } + + bb, err := json.Marshal(arr) + if err != nil { + logger.Errorf("parseConsoleRemoteArrayPreview", "failed to marshal array to string: %v", err) + } + + return string(bb) +} + //nolint:cyclop func parseConsoleRemoteObjectValue( logger *log.Logger,