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.
This commit is contained in:
@@ -32,10 +32,25 @@ func (g *Generator) GenerateFromURL(ctx context.Context, url string) ([]byte, er
|
|||||||
ctx, cancel := context.WithTimeout(ctx, g.timeout)
|
ctx, cancel := context.WithTimeout(ctx, g.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Create chromedp context
|
// Create chromedp options for headless mode (especially for CI environments)
|
||||||
allocCtx, allocCancel := chromedp.NewContext(ctx)
|
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()
|
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
|
// Buffer to store PDF
|
||||||
var pdfBuffer []byte
|
var pdfBuffer []byte
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user