{"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/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L252-L288","documentation":"fill() evaluates an injected script that must return one of the protocol strings 'done', 'needsinput', or 'error:...'. This error means the evaluation returned a non-string Go value (nil, bool, object), i.e. the injected-script contract was broken. This is an internal invariant failure (bug or version mismatch), not a wrong fill value.","triggerScenarios":"handle.fill(value) when the injected script returns undefined (execution context destroyed mid-eval) or when the bundled injected JS does not match the Go module, e.g. after a partial upgrade or a custom xk6 build mixing browser module versions.","commonSituations":"Custom xk6 builds bundling a stale injected script; page navigating while fill runs; rarely, a genuine k6 bug. Note: filling a non-fillable element normally yields 'element is not an <input>, <textarea> or [contenteditable] element' via errorFromDOMError, not this error.","solutions":["Rebuild/upgrade with a single clean k6 (or xk6) version so the injected script and Go code match","Re-query the element and retry fill after the page settles (wait for load state)","Verify the target really is input/textarea/contenteditable to rule out the normal not-fillable path","If reproducible on a stock k6 release, report it with the script and page URL"],"exampleFix":"// before\nawait handle.fill('hello'); // unexpected type <nil>\n\n// after\nconst el = await page.waitForSelector('#name'); // fresh handle in a live context\nawait el.fill('hello');","handlingStrategy":"try-catch","validationCode":"// Confirm the target is fillable before calling fill\nconst tag = await handle.evaluate((el) => el.tagName);\nconst editable = await handle.evaluate((el) => el.isContentEditable);\nif (!['INPUT', 'TEXTAREA'].includes(tag) && !editable) {\n  throw new Error('target is not fillable');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await el.fill('hello');\n} catch (e) {\n  if (String(e).includes('unexpected type')) {\n    // internal contract break: re-locate and retry once, then upgrade k6\n    await (await page.$(sel)).fill('hello');\n  } else { throw e; }\n}","preventionTips":["Use matching k6/xk6 versions so the injected script is never stale","Re-query elements before fill after navigation or re-renders","Expect not-fillable errors as DOM messages, not 'unexpected type' — the latter means a bug"],"tags":["browser","fill","injected-script","internal-invariant"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}