{"record":{"id":"eecbfa6713d65c09","repo":"grafana/k6","slug":"checking-element-is-visible-w","errorCode":null,"errorMessage":"checking element is visible: %w","messagePattern":"checking element is visible: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1113,"sourceCode":"}\n\n// IsHidden checks if the element is hidden.\nfunc (h *ElementHandle) IsHidden() (bool, error) {\n\tok, err := h.isHidden(h.ctx)\n\t// We don't care anout timeout errors here!\n\tif err != nil && !errors.Is(err, ErrTimedOut) {\n\t\treturn false, fmt.Errorf(\"checking element is hidden: %w\", err)\n\t}\n\n\treturn ok, nil\n}\n\n// IsVisible checks if the element is visible.\nfunc (h *ElementHandle) IsVisible() (bool, error) {\n\tok, err := h.isVisible(h.ctx)\n\t// We don't care anout timeout errors here!\n\tif err != nil && !errors.Is(err, ErrTimedOut) {\n\t\treturn false, fmt.Errorf(\"checking element is visible: %w\", err)\n\t}\n\n\treturn ok, nil\n}\n\n// OwnerFrame returns the frame containing this element.\nfunc (h *ElementHandle) OwnerFrame() (_ *Frame, rerr error) {\n\tfn := `\n\t\t(node, injected) => {\n\t\t\treturn injected.getDocumentElement(node);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: false,\n\t}\n\tres, err := h.evalWithScript(h.ctx, opts, fn)\n\tif err != nil {","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1095-L1131","documentation":"Returned by ElementHandle.isVisible() when the state probe fails with a non-timeout error. Timeouts are intentionally ignored (the probe uses a 0 timeout; a timeout just means 'not visible right now' and returns false), so this error means the probe itself failed: stale handle, destroyed execution context, CDP failure, or closed page/browser.","triggerScenarios":"Calling isVisible() on a detached handle or one captured before navigation; while the page navigates; after page.close(); when the CDP session dropped or the browser crashed.","commonSituations":"Cached handles invalidated by SPA re-renders; visibility checks racing redirects; browser shutdown before the final check completes.","solutions":["Re-query the handle right before isVisible()","Wait for the element if its existence is uncertain: page.waitForSelector(sel, { state: 'attached' })","Confirm the page is still open before probing","Handle the thrown error separately from a false result"],"exampleFix":"// before\nconst visible = await h.isVisible(); // stale handle\n// after\nconst el = await page.$('#banner');\nconst visible = await el.isVisible();","handlingStrategy":"try-catch","validationCode":"const el = await page.$('#banner');\nif (el) {\n  const visible = await el.isVisible();\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.isVisible();\n} catch (e) {\n  if (String(e).includes('checking element is visible')) {\n    const fresh = await page.$(sel);\n    return fresh ? fresh.isVisible() : false;\n  }\n  throw e;\n}","preventionTips":["A thrown error means the probe failed (stale handle/dead page), not that the element is hidden","Re-query handles before visibility checks","Guard assertions so browser shutdown does not fail the last check"],"tags":["browser","element-handle","is-visible","detached-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}