{"record":{"id":"92f542c827d6728b","repo":"grafana/k6","slug":"unexpected-value-v-of-type-t","errorCode":null,"errorMessage":"unexpected value %v of type %T","messagePattern":"unexpected value (.+?) of type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":767,"sourceCode":"\teopts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := h.evalWithScript(\n\t\tapiCtx,\n\t\teopts, fn, parsedSelector,\n\t)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tswitch r := result.(type) {\n\tcase float64:\n\t\tif r < float64(math.MinInt32) || r > float64(math.MaxInt32) {\n\t\t\treturn 0, fmt.Errorf(\"value %v out of range for int32 type\", r)\n\t\t}\n\t\treturn int(r), nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"unexpected value %v of type %T\", r, r)\n\t}\n}\n\n// findFrameNavigationIndex finds the index of the first internal:control=enter-frame directive\nfunc (h *ElementHandle) findFrameNavigationIndex(selector *Selector) int {\n\tfor i, part := range selector.Parts {\n\t\tif part.Name == \"internal:control\" && part.Body == \"enter-frame\" {\n\t\t\treturn i\n\t\t}\n\t}\n\treturn -1\n}\n\n// splitSelectorAtFrame splits a selector at the frame navigation boundary\nfunc (h *ElementHandle) splitSelectorAtFrame(selector *Selector, frameIndex int) (*Selector, *Selector) {\n\tbeforeFrame := &Selector{\n\t\tSelector: selector.Selector, // Keep original for reference\n\t\tParts:    selector.Parts[:frameIndex],","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L749-L785","documentation":"count() expects the evaluation to return a JS number (deserialized as float64). Any other type — string, nil, object — triggers this error; the injected count script broke its contract or the context died.","triggerScenarios":"handle.count(selector) when the eval returns undefined (execution context destroyed) or a non-numeric value from a mismatched injected script.","commonSituations":"Navigation racing the count; custom builds with stale injected script; rare on stock releases.","solutions":["Retry after the page settles","Upgrade to a matching k6 build","Report a minimal reproduction if it persists"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const n = await handle.count(sel);\n} catch (e) {\n  if (String(e).includes('unexpected value')) {\n    await handle.count(sel); // one retry with settled context\n  } else { throw e; }\n}","preventionTips":["Avoid counting during navigation","Upgrade k6 on recurrence"],"tags":["browser","count","injected-script","internal-invariant"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}