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

run chromedp on Linux #1108

Closed
fandazhou123 opened this issue Jul 7, 2022 · 3 comments
Closed

run chromedp on Linux #1108

fandazhou123 opened this issue Jul 7, 2022 · 3 comments

Comments

@fandazhou123
Copy link

What versions are you running?

$ go list -m github.com/chromedp/chromedp
chromedp v0.8.2
$ google-chrome --version
103.0.5060.66
$ go version
go 1.16

What did you do? Include clear steps.

docker pull chromedp/headless-shell:latest
docker run -d -p 9222:9222 --rm --name headless-shell chromedp/headless-shell 

What did you expect to see?

I want to run Chromedp on Linux, so I download the Docker image of Chromedp/Headless-shell, but after installing Chrome, I get an error when running my program: exec: "google-chrome": executable file not found in $PATH.
I think my application did not find Headless-shell Chrome. How can I set my program to find it?

What did you see instead?

image
image

@ZekeLu
Copy link
Member

ZekeLu commented Jul 7, 2022

Please read the doc to understand the difference between the ExecAllocator and the RemoteAllocator. In this case, you need to use the RemoteAllocator. See this comment for an example: #817 (comment)

@fandazhou123
Copy link
Author

	ctx, cancel := chromedp.NewRemoteAllocator(context.Background(), "https://baidu.com")
	ctx, cancel = context.WithTimeout(ctx, 30*time.Second)
	ctx, cancel = chromedp.NewContext(
		ctx,
		chromedp.WithLogf(log.Printf),
	)
	defer cancel()
	var htmlContent string
	var imgBuf []byte
	err := chromedp.Run(ctx,
		chromedp.Navigate(url),
		chromedp.Sleep(5 * time.Second),
		chromedp.FullScreenshot(&imgBuf,100),
	)

I'm not sure that RemoteAllocator is the key of this issue, I try it and get an error: could not dial "https://www.baidu.com": unexpected websocket scheme: "https"

@ZekeLu
Copy link
Member

ZekeLu commented Jul 8, 2022

docker run -d -p 9222:9222 --rm --name headless-shell chromedp/headless-shell

RemtoeAllocator connects to the running browser (which is chromedp/headless-shell in your case).

-	ctx, cancel := chromedp.NewRemoteAllocator(context.Background(), "https://baidu.com")
+	ctx, cancel := chromedp.NewRemoteAllocator(context.Background(), "ws://localhost:9222/")
	ctx, cancel = context.WithTimeout(ctx, 30*time.Second)
	ctx, cancel = chromedp.NewContext(
		ctx,
		chromedp.WithLogf(log.Printf),
	)
	defer cancel()
	var htmlContent string
	var imgBuf []byte
	err := chromedp.Run(ctx,
		chromedp.Navigate(url),
		chromedp.Sleep(5 * time.Second),
		chromedp.FullScreenshot(&imgBuf,100),
	)

@ZekeLu ZekeLu closed this as completed Jul 8, 2022
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