grafana/k6 · error
converting result (%v of type %t) to border: %w
Error message
converting result (%v of type %t) to border: %w
What it means
offsetPosition() converts the result of injected.getElementBorderWidth into struct{Top, Left float64}. This error means the eval result did not deserialize into that {top,left} shape. Note the message itself contains a formatting bug: %t (the bool verb) is used for the result argument, so the rendered type is garbage like %!t(string=...).
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:438
func (h *ElementHandle) offsetPosition(apiCtx context.Context, offset *Position) (*Position, error) {
fn := `
(node, injected) => {
return injected.getElementBorderWidth(node);
}
`
opts := evalOptions{
forceCallable: true,
returnByValue: true,
}
result, err := h.evalWithScript(apiCtx, opts, fn)
if err != nil {
return nil, err
}
var border struct{ Top, Left float64 }
if err := convert(result, &border); err != nil {
return nil, fmt.Errorf("converting result (%v of type %t) to border: %w", result, result, err)
}
box, err := h.BoundingBox()
if err != nil {
return nil, fmt.Errorf("finding offset position: %w", err)
}
if box == nil || (border.Left == 0 && border.Top == 0) {
return nil, ErrElementNotVisible
}
// Make point relative to the padding box to align with offsetX/offsetY.
return &Position{
X: box.X + border.Left + offset.X,
Y: box.Y + border.Top + offset.Y,
}, nil
}
View on GitHub (pinned to 93accf6570)
Solutions
- Retry after re-locating the element
- Upgrade k6 so the injected script and Go module match
- Avoid the offset path: omit `position` to click the element center
- Report the %t formatting bug upstream (should be %T) when filing any reproduction
Example fix
// before
await handle.click({ position: { x: 10, y: 10 } }); // converting result ... to border
// after
await handle.click(); // center click, avoids getElementBorderWidth path Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check the element still exists before an offset click
const attached = await handle.evaluate((el) => el.isConnected);
if (!attached) throw new Error('element detached'); Try / catch
try {
await handle.click({ position: { x: 10, y: 10 } });
} catch (e) {
if (String(e).includes('to border')) {
await handle.click(); // fall back to center click
} else { throw e; }
} Prevention
- Prefer center clicks; use position only when necessary
- Re-locate elements before offset clicks
- Report the %t format bug when filing reproductions
When it happens
Trigger: click()/dblclick()/hover() with a `position` option (the offsetPosition path) when the border-width script returns undefined or a non-object — node is not an element anymore, execution context mismatch, or injected-script version skew.
Common situations: Offset clicks on elements in cross-origin iframes; stale handles; custom xk6 builds with mismatched injected script; also the %t verb makes diagnosing the real type harder.
Related errors
- finding offset position: %w
- element is not attached to the DOM
- getting document element: nil document
- clicking the checkbox did not change its state
- parsing check options: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/06e7ef780ba77672.
Report an issue: GitHub.