{"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/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L257-L293","documentation":"fill() asked the injected script to prepare the element and got back 'needsinput', meaning the text must be inserted via the keyboard (contenteditable and special input cases). The error wraps a failure of Keyboard.InsertText — the CDP Input.insertText call — while typing the value.","triggerScenarios":"el.fill(value) on a contenteditable element or special input where the page navigates, closes, or crashes between the fill preparation and InsertText; the browser session/CDP target dies mid-call (browser crashed, page closed by the app, target swapped).","commonSituations":"Filling rich-text editors (contenteditable) in SPAs that remount or redirect on input; the page's own JS closing/replacing the node mid-fill; resource-exhausted CI browsers crashing; timeouts firing mid-fill.","solutions":["Wait for the editor to be fully loaded and focused before filling: await el.waitFor({ state: 'visible' }); await el.click();","Retry the fill once — transient session hiccups and remounts often clear","For contenteditable, prefer focus + page.keyboard.insertText(value) or type() so you control pacing","Check for browser crashes/page closure in the surrounding log; raise --timeout or the action timeout if the fill is racing a redirect"],"exampleFix":"// before\nawait page.locator('[contenteditable]').fill('draft');\n\n// after\nconst ed = page.locator('[contenteditable]');\nawait ed.waitFor({ state: 'visible' });\nawait ed.click();\nawait page.keyboard.insertText('draft');","handlingStrategy":"retry","validationCode":"// ensure the editable area is focused and stable before fill\nawait el.waitFor({ state: 'visible' });\nawait el.click();","typeGuard":null,"tryCatchPattern":"try {\n  await el.fill(value);\n} catch (e) {\n  if (/fill:/.test(String(e)) && !page.isClosed()) {\n    await page.waitForTimeout(500);\n    await el.fill(value); // single retry\n  } else throw e;\n}","preventionTips":["Focus contenteditable editors before filling","Avoid filling during known redirect/remount windows in SPAs","Give fill actions explicit timeouts sized to editor initialization"],"tags":["browser","fill","keyboard","contenteditable","cdp"],"backgroundTag":"browser-input-dispatch-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"}