{"record":{"id":"27500b0bb354a3c7","repo":"grafana/k6","slug":"converting-result-v-of-type-t-to-size-w","errorCode":null,"errorMessage":"converting result (%v of type %t) to size: %w","messagePattern":"converting result \\((.+?) of type %t\\) to size: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/screenshotter.go","lineNumber":132,"sourceCode":"            return {\n                width: Math.max(\n                    document.body.scrollWidth, document.documentElement.scrollWidth,\n                    document.body.offsetWidth, document.documentElement.offsetWidth,\n                    document.body.clientWidth, document.documentElement.clientWidth\n                ),\n                height: Math.max(\n                    document.body.scrollHeight, document.documentElement.scrollHeight,\n                    document.body.offsetHeight, document.documentElement.offsetHeight,\n                    document.body.clientHeight, document.documentElement.clientHeight\n                ),\n            };\n        }`)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar size Size\n\tif err := convert(result, &size); err != nil {\n\t\treturn nil, fmt.Errorf(\"converting result (%v of type %t) to size: %w\", result, result, err)\n\t}\n\n\treturn &size, nil\n}\n\nfunc (s *screenshotter) originalViewportSize(p *Page) (*Size, error) {\n\tviewportSize := p.viewportSize()\n\tif viewportSize.Width != 0 || viewportSize.Height != 0 {\n\t\treturn &viewportSize, nil\n\t}\n\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := p.frameManager.MainFrame().evaluate(s.ctx, mainWorld, opts, `\n\t() => (\n\t\t{ width: window.innerWidth, height: window.innerHeight }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/screenshotter.go#L114-L150","documentation":"Thrown during full-page screenshots when the JS expression computing document.body/documentElement scroll/offset/client dimensions evaluates successfully, but its result cannot be converted into a Size struct. The message helpfully embeds both the result value and its Go type, so you can see exactly what the page returned instead of {width, height}.","triggerScenarios":"page.screenshot({ fullPage: true }) where document.documentElement/HTML structure is unusual (e.g. height evaluates to null/undefined so the whole object serializes partially, or the page replaced the document during measurement). Fast DOM mutations between evaluation and conversion, or a page whose frames return a non-object, trigger it.","commonSituations":"Full-page screenshots of SPAs that rewrite the DOM continuously (infinite scroll, virtualized lists); pages inside iframe-heavy apps during teardown; screenshots taken while a navigation is starting.","solutions":["Inspect the (%v of type %t) part of the message — it shows the actual value returned; 'null' means the measurement raced a DOM change.","Take the full-page screenshot after the page settles: waitForLoadState or an explicit selector wait first.","Retry the screenshot once — this is a race between evaluation and DOM mutation.","If it persists, screenshot without fullPage (viewport-only) or against a stabilized DOM."],"exampleFix":"// before\nawait page.screenshot({ fullPage: true }); // during DOM churn\n\n// after\nawait page.waitForLoadState('networkidle');\nawait page.screenshot({ fullPage: true });","handlingStrategy":"retry","validationCode":"await page.waitForLoadState('networkidle'); // let DOM settle before fullPage capture","typeGuard":null,"tryCatchPattern":"try {\n  await page.screenshot({ fullPage: true, path: 'f.png' });\n} catch (e) {\n  if (/converting result .* to size/i.test(String(e))) {\n    await page.waitForTimeout(500);\n    await page.screenshot({ fullPage: true, path: 'f.png' });\n  } else throw e;\n}","preventionTips":["Avoid fullPage screenshots on pages with continuous DOM churn; pause the churn first.","Check the embedded value/type in the message to confirm a measurement race.","Stabilize the DOM (stop timers/infinite scroll) before measuring."],"tags":["k6","browser","screenshot","full-page","dom"],"backgroundTag":"screenshot-dom-measurement-failed","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}