{"record":{"id":"df6893d822080f8a","repo":"grafana/k6","slug":"protocol-error-while-initializing-worker-t-w","errorCode":null,"errorMessage":"protocol error while initializing worker %T: %w","messagePattern":"protocol error while initializing worker %T: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/worker.go","lineNumber":45,"sourceCode":"\t\ttargetID: id,\n\t\turl:      url,\n\t}\n\tif err := w.initEvents(); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &w, nil\n}\n\nfunc (w *Worker) initEvents() error {\n\tactions := []Action{\n\t\tlog.Enable(),\n\t\tnetwork.Enable(),\n\t\truntime.RunIfWaitingForDebugger(),\n\t}\n\tfor _, action := range actions {\n\t\tif err := action.Do(cdp.WithExecutor(w.ctx, w.session)); err != nil {\n\t\t\treturn fmt.Errorf(\"protocol error while initializing worker %T: %w\", action, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// URL returns the URL of the web worker.\nfunc (w *Worker) URL() string {\n\treturn w.url\n}\n","sourceCodeStart":27,"sourceCodeEnd":55,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/worker.go#L27-L55","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/worker.go:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the web worker script exists and stays alive long enough to be attached","Retry creating the worker handle if the worker was racing with termination","Check browser flags/permissions that might block worker instrumentation","Inspect the wrapped CDP error to identify which of log.Enable/network.Enable/RunIfWaitingForDebugger failed and why"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}