From d2ee1074fc3da1df18293045458f48add145de90 Mon Sep 17 00:00:00 2001 From: juanatsap Date: Thu, 20 Nov 2025 13:49:46 +0000 Subject: [PATCH] fix: Add headless Chrome configuration for CI environment - Configure chromedp with headless mode and CI-friendly flags - Add --no-sandbox flag (required for Docker/CI environments) - Add --disable-gpu and --disable-dev-shm-usage for stability - Use NewExecAllocator with DefaultExecAllocatorOptions This fixes 'chrome failed to start' errors in GitHub Actions CI where Chrome needs to run without a display and with relaxed sandbox restrictions. --- internal/pdf/generator.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/pdf/generator.go b/internal/pdf/generator.go index 53e505b..09e7200 100644 --- a/internal/pdf/generator.go +++ b/internal/pdf/generator.go @@ -32,10 +32,25 @@ func (g *Generator) GenerateFromURL(ctx context.Context, url string) ([]byte, er ctx, cancel := context.WithTimeout(ctx, g.timeout) defer cancel() - // Create chromedp context - allocCtx, allocCancel := chromedp.NewContext(ctx) + // Create chromedp options for headless mode (especially for CI environments) + opts := append(chromedp.DefaultExecAllocatorOptions[:], + chromedp.Flag("headless", true), + chromedp.Flag("disable-gpu", true), + chromedp.Flag("no-sandbox", true), + chromedp.Flag("disable-dev-shm-usage", true), + ) + + // Create exec allocator with custom options + allocCtx, allocCancel := chromedp.NewExecAllocator(ctx, opts...) defer allocCancel() + // Create chromedp context + browserCtx, browserCancel := chromedp.NewContext(allocCtx) + defer browserCancel() + + // Use browserCtx instead of allocCtx for chromedp operations + allocCtx = browserCtx + // Buffer to store PDF var pdfBuffer []byte