{"record":{"id":"0e32a19be6c73a8c","repo":"grafana/k6","slug":"checking-element-is-hidden-w","errorCode":null,"errorMessage":"checking element is hidden: %w","messagePattern":"checking element is hidden: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1102,"sourceCode":"}\n\n// IsEnabled checks if the element is enabled.\nfunc (h *ElementHandle) IsEnabled() (bool, error) {\n\tok, err := h.isEnabled(h.ctx, 0)\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 enabled: %w\", err)\n\t}\n\n\treturn ok, nil\n}\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) {","sourceCodeStart":1084,"sourceCodeEnd":1120,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1084-L1120","documentation":"Returned by ElementHandle.isHidden() when the state probe fails with a non-timeout error. Timeout errors are deliberately ignored (hiding is evaluated with a 0 timeout), so this error signals an operational failure: stale/detached handle, destroyed execution context, CDP transport error, or closed page/browser - not merely that the element is visible.","triggerScenarios":"Calling isHidden() on a handle whose node was removed; after a navigation destroyed the context; after the page was closed; when the browser crashed or the session dropped.","commonSituations":"Checking visibility of list items in re-rendering SPAs with cached handles; probing after a redirect; teardown races when the browser closes before the last assertion.","solutions":["Re-query the handle immediately before isHidden()","Wait for the element to be attached if it may not exist yet","Ensure the page is still open before probing","Distinguish the thrown error (operational) from a false return (element visible)"],"exampleFix":"// before\nconst hidden = await h.isHidden(); // stale handle\n// after\nconst el = await page.$('#modal');\nconst hidden = await el.isHidden();","handlingStrategy":"try-catch","validationCode":"const el = await page.$('#modal');\nif (el) {\n  const hidden = await el.isHidden();\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.isHidden();\n} catch (e) {\n  if (String(e).includes('checking element is hidden')) {\n    const fresh = await page.$(sel);\n    return fresh ? fresh.isHidden() : true;\n  }\n  throw e;\n}","preventionTips":["Treat a thrown error as 'could not determine', not as 'visible'","Re-query handles before visibility probes","Probe before the page closes, not after"],"tags":["browser","element-handle","is-hidden","detached-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}