grafana/k6 · error

internal error while enabling %T: %w

Error message

internal error while enabling %T: %w

What it means

FrameSession.initDomains (frame_session.go:232) enables the base CDP domains for a new target — DOM.enable, Log.enable, Runtime.enable and Target.setAutoAttach(flatten). Any failure is wrapped with the concrete action type (%T). Because these are foundational commands, failure means the CDP session/target is dead or the protocol is incompatible, not that the page content is bad.

Source

Thrown at internal/js/modules/k6/browser/common/frame_session.go:232

	}
	return nil
}

func (fs *FrameSession) getNetworkManager() *NetworkManager {
	return fs.networkManager
}

func (fs *FrameSession) initDomains() error {
	actions := []Action{
		// TODO: can we get rid of the following by doing DOM related stuff in JS instead?
		dom.Enable(),
		cdplog.Enable(),
		cdpruntime.Enable(),
		target.SetAutoAttach(true, true).WithFlatten(true),
	}
	for _, action := range actions {
		if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {
			return fmt.Errorf("internal error while enabling %T: %w", action, err)
		}
	}
	return nil
}

//nolint:cyclop
func (fs *FrameSession) initEvents() {
	fs.logger.Debugf("NewFrameSession:initEvents",
		"sid:%v tid:%v", fs.session.ID(), fs.targetID)

	events := []string{
		cdproto.EventInspectorTargetCrashed,
	}
	fs.session.on(fs.ctx, events, fs.eventCh)
	if !fs.isMainFrame() {
		fs.initRendererEvents()
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Stabilize chromium resources: more memory, fewer concurrent pages/VUs, restart browser per iteration if needed
  2. Check the wrapped %T action and the underlying CDP error to see which domain failed; a version mismatch usually points at Target.setAutoAttach
  3. Use the chromium bundled with/expected by your k6 version; avoid mixing k6 with arbitrary remote browser builds
Defensive patterns

Strategy: retry

Try / catch

try {
  const page = browser.newPage();
} catch (e) {
  if (/internal error while enabling/i.test(String(e))) {
    // CDP session died during domain init — retry page creation on a fresh context
  }
}

Prevention

When it happens

Trigger: Chromium crash/OOM kill at the moment a page or iframe target attaches, target already closed (session torn down) during rapid page churn, or a remote browser whose CDP version rejects one of these commands.

Common situations: High VU counts exhausting memory so chromium dies mid-attach, k6 driving a much older/newer chromium than supported, or flaky websocket endpoints for remote browsers.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/2a57f1048fd50cda. Report an issue: GitHub.