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

make the screenshot actions act the same as Chrome commands #863

Merged
merged 8 commits into from Jul 12, 2021

Conversation

ZekeLu
Copy link
Member

@ZekeLu ZekeLu commented Jun 17, 2021

This PR addresses some issues by making the screenshot actions act the same as the family of capture screenshot commands provided by Chrome. And it copies some of the unit tests from https://github.com/puppeteer/puppeteer/ too.

Here is the details:

  1. get node's position relative to its document (fixes Screenshoot of elements in scrolled page doesn't work properly #844)
  2. compression quality is just available for jpeg (fixes the bug that setting quality without specifying the image format)
  3. make it act the same as Chrome commands (main change: set captureBeyondViewport: true, fixes Blank image in non-headless mode for fullscreen screenshot #859)
  4. extract screenshot.go (put all the screenshot actions together)
  5. add more unit tests (most of them are copied from puppeteer) and compare images with pixelmatch

Note: this PR uses CallFunctionOn and //go:embed, so it can not be merged until #852 is merged. I will change the state to Draft.

Update: The //go:embed changes has been removed so that we can release this PR first.

Before this change, it's relative to the viewport. So it will get
the wrong position if the page scrolls.

Fixes chromedp#844.
Here is the list of actions and the coresponding commands:

- FullScreenshot: Capture full size screenshot
- CaptureScreenshot: Capture screenshot
- Screenshot: Capture node screenshot
Reasons:

- CaptureScreenshot has nothing to do with navigation, so it's ok
to move it out of the nav.go file.
- FullScreenshot does not use emulate action any more, so it's ok
to move it out of the emulate.go file.
- query.go is a little big and I'm planning to add more unit test
for the screenshot feature, so it's better to move the feature to
another file.

This change is a simple refactor, and does not change any behavior
of the source code.
github.com/orisano/pixelmatch is a go port of pixelmatch,
which is used by puppeteer to compare images.
This unit test is copied from puppeteer:
- testdata/grid.html
- testdata/digits/[0-9].png
- testdata/screenshots/grid-fullpage.png
This unit test is copied from puppeteer:
- testdata/screenshots/sanity.png
This unit test is copied from puppeteer.

The Screenshot action is updated to handle fractional dimensions
properly too.
@ZekeLu ZekeLu marked this pull request as ready for review July 12, 2021 17:31
@ZekeLu ZekeLu merged commit a3b306a into chromedp:master Jul 12, 2021
@ZekeLu ZekeLu deleted the screenshot branch July 12, 2021 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant