{"record":{"id":"7794065461b2fe28","repo":"grafana/k6","slug":"height-must-be-a-number-got-s","errorCode":null,"errorMessage":"height must be a number, got %s","messagePattern":"height must be a number, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":1213,"sourceCode":"\tfor _, k := range obj.Keys() {\n\t\tv := obj.Get(k)\n\t\tif k6common.IsNullish(v) {\n\t\t\tcontinue\n\t\t}\n\t\tswitch k {\n\t\tcase \"width\":\n\t\t\tswitch v.ExportType().Kind() {\n\t\t\tcase reflect.Int64, reflect.Float64:\n\t\t\t\tsize.Width = v.ToFloat()\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"width must be a number, got %s\", v.ExportType().Kind())\n\t\t\t}\n\t\tcase \"height\":\n\t\t\tswitch v.ExportType().Kind() {\n\t\t\tcase reflect.Int64, reflect.Float64:\n\t\t\t\tsize.Height = v.ToFloat()\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"height must be a number, got %s\", v.ExportType().Kind())\n\t\t\t}\n\t\t}\n\t}\n\n\treturn size, nil\n}\n\n// parsePageEmulateMediaOptions parses the page emulate media options from a Sobek value.\n//\n//nolint:unparam\nfunc parsePageEmulateMediaOptions(\n\trt *sobek.Runtime, opts sobek.Value, defaults *common.PageEmulateMediaOptions,\n) (*common.PageEmulateMediaOptions, error) {\n\tif k6common.IsNullish(opts) {\n\t\treturn defaults, nil\n\t}\n\n\tobj := opts.ToObject(rt)","sourceCodeStart":1195,"sourceCodeEnd":1231,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/page_mapping.go#L1195-L1231","documentation":"Thrown by parseSize when the 'height' key of page.setViewportSize(size) is present but its value's runtime kind is neither Int64 nor Float64. Like width, only real numbers are accepted; strings such as '720' or '720px', booleans, and objects are rejected with the offending reflect.Kind printed.","triggerScenarios":"page.setViewportSize({ width: 1280, height: '720' }); height sourced from JSON config where it was serialized as a string; height left as an empty string after env var defaulting; height passed as an array or object.","commonSituations":"Mixed-type config objects (one dimension numeric, the other string); environment-variable-driven responsive testing; configs authored in YAML/JSON where quotes were added around the number.","solutions":["Coerce both dimensions with Number() before calling setViewportSize.","Validate the parsed config once at script startup and fail fast with a clear message.","Use numeric literals for static viewport sizes.","Sanitize external config: strip quotes/units and check Number.isFinite."],"exampleFix":"// before\nawait page.setViewportSize({ width: cfg.width, height: cfg.height }); // cfg.height === \"720\"\n\n// after\nawait page.setViewportSize({ width: Number(cfg.width), height: Number(cfg.height) });","handlingStrategy":"type-guard","validationCode":"const h = Number(size.height);\nif (!Number.isFinite(h)) throw new TypeError(`height must be a number, got ${typeof size.height}`);\nawait page.setViewportSize({ width: Number(size.width), height: h });","typeGuard":"const isPlainNumber = (v) => typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":null,"preventionTips":["Treat all YAML/JSON/env-sourced dimensions as strings until proven otherwise; convert with Number().","Strip units/quotes during config sanitization before the browser call."],"tags":["k6","browser","viewport","type-error","argument-validation"],"backgroundTag":"argument-type-mismatch","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}