{"record":{"id":"df64217bbc30724e","repo":"grafana/k6","slug":"node-has-0-height","errorCode":null,"errorMessage":"node has 0 height","messagePattern":"node has 0 height","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/screenshotter.go","lineNumber":310,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting original viewport size: %w\", err)\n\t}\n\toriginalSize := h.frame.page.emulatedSize\n\n\terr = h.waitAndScrollIntoViewIfNeeded(h.ctx, false, true, opts.Timeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"scrolling element into view: %w\", err)\n\t}\n\n\tbbox, err := h.boundingBox()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"node is either not visible or not an HTMLElement: %w\", err)\n\t}\n\tif bbox.Width <= 0 {\n\t\treturn nil, fmt.Errorf(\"node has 0 width\")\n\t}\n\tif bbox.Height <= 0 {\n\t\treturn nil, fmt.Errorf(\"node has 0 height\")\n\t}\n\n\tfitsViewport := bbox.Width <= viewportSize.Width && bbox.Height <= viewportSize.Height\n\tif !fitsViewport { //nolint:nestif\n\t\toverriddenViewportSize := Size{\n\t\t\tWidth:  math.Max(viewportSize.Width, bbox.Width),\n\t\t\tHeight: math.Max(viewportSize.Height, bbox.Height),\n\t\t}.enclosingIntSize()\n\t\tdefer func() {\n\t\t\tif restoreErr := s.restoreViewport(h.frame.page, originalSize); restoreErr != nil {\n\t\t\t\terr = errors.Join(err, fmt.Errorf(\"restoring viewport: %w\", restoreErr))\n\t\t\t}\n\t\t}()\n\t\tif err := h.frame.page.setViewportSize(s.ctx, overriddenViewportSize); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"setting viewport size to %s: %w\",\n\t\t\t\toverriddenViewportSize, err)\n\t\t}\n\t\terr = h.waitAndScrollIntoViewIfNeeded(h.ctx, false, true, opts.Timeout)","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/screenshotter.go#L292-L328","documentation":"Sibling of the zero-width guard: the element's bounding box height is <= 0 at screenshot time, so the capture is refused. Width may be positive, but a zero-height element (collapsed row, empty block before content loads) yields no pixels.","triggerScenarios":"await elementHandle.screenshot() on elements with height: 0 / collapsed (empty container before async content renders, display collapsed by CSS grid auto rows, element whose only content is absolutely positioned and removed from flow).","commonSituations":"Screenshotting a chart container before the chart library initializes it; empty list/table bodies; accordions measured while closed; elements whose height comes only from floated/absolute children that have not rendered.","solutions":["Wait for the content that gives the element height (chart rendered, items loaded) before capturing.","Give the container a min-height in test CSS or app CSS.","Re-check with a computed-style assertion in page.evaluate(() => getComputedStyle(el).height).","Screenshot a parent wrapper with non-zero height instead."],"exampleFix":"// before\nconst c = page.$('#chart');\nawait c.waitFor(); // attached but 0px tall\nawait c.screenshot({ path: 'c.png' });\n\n// after\nconst c = page.$('#chart');\nawait c.waitFor();\nawait page.waitForFunction(() => document.querySelector('#chart').clientHeight > 0);\nawait c.screenshot({ path: 'c.png' });","handlingStrategy":"validation","validationCode":"await page.waitForFunction((sel) =>\n  document.querySelector(sel)?.clientHeight > 0, selector);\nawait handle.screenshot({ path: 'e.png' });","typeGuard":"const hasNonZeroHeight = async (h) => {\n  const b = await h.boundingBox();\n  return !!b && b.height > 0;\n};","tryCatchPattern":null,"preventionTips":["Wait for chart libraries/async content to size their containers before capture.","Give containers a min-height in test CSS.","Verify clientHeight > 0 with waitForFunction for dynamic content."],"tags":["k6","browser","screenshot","element-handle","layout"],"backgroundTag":"zero-size-element","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-09-20T22:01:45.163Z","contentChangedAt":"2026-09-20T22:01:45.163Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}