Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chromedp error "google-chrome": executable file not found in $PATH on lambda #1435

Open
oluwapaso opened this issue Feb 8, 2024 · 1 comment

Comments

@oluwapaso
Copy link

My dockerfile

FROM golang:1.22 as build

ENV CGO_ENABLED=0

WORKDIR /app

Install CA certificates

RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN mkdir -p /opt/extensions

RUN go build -o bootstrap

FROM chromedp/headless-shell:latest

COPY --from=build /app/bootstrap .

ENTRYPOINT ["./bootstrap"]

my golang code

func handler(event LambdaEvent) (events.APIGatewayProxyResponse, error) {

fmt.Println("In handler - 21")
// Create a new context
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()

// Set up options for the browser session
opts := append(chromedp.DefaultExecAllocatorOptions[:],
	chromedp.Headless,
	chromedp.NoSandbox,
	chromedp.NoFirstRun,
	chromedp.DisableGPU,
	chromedp.Flag("ignore-certificate-errors", true),
	chromedp.Flag("disable-setuid-sandbox", true),
	chromedp.Flag("disable-dev-shm-usage", true),
	chromedp.Flag("single-process", true),
	chromedp.Flag("no-zygote", true),
)

// Create a new context with the specified options
ctx, cancel = chromedp.NewExecAllocator(ctx, opts...)
defer cancel()

// Create a new browser session
ctx, cancel = chromedp.NewContext(ctx)
defer cancel()

// Set a timeout for the actions
ctx, cancel = context.WithTimeout(ctx, 40*time.Second)
defer cancel() 

// Navigate to a webpage
url := "https://www.mywesite.com"
if err := chromedp.Run(ctx,
	chromedp.Navigate(url),
	chromedp.WaitVisible("#colophon", chromedp.ByQuery),
); err != nil {
	fmt.Println("Failed to navigate:", err)
}

// Extract the title of the page
var title string
if err := chromedp.Run(ctx, chromedp.Title(&title)); err != nil {
	fmt.Println("Failed to get title:", err)
}

fmt.Println("Page Title:", title) 

var message = event.Body
greeting := message

return events.APIGatewayProxyResponse{
	Body:       greeting,
	StatusCode: 200,
}, nil

}

AWS lambda output

START RequestId: c66d676c-a959-45f3-9664-96c8ef5897c9 Version: $LATEST
In handler - 20
Failed to navigate: exec: "google-chrome": executable file not found in $PATH
Failed to get title: exec: "google-chrome": executable file not found in $PATH
Page Title:
END RequestId: c66d676c-a959-45f3-9664-96c8ef5897c9
REPORT RequestId: c66d676c-a959-45f3-9664-96c8ef5897c9 Duration: 210.54 ms Billed Duration: 300 ms Memory Size: 503 MB Max Memory Used: 32 MB Init Duration: 89.26 ms

@jameshulse
Copy link

I had the same issue, and the fix was to ensure the headless-chrome folder is on the path e.g ENV PATH /headless-shell:$PATH in your dockerfile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants