{"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":115,"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, *Size, error) {\n\toriginalViewportSize := p.viewportSize()\n\tviewportSize := originalViewportSize\n\tif viewportSize.Width != 0 || viewportSize.Height != 0 {\n\t\treturn &viewportSize, &originalViewportSize, 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() => (","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/screenshotter.go#L97-L133","documentation":"Thrown by the k6 browser module's full-page screenshot path. fullPageSize() evaluates JavaScript in the page to compute max(scrollWidth/offsetWidth/clientWidth, ...Height) and then converts the result into a Go Size struct via a JSON marshal/unmarshal round-trip (helpers.go convert). If the value returned by the in-page evaluation does not deserialize into {width,height} numeric fields, this error wraps the json error and reports the offending value and its Go type.","triggerScenarios":"Calling page.screenshot({fullPage: true}) (or locator/pageLocator screenshot with fullPage) when document.body or document.documentElement is missing (the evaluated JS explicitly returns null), or when the evaluation result has an unexpected shape/type (e.g. a string or non-numeric width/height), so json.Unmarshal into Size fails.","commonSituations":"Screenshotting immediately after page.goto() before the DOM is built (about:blank, text/plain responses, PDF/JSON payloads, redirect interstitials); pages that navigate or rewrite document.body mid-measurement; XML/SVG documents served without an HTML body; races between load and screenshot in CI.","solutions":["Wait for the DOM before shooting: await page.waitForLoadState('load') (or 'networkidle') and/or await page.waitForSelector('body') before page.screenshot({fullPage:true}).","If the target is not an HTML document (JSON/XML/plain text response), drop fullPage:true — a viewport screenshot does not need document metrics.","Wrap the call in try/catch and fall back to a non-fullPage screenshot so the test continues.","Upgrade k6 — the browser module's screenshot/eval handling has had fixes around result conversion; check the k6 release notes and GitHub issues for your version."],"exampleFix":"// before\nawait page.goto(url);\nawait page.screenshot({ path: 'full.png', fullPage: true }); // may hit converting-result error on body-less pages\n\n// after\nawait page.goto(url);\nawait page.waitForLoadState('load');\ntry {\n  await page.screenshot({ path: 'full.png', fullPage: true });\n} catch (e) {\n  if (String(e).includes('converting result')) {\n    await page.screenshot({ path: 'full.png' }); // viewport fallback\n  } else { throw e; }\n}","handlingStrategy":"try-catch","validationCode":"await page.waitForSelector('body', { state: 'attached' });\nawait page.waitForLoadState('load');","typeGuard":null,"tryCatchPattern":"try {\n  await page.screenshot({ path: 's.png', fullPage: true });\n} catch (e) {\n  if (String(e).includes('converting result')) {\n    await page.screenshot({ path: 's.png' }); // fallback: viewport-only capture\n  } else { throw e; }\n}","preventionTips":["Always await page.waitForLoadState before fullPage screenshots.","Do not use fullPage on non-HTML responses (JSON, plain text, PDF).","Keep screenshot and navigation strictly serialized in the script."],"tags":["k6","browser","screenshot","fullpage","dom","json-conversion"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}