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

Error, Create chrome instance: timeout waiting for initial target #1

Open
khigor777 opened this issue Oct 29, 2017 · 6 comments
Open

Comments

@khigor777
Copy link

Thanks, for your tool.
When I try run cmd with headless: web2image -s=100 -w -d -c "div.weather-today" "https://weather.rambler.ru/v-bryanske/" result.png
I've got an error : [web2image] Error, Create chrome instance: timeout waiting for initial target
But without headless, it's ok.
Any help?

@suntong
Copy link
Owner

suntong commented Oct 29, 2017

web2image is just a very thin wrapper to github.com/knq/chromedp --
https://github.com/suntong/web2image/blob/master/cdp-screenshot.go#L63-L68

so please direct any chromedp related question there, with a simple demo code.

To be absolutely honest, I didn't get the headless working either, but documented so only that I can spend less words explaining chromedp -- the web2image is the first useful tool that I build on top of https://github.com/go-easygen/wireframe go wireframe framework. I.e., the web2image is more to showcase wireframe than chromedp. That being said, if you find the setup of web2image on headless chromedp wrong, which I did according to the limited doc, please kindly send in a PR.

Thanks

@suntong
Copy link
Owner

suntong commented Oct 29, 2017

BTW, to get web2image work the way you show it, github.com/mkideal/cli need to be patched with my pending PR. How did you make it work? I'm just curious.

@khigor777
Copy link
Author

khigor777 commented Oct 30, 2017

Here is my code. When I add -d, i get an error [web2image] Error, Create chrome instance: timeout waiting for initial target. All other params works greate.

import (
	"os/exec"
	"fmt"
)

func GetPageImg() {
	r := exec.Command(
		"exec/web2image",
		"-c", "div.weather-today",
		"https://weather.rambler.ru/v-bryanske/", "result.png")
	res, _ := r.Output()
	fmt.Println(string(res))

}

@suntong
Copy link
Owner

suntong commented Oct 31, 2017

Oh, I never imagined that you use web2image like this. If you are using your own go code, why not directly call chromedp, or copy web2image and build you code on top of it?

I know you are trying to say web2image is failing, but what I am saying is that, I didn't get headless working either. if you need help on chromedp headless. you need to raise your issue there -- https://github.com/knq/chromedp/issues, not here.

@khigor777
Copy link
Author

khigor777 commented Oct 31, 2017

Thanks a lot for your help. I'll follow your advice. I think sleep flag in web2image doesn't work that's why headless got error. I have tried to do like that.
In chromedp:

cdp.Sleep(2 * time.Second), // wait for animation to finish
cdp.Screenshot(`.banner-section.third-section`, &buf, cdp.ByQuery),

@suntong
Copy link
Owner

suntong commented Oct 31, 2017

Oh, thanks for spotting that.

The default for -s, --sleep is "3s", which means 3 seconds. If your above code works, then try web2image without the -s, --sleep parameter.

If you need to wait longer, say 8 seconds, use

web2image -s 8s ...

I.e., that "s" is necessary for time.ParseDuration to work

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