{"record":{"id":"a4507e6889369be2","repo":"grafana/k6","slug":"setting-content-w","errorCode":null,"errorMessage":"setting content: %w","messagePattern":"setting content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1775,"sourceCode":"\n\t// TODO(@inancgumus): Respect the FrameSetContentOptions before executing the action.\n\t// A solution is similar to the logic in `WaitForLoadState`.\n\n\tjs := `(html) => {\n\t\twindow.stop();\n\t\tdocument.open();\n\t\tdocument.write(html);\n\t\tdocument.close();\n\t}`\n\n\tf.waitForExecutionContext(utilityWorld)\n\n\teopts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tif _, err := f.evaluate(f.ctx, utilityWorld, eopts, js, html); err != nil {\n\t\treturn fmt.Errorf(\"setting content: %w\", err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn nil\n}\n\n// SetInputFiles sets input files for the selected element.\nfunc (f *Frame) SetInputFiles(selector string, pfiles *Files, popts *FrameSetInputFilesOptions) error {\n\tf.log.Debugf(\"Frame:SetInputFiles\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tif err := f.setInputFiles(selector, pfiles, popts); err != nil {\n\t\treturn fmt.Errorf(\"setting input files on %q: %w\", selector, err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn nil","sourceCodeStart":1757,"sourceCodeEnd":1793,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L1757-L1793","documentation":"Frame.SetContent() evaluates document.open()/write()/close() with your HTML in the frame's utility world; any evaluation failure is wrapped as 'setting content: <cause>'. Common causes are a missing/destroyed execution context (frame navigating or detaching), a closed page, or a context cancelled by the k6 iteration timeout.","triggerScenarios":"frame.setContent(html) while the frame is mid-navigation; calling setContent on a detached frame or after page.close(); the k6 iteration was cancelled (per-iteration timeout reached) so f.ctx was done.","commonSituations":"setContent racing an automatic navigation (redirect chains after goto); reuse of stale frame handles; tight iteration timeouts in load tests causing context cancellation.","solutions":["Wait for the frame to be idle before setContent: await frame.waitForLoadState('load') (or waitForNavigation to settle redirects).","Use a fresh frame/page reference; check page.isClosed() first.","Raise the k6 iteration timeout (options thresholds / per-VU timeout) if context cancellation is the cause.","For iframes, ensure the parent document finished loading so the utility world exists."],"exampleFix":"// before\nawait page.goto(url);\nawait page.setContent(html); // redirect still in flight\n\n// after\nawait page.goto(url);\nawait page.waitForLoadState('load');\nawait page.setContent(html);","handlingStrategy":"retry","validationCode":"if (page.isClosed()) throw new Error('page closed');\nawait page.waitForLoadState('load');","typeGuard":null,"tryCatchPattern":"try { await page.setContent(html); }\ncatch (e) {\n  if (/setting content/.test(e.message)) { await page.waitForLoadState('load'); return page.setContent(html); }\n  throw e;\n}","preventionTips":["Wait for redirects/load to settle before setContent","Check page.isClosed() and frame detachment first","Size k6 iteration timeouts above worst-case page load"],"tags":["browser","frame","navigation","execution-context","cancellation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}