grafana/k6 · error

emulating media

Error message

emulating media: %w

What it means

Aggregated failure while applying emulated media (media type, color scheme, reduced motion) to every frame session of the page. Fires when any frame's CDP emulation command fails — detached iframe session, canceled context, or browser rejection of the emulation values.

Solutions

  1. Use supported values for media/colorScheme/reducedMotion in EmulateMedia options
  2. Call EmulateMedia on a stable, fully loaded page
  3. Retry if an out-of-process iframe attached mid-update
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/page.go:1076 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/84288f341eab5bc1. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/page.go:1081

func (p *Page) DispatchEvent(selector string, typ string, eventInit any, opts *FrameDispatchEventOptions) error {
	p.logger.Debugf("Page:DispatchEvent", "sid:%v selector:%s", p.sessionID(), selector)

	return p.MainFrame().DispatchEvent(selector, typ, eventInit, opts)
}

// EmulateMedia emulates the given media type.
func (p *Page) EmulateMedia(popts *PageEmulateMediaOptions) error {
	p.logger.Debugf("Page:EmulateMedia", "sid:%v", p.sessionID())

	p.mediaType = popts.Media
	p.colorScheme = popts.ColorScheme
	p.reducedMotion = popts.ReducedMotion

	p.frameSessionsMu.RLock()
	for _, fs := range p.frameSessions {
		if err := fs.updateEmulateMedia(); err != nil {
			p.frameSessionsMu.RUnlock()
			return fmt.Errorf("emulating media: %w", err)
		}
	}
	p.frameSessionsMu.RUnlock()

	applySlowMo(p.ctx)

	return nil
}

// EmulateVisionDeficiency activates/deactivates emulation of a vision deficiency.
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,

View on GitHub (pinned to 3fcf5388d7)