{"record":{"id":"b531a441f3e9d3d2","repo":"d2lang/d2","slug":"failed-to-start-new-playwright-browser-context-w","errorCode":null,"errorMessage":"failed to start new Playwright browser context: %w","messagePattern":"failed to start new Playwright browser context: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/png/png.go","lineNumber":68,"sourceCode":"\t// Optimizations for a very tightly scoped Playwright instance\n\tbrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{\n\t\tArgs: []string{\n\t\t\t\"--no-sandbox\",                             // Removes security overhead\n\t\t\t\"--disable-dev-shm-usage\",                  // Prevents /dev/shm issues\n\t\t\t\"--disable-background-timer-throttling\",    // Prevents CPU throttling\n\t\t\t\"--disable-backgrounding-occluded-windows\", // Keeps rendering active\n\t\t\t\"--disable-features=TranslateUI\",           // Reduces feature overhead\n\t\t\t\"--disable-ipc-flooding-protection\",        // Removes IPC limits\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn Playwright{}, fmt.Errorf(\"failed to launch Chromium: %w\", err)\n\t}\n\tcontext, err := browser.NewContext(playwright.BrowserNewContextOptions{\n\t\tDeviceScaleFactor: playwright.Float(2.0),\n\t})\n\tif err != nil {\n\t\treturn Playwright{}, fmt.Errorf(\"failed to start new Playwright browser context: %w\", err)\n\t}\n\tpage, err := context.NewPage()\n\tif err != nil {\n\t\treturn Playwright{}, fmt.Errorf(\"failed to start new Playwright page: %w\", err)\n\t}\n\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 {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/png/png.go#L50-L86","documentation":"After launching Chromium, startPlaywright creates an isolated browser context with a device scale factor of 2.0. If browser.NewContext fails, this error wraps the driver's message. Without a context, no page can be created, so rendering cannot proceed.","triggerScenarios":"browser.NewContext returns an error from the driver — typically the browser process died immediately after launch (crash, OOM), or the driver connection was lost between Launch and NewContext.","commonSituations":"Chromium crashing seconds after startup due to limited /dev/shm or memory in containers; driver instability right after launch; invalid option combinations rejected by the driver.","solutions":["Check the wrapped driver error and Chromium crash logs; fix the crash cause (raise memory/shm limits, adjust flags)","Retry via RestartBrowser — transient post-launch crashes are common under resource pressure","Ensure Launch succeeded against a healthy browser (verify with playwright doctor-equivalent / manual launch)","Keep playwright-go and browser builds in sync; reinstall browsers if versions drifted"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"pw, err := startPlaywright(p)\nif err != nil {\n\tif strings.Contains(err.Error(), \"browser context\") {\n\t\ttime.Sleep(retryDelay)\n\t\tpw, err = startPlaywright(p) // transient crash right after launch\n\t}\n}","preventionTips":["Provision sufficient memory and /dev/shm for Chromium","Serialize lifecycle operations to avoid racing context creation with Close","Investigate wrapped driver errors for crash signatures","Keep driver/browser versions matched"],"tags":["playwright","browser-context","chromium","go"],"backgroundTag":"browser-context-creation-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}