grafana/k6 · error
unmarshaling to ReducedMotion
Error message
unmarshaling %q to ReducedMotion: %w
What it means
Failure while decoding the JSON value of a 'reducedMotion' browser-context option into the ReducedMotion enum. The input at fault is the raw JSON token: either it is not a JSON string at all, or the string is not one of the known values ('reduce', 'no-preference').
Solutions
- Pass reducedMotion as one of the strings 'reduce' or 'no-preference'
- Do not pass an enum as a number or object — the decoder expects a quoted string
- Validate script/CLI-provided options before constructing the browser context
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/page.go:117 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/277de817a1ab6def.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/page.go:119
var reducedMotionToID = map[string]ReducedMotion{
"reduce": ReducedMotionReduce,
"no-preference": ReducedMotionNoPreference,
}
// MarshalJSON marshals the enum as a quoted JSON string.
func (r ReducedMotion) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(reducedMotionToString[r])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
// UnmarshalJSON unmarshals a quoted JSON string to the enum value.
func (r *ReducedMotion) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return fmt.Errorf("unmarshaling %q to ReducedMotion: %w", b, err)
}
// Note that if the string cannot be found then it will be set to the zero value.
*r = reducedMotionToID[j]
return nil
}
// Screen represents a device screen.
type Screen struct {
Width int64 `js:"width"`
Height int64 `js:"height"`
}
// ColorScheme represents a browser color scheme.
type ColorScheme string
// Valid color schemes.
const (
ColorSchemeLight ColorScheme = "light"View on GitHub (pinned to 3fcf5388d7)