{"record":{"id":"1253d74d3fe62b7d","repo":"grafana/k6","slug":"value-v-out-of-range-for-int32-type","errorCode":null,"errorMessage":"value %v out of range for int32 type","messagePattern":"value (.+?) out of range for int32 type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":763,"sourceCode":"\t\t\t(node, injected, selector) => {\n\t\t\t\treturn injected.count(selector, node);\n\t\t\t}\n\t\t`\n\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","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L745-L781","documentation":"In ElementHandle's count() path, the injected script returned a numeric element count that falls outside the int32 range before being cast to int. Mathematically this cannot happen for a real DOM query result, so hitting it implies a corrupted evaluation result rather than an actual page with billions of elements.","triggerScenarios":"el.count() / internal count queries (including the frame-chained count path above it) where the JS evaluation returns Infinity, NaN-like large values, or garbage due to page tampering or a broken eval; the float64 range check at element_handle.go:762 rejects it.","commonSituations":"Practically never in real usage; if reported it accompanies a broken evaluation environment (page overriding the injected helpers) or an internal k6 bug.","solutions":["Re-run the count on a plain page to check for evaluation corruption","Upgrade k6 in case of an internal counting regression","Replace el.count() with an evaluate-based count as a workaround","Report to k6 with the reproducer if persistent"],"exampleFix":"// workaround\n// before\nconst n = await page.locator('.item').count();\n\n// after\nconst n = await page.evaluate(() => document.querySelectorAll('.item').length);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const n = await page.locator('.item').count();\n} catch (e) {\n  if (/out of range for int32/.test(String(e))) {\n    const n = await page.evaluate(() => document.querySelectorAll('.item').length);\n  } else throw e;\n}","preventionTips":["Treat this error as a signal of evaluation corruption; test on a clean page","Keep k6 version consistent"],"tags":["browser","count","range-check","internal"],"backgroundTag":"value-out-of-range","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"}