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

Screenshot in Emulate error #1034

Open
8763232 opened this issue Apr 2, 2024 · 3 comments
Open

Screenshot in Emulate error #1034

8763232 opened this issue Apr 2, 2024 · 3 comments
Labels
enhance New feature or request

Comments

@8763232
Copy link

8763232 commented Apr 2, 2024

// Screenshot of the area of the element
func (el *Element) Screenshot(format proto.PageCaptureScreenshotFormat, quality int) ([]byte, error) {
	err := el.ScrollIntoView()
	if err != nil {
		return nil, err
	}

	opts := &proto.PageCaptureScreenshot{
		Quality: gson.Int(quality),
		Format:  format,
	}
        //page full Screenshot   Notice :The device resolution is inconsistent with the display resolution
	bin, err := el.page.Context(el.ctx).Screenshot(false, opts)    
	if err != nil {
		return nil, err
	}

	// so that it won't clip the css-transformed element
	shape, err := el.Shape()
	if err != nil {
		return nil, err
	}

	box := shape.Box()   // get el box 

	// TODO: proto.PageCaptureScreenshot has a Clip option, but it's buggy, so now we do in Go.
        // cut the Screenshot ,but this box x/y, Width/Height are inconsistent with the resolution. Will cause screenshot error
       //   window.devicePixelRatio  is not 1,in Emulate that is 3
	return utils.CropImage(bin, quality,  
		int(box.X),
		int(box.Y),
		int(box.Width),
		int(box.Height),
	)
}

Rod Version: v0.114.6

Need to recalculate coordinates to take screenshot correctly

@8763232 8763232 added the enhance New feature or request label Apr 2, 2024
Copy link

github-actions bot commented Apr 2, 2024

Please fix the format of your markdown:

37 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]

generated by check-issue

@8763232
Copy link
Author

8763232 commented Apr 2, 2024

        res, err := el.Eval(`() => window.devicePixelRatio`)
	if err != nil {
		return nil, err
	}
	devicePixelRatio, _ := strconv.Atoi(res.Value.Str())
	
	box := shape.Box()
	// TODO: proto.PageCaptureScreenshot has a Clip option, but it's buggy, so now we do in Go.
	return CropImage(bin, quality,
		int(box.X)*devicePixelRatio,
		int(box.Y)*devicePixelRatio,
		int(box.Width)*devicePixelRatio,
		int(box.Height)*devicePixelRatio,
	)

@ysmood
Copy link
Collaborator

ysmood commented Apr 17, 2024

Could you create a test case to reproduce it?

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

No branches or pull requests

2 participants