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

Blank screenshots #864

Closed
marcelblijleven opened this issue Jun 17, 2021 · 3 comments
Closed

Blank screenshots #864

marcelblijleven opened this issue Jun 17, 2021 · 3 comments

Comments

@marcelblijleven
Copy link

What versions are you running?

$ go list -m github.com/chromedp/chromedp
github.com/chromedp/chromedp
$ google-chrome --version
91.0.4472.106
$ go version
go version go1.15.2 darwin/amd64

What did you do? Include clear steps.

func Demo() {
	allocContext, cancel := chromedp.NewExecAllocator(context.Background(), append(
		chromedp.DefaultExecAllocatorOptions[:],
		chromedp.Flag("headless", false),
		chromedp.WindowSize(1920, 1080),
	)...)
	ctx, cancel := browser.NewContext(allocContext)
	defer cancel()

	var tasks chromedp.Tasks
	var buf []byte
	tasks = append(tasks,
		chromedp.Navigate("https://github.com/chromedp"),
		chromedp.Click("[title='chromedp']"),
		chromedp.Screenshot("#readme h1", &buf, chromedp.ByQuery),
	)

	if err := chromedp.Run(ctx, tasks); err != nil {
		panic(err)
	}

	r := bytes.NewReader(buf)
	img, err := png.Decode(r)

	if err != nil {
		panic(err)
	}

	f, err := os.Create("example.png")

	if err != nil {
		panic(err)
	}

	if err = png.Encode(f, img); err != nil {
		panic(err)
	}
}

What did you expect to see?

A screenshot of the h1 inside the README section of the chromedp github actions page

What did you see instead?

A 'blank' screenshot with just the background color. On different websites with a white background, the screenshot will be white

example

@ZekeLu
Copy link
Member

ZekeLu commented Jun 17, 2021

I just sent a PR (#863) to fix some issues of the screenshot actions. Can you confirm whether this issue has been addressed by that PR? Thanks!

@marcelblijleven
Copy link
Author

Can confirm your PR fixes the issue! Had to upgrade to Go 1.16 though, but that's no big deal for me

@ZekeLu
Copy link
Member

ZekeLu commented Jun 17, 2021

Yes, it uses //go:embed (which was added in Go 1.6) to make it easy to manage the javascript files. The plan is to drop support for Go 1.15 once Go 1.17 is released.
Since there are other isssues tracking the same issue, I'm going to close this one. Thank you!

@ZekeLu ZekeLu closed this as completed Jun 17, 2021
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