{"record":{"id":"061a5a630393b13e","repo":"JuliusBrussee/caveman","slug":"start-browser-w","errorCode":null,"errorMessage":"start browser: %w","messagePattern":"start browser: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"browse/cdp.go","lineNumber":88,"sourceCode":"\t\tif !opts.Headless {\n\t\t\texecOpts = append(execOpts, chromedp.Flag(\"headless\", false))\n\t\t}\n\t\tallocCtx, allocCancel = chromedp.NewExecAllocator(parent, execOpts...)\n\t}\n\tvar ctx context.Context\n\tvar cancel context.CancelFunc\n\tif opts.TargetID != \"\" {\n\t\tctx, cancel = chromedp.NewContext(allocCtx, chromedp.WithTargetID(cdptarget.ID(opts.TargetID)))\n\t} else {\n\t\tctx, cancel = chromedp.NewContext(allocCtx)\n\t}\n\tif err := chromedp.Run(ctx); err != nil {\n\t\tcancel()\n\t\tallocCancel()\n\t\tif tmpProfile != \"\" {\n\t\t\t_ = os.RemoveAll(tmpProfile)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"start browser: %w\", err)\n\t}\n\treturn &CDPDriver{allocCtx: allocCtx, allocCancel: allocCancel, ctx: ctx, cancel: cancel, tmpProfile: tmpProfile}, nil\n}\n\nfunc (d *CDPDriver) Close() error {\n\tif d.cancel != nil {\n\t\td.cancel()\n\t}\n\tif d.allocCancel != nil {\n\t\td.allocCancel()\n\t}\n\tif d.tmpProfile != \"\" {\n\t\treturn os.RemoveAll(d.tmpProfile)\n\t}\n\treturn nil\n}\n\nfunc (d *CDPDriver) TargetID() string {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/browse/cdp.go#L70-L106","documentation":"NewCDPDriver allocates and starts a Chrome instance via chromedp; chromedp.Run(ctx) performs the initial browser launch and connection. If Chrome fails to launch (binary missing, flags rejected, crash) or the DevTools connection fails, the driver wraps the underlying error as 'start browser: %w' and cleans up the temp profile and contexts.","triggerScenarios":"Calling browse.NewCDPDriver when the Chrome/Chromium executable cannot be found or executed, the requested user-data-dir or flags are invalid, the binary crashes on startup, or the DevTools websocket endpoint cannot be reached within the allocation timeout.","commonSituations":"CI containers without Chrome installed; missing shared libraries (libnss3, libatk) in minimal Docker images; running as root without --no-sandbox; running headless=false on a headless server; stale or unwritable temp profile directory; version mismatch between chromedp and the installed Chrome.","solutions":["Read the wrapped cause (errors.Unwrap / %v) to see the real launch failure and fix it — usually 'exec: chromium: executable file not found' or a missing shared library","Ensure a Chrome/Chromium binary is installed and either on PATH or explicitly configured (chromedp's executor options / executable path)","In Docker, install chromium and its dependencies (or use a chrome-enabled base image) and pass --no-sandbox when running as root","Ensure the temp profile directory is writable and the environment can open DevTools ports (not blocked by sandbox/seccomp policies)"],"exampleFix":"// before\ndriver, err := browse.NewCDPDriver(ctx) // fails in bare container\n// after\n// Dockerfile: apt-get install -y chromium && export CHROME_PATH=/usr/bin/chromium\n// or ensure the driver locates the binary before retrying\nif _, err := exec.LookPath(\"chromium\"); err != nil {\n    return fmt.Errorf(\"chrome not installed: %w\", err)\n}\ndriver, err := browse.NewCDPDriver(ctx)","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"chromium\"); err != nil {\n\treturn fmt.Errorf(\"chrome binary unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"driver, err := browse.NewCDPDriver(ctx)\nif err != nil {\n\tvar startErr error\n\tif strings.HasPrefix(err.Error(), \"start browser:\") {\n\t\t// inspect wrapped cause, ensure chrome installed/sandbox flags correct, retry once\n\t\tstartErr = err\n\t}\n\treturn startErr\n}","preventionTips":["Install Chrome/Chromium and required shared libraries in every deployment image","Use --no-sandbox when running as root in containers","Verify the browser launches in CI with the same flags you use in production","Keep chromedp and Chrome versions reasonably current"],"tags":["go","browser","chromedp","cdp","launch-failure"],"backgroundTag":"browser-launch-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}