{"record":{"id":"100e946c6efaf963","repo":"grafana/k6","slug":"node-has-0-width","errorCode":null,"errorMessage":"node has 0 width","messagePattern":"node has 0 width","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/screenshotter.go","lineNumber":289,"sourceCode":"\nfunc (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleScreenshotOptions) ([]byte, error) {\n\tformat := opts.Format\n\tviewportSize, originalViewportSize, err := s.originalViewportSize(h.frame.page)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting original viewport size: %w\", err)\n\t}\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\tvar overriddenViewportSize *Size\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\tif err := h.frame.page.setViewportSize(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)\n\t\tif err != nil {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/screenshotter.go#L271-L307","documentation":"elementHandle.screenshot() refuses to capture when the element's bounding box has width <= 0. The element has a layout box but renders with zero width (first check, before any viewport resizing).","triggerScenarios":"Elements with CSS width:0 (collapsed), zero-size inline elements, containers whose children are absolutely positioned so the parent has no intrinsic width, or elements in a display:grid/flex context that collapsed to 0.","commonSituations":"Empty data containers before async data arrives; icon-only elements sized only by content that hasn't loaded; elements animated from width:0 (drawers, progress bars) captured mid-animation.","solutions":["Wait until the element has size: poll await locator.boundingBox() until width > 0, or waitFor({state:'visible'}) plus a settled state.","Give the element an explicit width via CSS if it is a container you control.","Capture later in the lifecycle (after data render/charts drawn).","If zero-width is expected, screenshot the page with a clip around the area instead of the element."],"exampleFix":"// before\nawait page.$('.drawer').then(el => el.screenshot({ path: 'd.png' })); // mid-animation width 0\n\n// after\nconst drawer = page.locator('.drawer');\nawait page.waitForFunction(() => document.querySelector('.drawer').getBoundingClientRect().width > 0);\nawait drawer.screenshot({ path: 'd.png' });","handlingStrategy":"validation","validationCode":"const bb = await locator.boundingBox();\nif (!bb || bb.width <= 0) throw new Error('element has zero width; wait for it to render');","typeGuard":"function hasPositiveWidth(bb) { return bb != null && Number.isFinite(bb.width) && bb.width > 0; }","tryCatchPattern":"try { await el.screenshot({ path: 'e.png' }); }\ncatch (e) { if (String(e).includes('node has 0 width')) { /* wait for width>0 then retry */ } else throw e; }","preventionTips":["Wait for content (data, images) that gives the element width.","Avoid capturing mid-animation drawers/progress bars.","Prefer locator.screenshot() so you can boundingBox() first."],"tags":["k6","browser","screenshot","element-handle","zero-size","layout"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}