{"record":{"id":"06e7ef780ba77672","repo":"grafana/k6","slug":"converting-result-v-of-type-t-to-border-w","errorCode":null,"errorMessage":"converting result (%v of type %t) to border: %w","messagePattern":"converting result \\((.+?) of type %t\\) to border: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":438,"sourceCode":"\nfunc (h *ElementHandle) offsetPosition(apiCtx context.Context, offset *Position) (*Position, error) {\n\tfn := `\n\t\t(node, injected) => {\n\t\t\treturn injected.getElementBorderWidth(node);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := h.evalWithScript(apiCtx, opts, fn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar border struct{ Top, Left float64 }\n\tif err := convert(result, &border); err != nil {\n\t\treturn nil, fmt.Errorf(\"converting result (%v of type %t) to border: %w\", result, result, err)\n\t}\n\n\tbox, err := h.BoundingBox()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"finding offset position: %w\", err)\n\t}\n\n\tif box == nil || (border.Left == 0 && border.Top == 0) {\n\t\treturn nil, ErrElementNotVisible\n\t}\n\n\t// Make point relative to the padding box to align with offsetX/offsetY.\n\treturn &Position{\n\t\tX: box.X + border.Left + offset.X,\n\t\tY: box.Y + border.Top + offset.Y,\n\t}, nil\n}\n","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L420-L456","documentation":"offsetPosition() runs the injected getElementBorderWidth script and converts the result to a {Top, Left float64} border struct; convert() failed, meaning the JS returned something unconvertible (null, strings, or a differently-shaped object). Note the message itself has a formatting bug: %t is applied to a non-bool value, so the type prints as %!t(...) garbage.","triggerScenarios":"Using click({ pos: { x, y } }) / pointer options with an offset on an element where getElementBorderWidth returns null or a non-numeric shape: custom elements, elements whose computed style is unavailable (in a detached shadow root or display:none), or pages stubbing getComputedStyle.","commonSituations":"Clicking by offset on custom web components or elements in closed shadow DOM; offset clicks on elements that are not yet laid out; k6 versions before the offset path was hardened — the mangled %t output makes logs confusing regardless of cause.","solutions":["Ensure the element is rendered and laid out before using a pos offset: await el.waitFor({ state: 'visible' })","Prefer plain click() (center of the element) when you don't truly need an offset","If an offset is required, verify the element's border style is computable (not display:none, not detached shadow DOM)","File a k6 issue about the garbled %t formatting so the real type is logged"],"exampleFix":"// before\nawait el.click({ pos: { x: 10, y: 10 } }); // element hidden\n\n// after\nawait el.waitFor({ state: 'visible' });\nawait el.click(); // center click, no offset conversion needed","handlingStrategy":"validation","validationCode":"// only use pos offsets on laid-out, visible standard elements\nawait el.waitFor({ state: 'visible' });\nconst box = await el.boundingBox();\nif (!box) throw new Error('element not laid out; skip pos offset');","typeGuard":null,"tryCatchPattern":"try {\n  await el.click({ pos: { x: 5, y: 5 } });\n} catch (e) {\n  if (/to border/.test(String(e))) {\n    await el.click(); // fall back to center click\n  } else throw e;\n}","preventionTips":["Avoid pos offsets on custom elements and closed shadow DOM","Ensure elements are rendered before offset-based clicks"],"tags":["browser","click","offset","type-conversion","formatting-bug"],"backgroundTag":"type-conversion-failed","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"}