{"record":{"id":"935f974d644906d2","repo":"d2lang/d2","slug":"failed-to-run-playwright-w","errorCode":null,"errorMessage":"failed to run Playwright: %w","messagePattern":"failed to run Playwright: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/png/png.go","lineNumber":92,"sourceCode":"\treturn Playwright{\n\t\tPW:      pw,\n\t\tBrowser: browser,\n\t\tPage:    page,\n\t}, nil\n}\n\nfunc InitPlaywright() (Playwright, error) {\n\terr := playwright.Install(&playwright.RunOptions{\n\t\tVerbose:  false,\n\t\tBrowsers: []string{\"chromium\"},\n\t})\n\tif err != nil {\n\t\treturn Playwright{}, fmt.Errorf(\"failed to install Playwright: %w\", err)\n\t}\n\n\tpw, err := playwright.Run()\n\tif err != nil {\n\t\treturn Playwright{}, fmt.Errorf(\"failed to run Playwright: %w\", err)\n\t}\n\treturn startPlaywright(pw)\n}\n\nfunc InitPlaywrightWithPrompt() (Playwright, error) {\n\tif os.Getenv(\"CI\") != \"\" {\n\t\treturn InitPlaywright()\n\t}\n\n\t// Just try running first. This only works if drivers and browsers are already installed\n\tpw, err := playwright.Run()\n\tif err == nil {\n\t\treturn startPlaywright(pw)\n\t}\n\n\tfmt.Print(\"D2 needs to install Chromium v149.0.7827.55 to render non-SVG images. Continue? (y/N): \")\n\treader := bufio.NewReader(os.Stdin)\n\tresponse, err := reader.ReadString('\\n')","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/png/png.go#L74-L110","documentation":"InitPlaywright wraps any error from playwright.Run() (starting the Playwright driver process after installation) with this message. Installation succeeded but launching the driver/browser runtime failed; the cause is preserved via %w.","triggerScenarios":"playwright.Run() fails because the installed driver binary cannot execute: unsupported/missing shared libraries for Chromium, wrong architecture, exec permissions, or driver/version mismatch between the playwright-go library and downloaded browsers.","commonSituations":"Minimal Docker images (e.g. alpine, scratch-based) missing libc/libnss3 dependencies; running as non-root without deps; macOS/Linux architecture mismatch; antivirus blocking the driver executable.","solutions":["Install OS dependencies required by Chromium (libnss3, libatk, libgbm, fonts, etc.)","Verify the platform/arch is supported and the driver binary is executable","Check the wrapped cause (%w) for the exact launch failure","Use a Playwright-ready base image or install deps via the official dependency script","Run outside restricted sandboxes (seccomp/apparmor) that block the driver"],"exampleFix":"// before, in a minimal container\npw, _ := InitPlaywright() // fails to run driver\n// after (Dockerfile)\n// RUN apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2\npw, err := InitPlaywright()\nif err != nil { log.Fatal(err) }","handlingStrategy":"try-catch","validationCode":"if runtime.GOOS == \"linux\" { if _, err := os.Stat(\"/usr/lib/x86_64-linux-gnu/libnss3.so\"); err != nil { log.Fatal(\"missing chromium deps\") } }","typeGuard":"func isLaunchFailure(err error) bool { return strings.Contains(err.Error(), \"failed to run Playwright\") }","tryCatchPattern":"pw, err := InitPlaywright()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to run Playwright\") {\n        log.Fatalf(\"chromium deps missing? %v\", errors.Unwrap(err))\n    }\n    return err\n}","preventionTips":["Use Playwright-official base images with deps preinstalled","Pin playwright-go version to match browser builds","Run ldd on the driver binary in minimal containers","Avoid running under restrictive seccomp profiles"],"tags":["go","playwright","chromium","runtime","dependencies"],"backgroundTag":"browser-launch-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}