d2lang/d2 · error
failed to start new Playwright page: %w
Error message
failed to start new Playwright page: %w
What it means
startPlaywright finishes by opening a new page inside the browser context. If context.NewPage fails, this error wraps the driver's message. This is the last step of Playwright setup; failing here means the browser and context exist but no usable tab could be opened.
Source
Thrown at lib/png/png.go:72
"--disable-dev-shm-usage", // Prevents /dev/shm issues
"--disable-background-timer-throttling", // Prevents CPU throttling
"--disable-backgrounding-occluded-windows", // Keeps rendering active
"--disable-features=TranslateUI", // Reduces feature overhead
"--disable-ipc-flooding-protection", // Removes IPC limits
},
})
if err != nil {
return Playwright{}, fmt.Errorf("failed to launch Chromium: %w", err)
}
context, err := browser.NewContext(playwright.BrowserNewContextOptions{
DeviceScaleFactor: playwright.Float(2.0),
})
if err != nil {
return Playwright{}, fmt.Errorf("failed to start new Playwright browser context: %w", err)
}
page, err := context.NewPage()
if err != nil {
return Playwright{}, fmt.Errorf("failed to start new Playwright page: %w", err)
}
return Playwright{
PW: pw,
Browser: browser,
Page: page,
}, nil
}
func InitPlaywright() (Playwright, error) {
err := playwright.Install(&playwright.RunOptions{
Verbose: false,
Browsers: []string{"chromium"},
})
if err != nil {
return Playwright{}, fmt.Errorf("failed to install Playwright: %w", err)
}
pw, err := playwright.Run()View on GitHub (pinned to 0d69dca6f5)
Solutions
- Verify no concurrent RestartBrowser/Cleanup is racing the setup; serialize lifecycle access with a mutex
- Check Chromium process count/pages in flight; close stale pages or restart the browser when targets are exhausted
- Inspect the wrapped driver error for a crash message and address resource limits (memory, /dev/shm)
- Retry the whole startPlaywright sequence once — transient driver hiccups often clear on retry
Defensive patterns
Strategy: retry
Try / catch
pw, err := startPlaywright(p)
if err != nil {
if strings.Contains(err.Error(), "Playwright page") {
// close stale pages / restart browser, then retry startPlaywright once
}
} Prevention
- Limit concurrent open pages; close pages after each capture
- Guard against concurrent Close/RestartBrowser during setup with a mutex
- Bound page accumulation in long-lived workers; recycle the browser periodically
- Watch Chromium resource limits (memory, file descriptors) in production
When it happens
Trigger: context.NewPage returns a driver error — context/browser closed concurrently, browser crashed between NewContext and NewPage, or too many open pages/targets exhausting resources.
Common situations: Other goroutines closing the browser/page while startPlaywright runs; long-lived workers accumulating pages until Chromium refuses new targets; crashes from resource exhaustion in shared environments.
Related errors
- failed to close Playwright browser: %w
- failed to launch Chromium: %w
- failed to start new Playwright browser context: %w
- failed to install Playwright: %w
- failed to run Playwright: %w
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/056d977a24ccd9bf.
Report an issue: GitHub.