grafana/k6 · error
setting emulated vision deficiency %q: %w
Error message
setting emulated vision deficiency %q: %w
What it means
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.
Source
Thrown at internal/js/modules/k6/browser/common/page.go:1105
func (p *Page) EmulateVisionDeficiency(typ string) error {
p.logger.Debugf("Page:EmulateVisionDeficiency", "sid:%v typ:%s", p.sessionID(), typ)
validTypes := map[string]emulation.SetEmulatedVisionDeficiencyType{
"achromatopsia": emulation.SetEmulatedVisionDeficiencyTypeAchromatopsia,
"blurredVision": emulation.SetEmulatedVisionDeficiencyTypeBlurredVision,
"deuteranopia": emulation.SetEmulatedVisionDeficiencyTypeDeuteranopia,
"none": emulation.SetEmulatedVisionDeficiencyTypeNone,
"protanopia": emulation.SetEmulatedVisionDeficiencyTypeProtanopia,
"tritanopia": emulation.SetEmulatedVisionDeficiencyTypeTritanopia,
}
t, ok := validTypes[typ]
if !ok {
return fmt.Errorf("unsupported vision deficiency: %s", typ)
}
action := emulation.SetEmulatedVisionDeficiency(t)
if err := action.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {
return fmt.Errorf("setting emulated vision deficiency %q: %w", typ, err)
}
applySlowMo(p.ctx)
return nil
}
// Evaluate runs JS code within the execution context of the main frame of the page.
func (p *Page) Evaluate(pageFunc string, args ...any) (any, error) {
p.logger.Debugf("Page:Evaluate", "sid:%v", p.sessionID())
return p.MainFrame().Evaluate(pageFunc, args...)
}
// EvaluateHandle runs JS code within the execution context of the main frame of the page.
func (p *Page) EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) {
p.logger.Debugf("Page:EvaluateHandle", "sid:%v", p.sessionID())
View on GitHub (pinned to 93accf6570)
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
Example fix
// before
await page.close();
await page.emulateVisionDeficiency('deuteranopia');
// after
await page.emulateVisionDeficiency('deuteranopia');
await page.close(); Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) throw new Error('page closed before vision emulation'); Try / catch
try { await page.emulateVisionDeficiency(typ); } catch (e) { if (!/setting emulated vision deficiency/.test(e.message)) throw e; } Prevention
- Run emulation early in the iteration, far from teardown
- Treat repeated failures as a browser/session health signal and restart the browser
When it happens
Trigger: page.emulateVisionDeficiency('none') on a page that is closing, whose renderer crashed, or after the DevTools connection dropped.
Common situations: 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.
Related errors
- internal error while initializing frame %T: %w
- internal error while updating emulated media: %w
- bringing page to front: %w
- emulating media: %w
- unsupported vision deficiency: %s
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/b608003d1cc050a9.
Report an issue: GitHub.