{"record":{"id":"690cad54141e4329","repo":"grafana/k6","slug":"unexpected-type-t","errorCode":null,"errorMessage":"unexpected type %T","messagePattern":"unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":270,"sourceCode":"}\n\nfunc (h *ElementHandle) fill(_ context.Context, value string) error {\n\tfn := `\n\t\t(node, injected, value) => {\n\t\t\treturn injected.fill(node, value);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := h.evalWithScript(h.ctx, opts, fn, value)\n\tif err != nil {\n\t\treturn err\n\t}\n\ts, ok := result.(string)\n\tif !ok {\n\t\treturn fmt.Errorf(\"unexpected type %T\", result)\n\t}\n\n\tif s == resultNeedsInput {\n\t\tif err := h.frame.page.Keyboard.InsertText(value); err != nil {\n\t\t\treturn fmt.Errorf(\"fill: %w\", err)\n\t\t}\n\t} else if s != resultDone {\n\t\t// Either we're done or an error happened (returned as \"error:...\" from JS)\n\t\treturn errorFromDOMError(s)\n\t}\n\n\treturn nil\n}\n\nfunc (h *ElementHandle) focus(apiCtx context.Context, resetSelectionIfNotFocused bool) error {\n\tfn := `\n\t\t(node, injected, resetSelectionIfNotFocused) => {\n\t\t\treturn injected.focusNode(node, resetSelectionIfNotFocused);","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L252-L288","documentation":"Internal invariant in ElementHandle.fill(): the injected fill script must return a string ('done', 'needsinput', or 'error:...'), but the evaluation returned a different type. This indicates the Go/JS contract of the injected script was violated rather than a user input problem.","triggerScenarios":"el.fill('text') where evalWithScript returns a non-string because the injected script was tampered with by page JS, or an internal regression in the injected bundle; distinct from the DOM-level 'error:notfillableelement' errors which arrive as strings and are mapped by errorFromDOMError.","commonSituations":"Pages defining hostile prototypes or overriding globals used by the injected script; k6 version skew between generated JS helpers and the Go runtime; essentially never seen on ordinary pages.","solutions":["Upgrade k6 to the latest patch release to rule out an internal contract bug","Reproduce against a minimal static page; if it only fails on your app, audit page scripts that override Object/Function/JSON","Fall back to el.focus() + page.keyboard.type('...') for the same effect","Report a k6 issue with a minimal reproducer if it persists on a clean page"],"exampleFix":"// workaround when fill() hits the invariant\n// before\nawait el.fill('hello');\n\n// after\nawait el.focus();\nawait page.keyboard.type('hello');","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await el.fill('hello');\n} catch (e) {\n  if (/unexpected type/.test(String(e))) {\n    await el.focus();\n    await page.keyboard.type('hello');\n  } else throw e;\n}","preventionTips":["Keep k6 version consistent between script authoring and CI runs","Test fill flows on a static page first when an app is suspected of tampering with eval"],"tags":["browser","fill","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"}