{"record":{"id":"92e3b987091c16b0","repo":"grafana/k6","slug":"fill-w","errorCode":null,"errorMessage":"fill: %w","messagePattern":"fill: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":275,"sourceCode":"\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);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L257-L293","documentation":"When the injected fill script returns 'needsinput', k6 completes the fill by calling Keyboard.InsertText (CDP Input.insertText). This error wraps a failure of that CDP input command, so the value could not be typed into the page.","triggerScenarios":"handle.fill() on elements the script defers to keyboard input while the CDP call fails: page or target closed mid-action, browser session interrupted/crashed, or the element detached between evaluation and text insertion.","commonSituations":"Page navigation or form submission racing the fill; browser process killed (OOM in constrained CI); flaky headless environments dropping input commands; extremely long fill strings under load.","solutions":["Retry the fill after re-locating the element and waiting for the page to be idle","Ensure no navigation/submission is triggered between locating the element and filling","Check browser process health and memory limits (headless_shell crashes surface here)","As a workaround for input[type=number] and similar, use click + type() instead of fill()"],"exampleFix":"// before\nawait handle.fill('42'); // fill: Input.insertText failed\n\n// after\nawait handle.click();\nawait handle.type('42');","handlingStrategy":"retry","validationCode":"// Avoid fills racing navigation\nawait page.waitForLoadState?.() ?? await page.waitForLoadState();\nconst el = await page.$(sel);\nif (!el) throw new Error('element missing');","typeGuard":null,"tryCatchPattern":"async function safeFill(handle, value, tries = 3) {\n  for (let i = 0; i < tries; i++) {\n    try { return await handle.fill(value); }\n    catch (e) {\n      if (!String(e).includes('fill:')) throw e;\n      await sleep(500);\n    }\n  }\n  throw new Error('fill failed after retries');\n}","preventionTips":["Wait for load/idle before filling","Don't trigger submission between locating and filling","Watch browser memory in CI; crashes surface as CDP input failures"],"tags":["browser","fill","keyboard","cdp"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}