d2lang/d2 · error

failed to run Playwright: %w

Error message

failed to run Playwright: %w

What it means

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.

Source

Thrown at lib/png/png.go:92

	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()
	if err != nil {
		return Playwright{}, fmt.Errorf("failed to run Playwright: %w", err)
	}
	return startPlaywright(pw)
}

func InitPlaywrightWithPrompt() (Playwright, error) {
	if os.Getenv("CI") != "" {
		return InitPlaywright()
	}

	// Just try running first. This only works if drivers and browsers are already installed
	pw, err := playwright.Run()
	if err == nil {
		return startPlaywright(pw)
	}

	fmt.Print("D2 needs to install Chromium v149.0.7827.55 to render non-SVG images. Continue? (y/N): ")
	reader := bufio.NewReader(os.Stdin)
	response, err := reader.ReadString('\n')

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Install OS dependencies required by Chromium (libnss3, libatk, libgbm, fonts, etc.)
  2. Verify the platform/arch is supported and the driver binary is executable
  3. Check the wrapped cause (%w) for the exact launch failure
  4. Use a Playwright-ready base image or install deps via the official dependency script
  5. Run outside restricted sandboxes (seccomp/apparmor) that block the driver

Example fix

// before, in a minimal container
pw, _ := InitPlaywright() // fails to run driver
// after (Dockerfile)
// RUN apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2
pw, err := InitPlaywright()
if err != nil { log.Fatal(err) }
Defensive patterns

Strategy: try-catch

Validate before calling

if runtime.GOOS == "linux" { if _, err := os.Stat("/usr/lib/x86_64-linux-gnu/libnss3.so"); err != nil { log.Fatal("missing chromium deps") } }

Type guard

func isLaunchFailure(err error) bool { return strings.Contains(err.Error(), "failed to run Playwright") }

Try / catch

pw, err := InitPlaywright()
if err != nil {
    if strings.Contains(err.Error(), "failed to run Playwright") {
        log.Fatalf("chromium deps missing? %v", errors.Unwrap(err))
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/935f974d644906d2. Report an issue: GitHub.