{"record":{"id":"ddeae1cf52a93272","repo":"d2lang/d2","slug":"issue-encountered-with-png-exporter-w","errorCode":null,"errorMessage":"issue encountered with PNG exporter: %w","messagePattern":"issue encountered with PNG exporter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2cli/watch.go","lineNumber":430,"sourceCode":"\nfunc (w *watcher) compileLoop(ctx context.Context) error {\n\tfirstCompile := true\n\tfor {\n\t\tselect {\n\t\tcase <-w.compileCh:\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\t}\n\n\t\trecompiledPrefix := \"\"\n\t\tif !firstCompile {\n\t\t\trecompiledPrefix = \"re\"\n\t\t}\n\n\t\tif (filepath.Ext(w.outputPath) == \".png\" || filepath.Ext(w.outputPath) == \".pdf\") && !w.pw.Browser.IsConnected() {\n\t\t\tnewPW, err := w.pw.RestartBrowser()\n\t\t\tif err != nil {\n\t\t\t\tbroadcastErr := fmt.Errorf(\"issue encountered with PNG exporter: %w\", err)\n\t\t\t\tw.ms.Log.Error.Print(broadcastErr)\n\t\t\t\tw.broadcast(&compileResult{\n\t\t\t\t\tErr: broadcastErr.Error(),\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tw.pw = newPW\n\t\t}\n\n\t\tfs := trackedFS{}\n\t\tw.boardpathMu.Lock()\n\t\tvar boardPath []string\n\t\tif w.boardPath != \"\" {\n\t\t\tboardPath = strings.Split(w.boardPath, string(os.PathSeparator))\n\t\t}\n\t\tsvg, _, err := compile(ctx, w.ms, w.plugins, &fs, w.layout, w.renderOpts, w.fontFamily, w.monoFontFamily, w.animateInterval, w.inputPath, w.outputPath, boardPath, false, w.bundle, w.forceAppendix, w.pw.Browser, w.outputFormat, w.asciiMode)\n\t\tw.boardpathMu.Unlock()\n\t\terrs := \"\"","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2cli/watch.go#L412-L448","documentation":"In watch mode, when the output is a PNG or PDF, compilation uses a headless browser managed by Playwright. If the browser is disconnected, watch tries RestartBrowser(); if that fails, the error is wrapped as \"issue encountered with PNG exporter\" and broadcast to connected viewers.","triggerScenarios":"compileLoop detects output extension .png or .pdf with w.pw.Browser.IsConnected() == false, and the attempted RestartBrowser() returns an error (browser binary missing, failed launch, display/sandbox issues).","commonSituations":"Playwright/Chromium not installed or downloaded, running in a container without required shared libraries, headless environment missing --no-sandbox, browser process crashed (OOM) during a long watch session.","solutions":["Install/reinstall the Playwright browser binaries that D2 relies on","Run the container/host with required Chromium dependencies (or --no-sandbox where appropriate)","Restart the watch session to get a fresh browser process"],"exampleFix":"// before\nd2 file.d2 --watch --format png   # chromium missing\n// after\n# install browser deps first, then\nd2 file.d2 --watch --format png","handlingStrategy":"fallback","validationCode":"// before watching:\nif _, err := exec.LookPath(browserBinary); err != nil {\n\t// install Playwright browser dependencies first\n}","typeGuard":null,"tryCatchPattern":"if result.Err != \"\" && strings.Contains(result.Err, \"PNG exporter\") {\n\t// restart watch or switch output format to svg\n}","preventionTips":["Pre-install Playwright/Chromium before watch sessions","Ensure container has browser shared libraries","For long watch sessions, restart periodically to avoid crashed browser processes"],"tags":["watch-mode","playwright","browser","png"],"backgroundTag":"browser-launch-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}