grafana/k6 · error

protocol error while initializing worker %T

Error message

protocol error while initializing worker %T: %w

What it means

Raised in Worker.initEvents when one of the bootstrap CDP actions sent to a newly attached web worker — log.Enable, network.Enable, or runtime.RunIfWaitingForDebugger — fails to execute. The '%T' names which action failed. This fires during NewWorker setup when the worker target cannot be instrumented: the worker terminated before attachment, the session is unauthorized, or the CDP connection dropped.

Solutions

  1. Ensure the web worker script exists and stays alive long enough to be attached
  2. Retry creating the worker handle if the worker was racing with termination
  3. Check browser flags/permissions that might block worker instrumentation
  4. Inspect the wrapped CDP error to identify which of log.Enable/network.Enable/RunIfWaitingForDebugger failed and why
Defensive patterns

Strategy: retry

When it happens

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

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/df6893d822080f8a. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/worker.go:45

		targetID: id,
		url:      url,
	}
	if err := w.initEvents(); err != nil {
		return nil, err
	}

	return &w, nil
}

func (w *Worker) initEvents() error {
	actions := []Action{
		log.Enable(),
		network.Enable(),
		runtime.RunIfWaitingForDebugger(),
	}
	for _, action := range actions {
		if err := action.Do(cdp.WithExecutor(w.ctx, w.session)); err != nil {
			return fmt.Errorf("protocol error while initializing worker %T: %w", action, err)
		}
	}
	return nil
}

// URL returns the URL of the web worker.
func (w *Worker) URL() string {
	return w.url
}

View on GitHub (pinned to 01ffac6f24)