@@ -100,45 +100,47 @@ func NewPageScreenshotOptions() *PageScreenshotOptions {
100
100
}
101
101
102
102
// Parse parses the page screenshot options.
103
- func (o * PageScreenshotOptions ) Parse (ctx context.Context , opts sobek.Value ) error {
103
+ func (o * PageScreenshotOptions ) Parse (ctx context.Context , opts sobek.Value ) error { //nolint:cyclop
104
+ if ! sobekValueExists (opts ) {
105
+ return nil
106
+ }
107
+
104
108
rt := k6ext .Runtime (ctx )
105
- if opts != nil && ! sobek .IsUndefined (opts ) && ! sobek .IsNull (opts ) {
106
- formatSpecified := false
107
- opts := opts .ToObject (rt )
108
- for _ , k := range opts .Keys () {
109
- switch k {
110
- case "clip" :
111
- var c map [string ]float64
112
- if rt .ExportTo (opts .Get (k ), & c ) != nil {
113
- o .Clip = & page.Viewport {
114
- X : c ["x" ],
115
- Y : c ["y" ],
116
- Width : c ["width" ],
117
- Height : c ["height" ],
118
- Scale : 1 ,
119
- }
120
- }
121
- case "fullPage" :
122
- o .FullPage = opts .Get (k ).ToBoolean ()
123
- case "omitBackground" :
124
- o .OmitBackground = opts .Get (k ).ToBoolean ()
125
- case "path" :
126
- o .Path = opts .Get (k ).String ()
127
- case "quality" :
128
- o .Quality = opts .Get (k ).ToInteger ()
129
- case "type" :
130
- if f , ok := imageFormatToID [opts .Get (k ).String ()]; ok {
131
- o .Format = f
132
- formatSpecified = true
109
+ formatSpecified := false
110
+ obj := opts .ToObject (rt )
111
+ for _ , k := range obj .Keys () {
112
+ switch k {
113
+ case "clip" :
114
+ var c map [string ]float64
115
+ if rt .ExportTo (obj .Get (k ), & c ) != nil {
116
+ o .Clip = & page.Viewport {
117
+ X : c ["x" ],
118
+ Y : c ["y" ],
119
+ Width : c ["width" ],
120
+ Height : c ["height" ],
121
+ Scale : 1 ,
133
122
}
134
123
}
124
+ case "fullPage" :
125
+ o .FullPage = obj .Get (k ).ToBoolean ()
126
+ case "omitBackground" :
127
+ o .OmitBackground = obj .Get (k ).ToBoolean ()
128
+ case "path" :
129
+ o .Path = obj .Get (k ).String ()
130
+ case "quality" :
131
+ o .Quality = obj .Get (k ).ToInteger ()
132
+ case "type" :
133
+ if f , ok := imageFormatToID [obj .Get (k ).String ()]; ok {
134
+ o .Format = f
135
+ formatSpecified = true
136
+ }
135
137
}
138
+ }
136
139
137
- // Infer file format by path if format not explicitly specified (default is PNG)
138
- if o .Path != "" && ! formatSpecified {
139
- if strings .HasSuffix (o .Path , ".jpg" ) || strings .HasSuffix (o .Path , ".jpeg" ) {
140
- o .Format = ImageFormatJPEG
141
- }
140
+ // Infer file format by path if format not explicitly specified (default is PNG)
141
+ if o .Path != "" && ! formatSpecified {
142
+ if strings .HasSuffix (o .Path , ".jpg" ) || strings .HasSuffix (o .Path , ".jpeg" ) {
143
+ o .Format = ImageFormatJPEG
142
144
}
143
145
}
144
146
0 commit comments