{"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":"error","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/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L749-L785","documentation":"The count() path received a non-float64 result from the injected counting script (expected a number returned by value from the evaluation). This is an internal Go/JS contract violation — legitimate DOM counts always arrive as float64 via returnByValue.","triggerScenarios":"el.count() or frame-chained counts where evalWithScript returns a string/object/undefined because the injected script was interfered with or the evaluation protocol broke; distinct from selector errors, which fail earlier in NewSelector/waitForSelector.","commonSituations":"Adversarial pages patching globals used by injected scripts; k6 version mismatch between the generated JS helpers and the binary; not seen in ordinary flows.","solutions":["Upgrade or pin a consistent k6 version","Isolate against a static page to rule out app interference","Work around with page.evaluate(() => document.querySelectorAll(sel).length)","File a k6 issue with the minimal case"],"exampleFix":"// workaround\nconst n = await page.evaluate(() => document.querySelectorAll('.item').length);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const n = await page.locator('.item').count();\n} catch (e) {\n  if (/unexpected value/.test(String(e))) {\n    const n = await page.evaluate(() => document.querySelectorAll('.item').length);\n  } else throw e;\n}","preventionTips":["Pin k6 versions; report internal invariant errors upstream with a reproducer"],"tags":["browser","count","internal","js-evaluation","invariant"],"backgroundTag":"browser-unexpected-eval-result","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}