{"record":{"id":"b608003d1cc050a9","repo":"grafana/k6","slug":"setting-emulated-vision-deficiency-q-w","errorCode":null,"errorMessage":"setting emulated vision deficiency %q: %w","messagePattern":"setting emulated vision deficiency %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":1105,"sourceCode":"func (p *Page) EmulateVisionDeficiency(typ string) error {\n\tp.logger.Debugf(\"Page:EmulateVisionDeficiency\", \"sid:%v typ:%s\", p.sessionID(), typ)\n\n\tvalidTypes := map[string]emulation.SetEmulatedVisionDeficiencyType{\n\t\t\"achromatopsia\": emulation.SetEmulatedVisionDeficiencyTypeAchromatopsia,\n\t\t\"blurredVision\": emulation.SetEmulatedVisionDeficiencyTypeBlurredVision,\n\t\t\"deuteranopia\":  emulation.SetEmulatedVisionDeficiencyTypeDeuteranopia,\n\t\t\"none\":          emulation.SetEmulatedVisionDeficiencyTypeNone,\n\t\t\"protanopia\":    emulation.SetEmulatedVisionDeficiencyTypeProtanopia,\n\t\t\"tritanopia\":    emulation.SetEmulatedVisionDeficiencyTypeTritanopia,\n\t}\n\tt, ok := validTypes[typ]\n\tif !ok {\n\t\treturn fmt.Errorf(\"unsupported vision deficiency: %s\", typ)\n\t}\n\n\taction := emulation.SetEmulatedVisionDeficiency(t)\n\tif err := action.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {\n\t\treturn fmt.Errorf(\"setting emulated vision deficiency %q: %w\", typ, err)\n\t}\n\n\tapplySlowMo(p.ctx)\n\n\treturn nil\n}\n\n// Evaluate runs JS code within the execution context of the main frame of the page.\nfunc (p *Page) Evaluate(pageFunc string, args ...any) (any, error) {\n\tp.logger.Debugf(\"Page:Evaluate\", \"sid:%v\", p.sessionID())\n\n\treturn p.MainFrame().Evaluate(pageFunc, args...)\n}\n\n// EvaluateHandle runs JS code within the execution context of the main frame of the page.\nfunc (p *Page) EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) {\n\tp.logger.Debugf(\"Page:EvaluateHandle\", \"sid:%v\", p.sessionID())\n","sourceCodeStart":1087,"sourceCodeEnd":1123,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/page.go#L1087-L1123","documentation":"After validating the vision deficiency name, Page.EmulateVisionDeficiency sends emulation.SetEmulatedVisionDeficiency over CDP; this error wraps a protocol-level failure of that command. Validation already passed, so the failure is environmental: detached session, closing page, or dead browser connection.","triggerScenarios":"page.emulateVisionDeficiency('none') on a page that is closing, whose renderer crashed, or after the DevTools connection dropped.","commonSituations":"Emulating vision deficiency near the end of an iteration while teardown begins; renderer crash from a heavy page; browser already closed by a prior statement.","solutions":["Verify the page is open and loaded before the call","Recreate the page if a crash was observed earlier","Move emulation earlier in the script, away from teardown","Check the browser process and websocket connection if it fails repeatedly"],"exampleFix":"// before\nawait page.close();\nawait page.emulateVisionDeficiency('deuteranopia');\n\n// after\nawait page.emulateVisionDeficiency('deuteranopia');\nawait page.close();","handlingStrategy":"try-catch","validationCode":"if (page.isClosed()) throw new Error('page closed before vision emulation');","typeGuard":null,"tryCatchPattern":"try { await page.emulateVisionDeficiency(typ); } catch (e) { if (!/setting emulated vision deficiency/.test(e.message)) throw e; }","preventionTips":["Run emulation early in the iteration, far from teardown","Treat repeated failures as a browser/session health signal and restart the browser"],"tags":["browser","emulation","cdp","vision-deficiency","page-lifecycle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}