From 32814c4796fd090755b4416beb5475dc0f8dddba Mon Sep 17 00:00:00 2001 From: juanatsap Date: Thu, 20 Nov 2025 13:56:29 +0000 Subject: [PATCH] fix: Use proper chromedp options for no-sandbox mode - Replace chromedp.Flag() with chromedp.NoSandbox - Replace chromedp.Flag() with chromedp.DisableGPU - Apply fix to both GenerateFromURL and GenerateFromURLWithOptions - Fixes Ubuntu 23.10+ AppArmor sandbox restrictions The chromedp.Flag() method wasn't properly disabling the sandbox, causing Chrome to crash with 'No usable sandbox!' fatal error in CI. --- internal/pdf/generator.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/pdf/generator.go b/internal/pdf/generator.go index 09e7200..e46eb90 100644 --- a/internal/pdf/generator.go +++ b/internal/pdf/generator.go @@ -34,10 +34,8 @@ func (g *Generator) GenerateFromURL(ctx context.Context, url string) ([]byte, er // 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), + chromedp.NoSandbox, + chromedp.DisableGPU, ) // Create exec allocator with custom options @@ -114,8 +112,18 @@ func (g *Generator) GenerateFromURLWithOptions(ctx context.Context, url string, ctx, cancel := context.WithTimeout(ctx, g.timeout) defer cancel() + // Create chromedp options for headless mode (especially for CI environments) + opts := append(chromedp.DefaultExecAllocatorOptions[:], + chromedp.NoSandbox, + chromedp.DisableGPU, + ) + + // Create exec allocator with custom options + execCtx, execCancel := chromedp.NewExecAllocator(ctx, opts...) + defer execCancel() + // Create chromedp context - allocCtx, allocCancel := chromedp.NewContext(ctx) + allocCtx, allocCancel := chromedp.NewContext(execCtx) defer allocCancel() // Buffer to store PDF