@@ -435,36 +435,39 @@ func NewElementHandleScreenshotOptions(defaultTimeout time.Duration) *ElementHan
435
435
}
436
436
437
437
// Parse parses the ElementHandleScreenshotOptions from the given opts.
438
- func (o * ElementHandleScreenshotOptions ) Parse (ctx context.Context , opts sobek.Value ) error {
438
+ func (o * ElementHandleScreenshotOptions ) Parse (ctx context.Context , opts sobek.Value ) error { //nolint:cyclop
439
+ if ! sobekValueExists (opts ) {
440
+ return nil
441
+ }
442
+
439
443
rt := k6ext .Runtime (ctx )
440
- if opts != nil && ! sobek .IsUndefined (opts ) && ! sobek .IsNull (opts ) {
441
- formatSpecified := false
442
- opts := opts .ToObject (rt )
443
- for _ , k := range opts .Keys () {
444
- switch k {
445
- case "omitBackground" :
446
- o .OmitBackground = opts .Get (k ).ToBoolean ()
447
- case "path" :
448
- o .Path = opts .Get (k ).String ()
449
- case "quality" :
450
- o .Quality = opts .Get (k ).ToInteger ()
451
- case "type" :
452
- if f , ok := imageFormatToID [opts .Get (k ).String ()]; ok {
453
- o .Format = f
454
- formatSpecified = true
455
- }
456
- case "timeout" :
457
- o .Timeout = time .Duration (opts .Get (k ).ToInteger ()) * time .Millisecond
444
+ formatSpecified := false
445
+ obj := opts .ToObject (rt )
446
+ for _ , k := range obj .Keys () {
447
+ switch k {
448
+ case "omitBackground" :
449
+ o .OmitBackground = obj .Get (k ).ToBoolean ()
450
+ case "path" :
451
+ o .Path = obj .Get (k ).String ()
452
+ case "quality" :
453
+ o .Quality = obj .Get (k ).ToInteger ()
454
+ case "type" :
455
+ if f , ok := imageFormatToID [obj .Get (k ).String ()]; ok {
456
+ o .Format = f
457
+ formatSpecified = true
458
458
}
459
+ case "timeout" :
460
+ o .Timeout = time .Duration (obj .Get (k ).ToInteger ()) * time .Millisecond
459
461
}
462
+ }
460
463
461
- // Infer file format by path if format not explicitly specified (default is PNG)
462
- if o .Path != "" && ! formatSpecified {
463
- if strings .HasSuffix (o .Path , ".jpg" ) || strings .HasSuffix (o .Path , ".jpeg" ) {
464
- o .Format = ImageFormatJPEG
465
- }
464
+ // Infer file format by path if format not explicitly specified (default is PNG)
465
+ if o .Path != "" && ! formatSpecified {
466
+ if strings .HasSuffix (o .Path , ".jpg" ) || strings .HasSuffix (o .Path , ".jpeg" ) {
467
+ o .Format = ImageFormatJPEG
466
468
}
467
469
}
470
+
468
471
return nil
469
472
}
470
473
0 commit comments