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.
This commit is contained in:
juanatsap
2025-11-20 13:56:29 +00:00
parent c6b2631989
commit 32814c4796
+13 -5
View File
@@ -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) // Create chromedp options for headless mode (especially for CI environments)
opts := append(chromedp.DefaultExecAllocatorOptions[:], opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("headless", true), chromedp.NoSandbox,
chromedp.Flag("disable-gpu", true), chromedp.DisableGPU,
chromedp.Flag("no-sandbox", true),
chromedp.Flag("disable-dev-shm-usage", true),
) )
// Create exec allocator with custom options // 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) ctx, cancel := context.WithTimeout(ctx, g.timeout)
defer cancel() 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 // Create chromedp context
allocCtx, allocCancel := chromedp.NewContext(ctx) allocCtx, allocCancel := chromedp.NewContext(execCtx)
defer allocCancel() defer allocCancel()
// Buffer to store PDF // Buffer to store PDF