GithubHelp home page GithubHelp logo

Full page screenshot? about rod HOT 8 CLOSED

go-rod avatar go-rod commented on July 18, 2024
Full page screenshot?

from rod.

Comments (8)

ysmood avatar ysmood commented on July 18, 2024 1

Let's keep this ticket open since the full-page screenshot is actually useful. I just don't have enough time to implement it. The common solution is to take multiple shots while scrolling down the page until it hits the bottom, then merge all those shots into one.

If you are interested in it, it'll be great if you can help to implement it.

from rod.

ysmood avatar ysmood commented on July 18, 2024 1

If your chrome version is too old, it doesn't support the PDF API.

The way you code it is similar to puppeteer, which changes the size of the frame. But puppeteer uses Emulation.setDeviceMetricsOverride to do it:

https://github.com/puppeteer/puppeteer/blob/caaf4d2086036d4bf201587529dd3e3b38b6f9c6/src/Page.ts#L1058-L1064

I think this kind of solution is good to have.

from rod.

ysmood avatar ysmood commented on July 18, 2024 1

To make the chrome version consistent, you can download a specific version of chrome and specified the bin location:

launcher.New().Bin("the_path_of_chrome")

Or you can check this FAQ to use docker: https://github.com/ysmood/rod#q-how-to-use-rod-with-docker

from rod.

ysmood avatar ysmood commented on July 18, 2024 1

Published v0.34.2 with the full page screenshot feature.

I changed the name to SceenshotFullPage, so that when user types Screenshot the IDE will give the user a list to choose which one to use.

Because of the retina scale bug, I have to revert the GetViewport, the safest way to do it is to store a private viewport whenever we set it, once chrome adds the API to retrieve the metrics we can optimize it.

from rod.

youshy avatar youshy commented on July 18, 2024 1

Good call!

I'll close this one for now then. If you have any more tasks or functionalities you want to implement - hit me up, happy to help :) (I'll probably learn some stuff while using the lib tho, will try to add them here as I go)

from rod.

ysmood avatar ysmood commented on July 18, 2024

How about to use page.PDF()?

from rod.

youshy avatar youshy commented on July 18, 2024

I've ended up writing this:

func UseRod(link string) {
	url := launcher.New().
		Headless(false).
		Devtools(false).
		Launch()

	browser := rod.New().
		ControlURL(url).
		Trace(false).
		Connect().
		Timeout(time.Minute)

	defer browser.Close()
	page := browser.Timeout(time.Minute).Page(link)
	wait := page.WaitRequestIdle()
	wait()
	height := page.Eval(`() => document.body.clientHeight`).String()
	heightToInt, err := strconv.ParseInt(height, 10, 64)
	if err != nil {
		log.Fatalln(err)
	}
	page.Viewport(1920, heightToInt, 1, false)
	toByte, err := page.ScreenshotE(&proto.PageCaptureScreenshot{})

	f, err := os.Create("img_2.png")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	img, _, _ := image.Decode(bytes.NewReader(toByte))
	err = png.Encode(f, img)
	if err != nil {
		log.Fatal(err)
	}
}

but will try the page.PDF() as well! My solution is a tad verbose... 😆

from rod.

youshy avatar youshy commented on July 18, 2024

Both page.PDF() and page.PDFE() returns

2020/05/19 15:37:54 {"code":-32000,"message":"PrintToPDF is not implemented","data":""}

@ysmood I'm more than happy with helping!

from rod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.