{"record":{"id":"987a07e9bcd4409e","repo":"grafana/k6","slug":"getting-element-s-inner-html-w","errorCode":null,"errorMessage":"getting element's inner HTML: %w","messagePattern":"getting element's inner HTML: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":997,"sourceCode":"\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// InnerHTML returns the inner HTML of the element.\nfunc (h *ElementHandle) InnerHTML() (string, error) {\n\tinnerHTML := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.innerHTML(apiCtx)\n\t}\n\topts := NewElementHandleBaseOptions(h.DefaultTimeout())\n\tinnerHTMLAction := h.newAction(\n\t\t[]string{}, innerHTML, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tv, err := call(h.ctx, innerHTMLAction, opts.Timeout)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting element's inner HTML: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\ts, ok := v.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type %T (expecting string)\", v)\n\t}\n\n\treturn s, nil\n}\n\n// InnerText returns the inner text of the element.\nfunc (h *ElementHandle) InnerText() (string, error) {\n\tinnerText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.innerText(apiCtx)\n\t}\n\topts := NewElementHandleBaseOptions(h.DefaultTimeout())","sourceCodeStart":979,"sourceCodeEnd":1015,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L979-L1015","documentation":"Returned by ElementHandle.innerHTML() when the underlying evaluation fails. The method evaluates element.innerHTML via CDP with returnByValue inside a retried action; this error wraps CDP/transport failures, stale handles, destroyed execution contexts (navigation), or an expired timeout.","triggerScenarios":"Calling innerHTML() on a detached or pre-navigation handle; calling it while the page navigates and the execution context is destroyed; the action timeout expiring; the browser/page being closed mid-evaluation.","commonSituations":"Scraping rendered HTML from SPAs that re-render between page.$() and innerHTML(); reading HTML right after a click that triggers navigation; tight timeouts on slow CI browsers.","solutions":["Wait for the element: page.waitForSelector(sel, { state: 'attached' })","Re-query the handle immediately before innerHTML()","After a navigation-triggering action, await page.waitForLoadState() first","Increase the timeout if the wrapped error indicates a timeout"],"exampleFix":"// before\nconst html = await (await page.$('#content')).innerHTML();\n// after\nawait page.waitForSelector('#content', { state: 'attached' });\nconst el = await page.$('#content');\nconst html = await el.innerHTML();","handlingStrategy":"try-catch","validationCode":"await page.waitForSelector('#content', { state: 'attached' });\nconst el = await page.$('#content');\nif (el) {\n  const html = await el.innerHTML();\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.innerHTML();\n} catch (e) {\n  if (String(e).includes(\"getting element's inner HTML\")) {\n    await page.waitForLoadState();\n    return (await page.$(sel)).innerHTML();\n  }\n  throw e;\n}","preventionTips":["waitForSelector(attached) before DOM reads","Re-query handles after re-renders or navigations","waitForLoadState() after actions that navigate"],"tags":["browser","element-handle","inner-html","detached-handle","timeout"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}