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

[Question] Why capture whole page instead of element? #762

Open
Filipoliko opened this issue May 29, 2023 · 1 comment
Open

[Question] Why capture whole page instead of element? #762

Filipoliko opened this issue May 29, 2023 · 1 comment

Comments

@Filipoliko
Copy link

Hi everyone!
Our team has been analysing visual regression tools, that we could use for our projects and storycap/reg-suite is really standing out as a great and powerful solution full of features. You did some amazing work here and thank you for sharing it as an open-source solution!

We are thinking to migrate from our aging test solution to storycap, but there has been one missing feature and I am trying to figure out if I missed some documentation, or if there is some good reason why it is not implemented.

Is there any option to capture screenshot only for the story preview element, not the whole page? If not, are you open to PRs, or is there some reason why are you choosing not to have this option?

I ran into this feature request #506 , but I am not really sure, if it is possible to use the clip screenshot option to only capture the element. I tried playing with document.querySelector().getBoundingClientRect(), but I could not get it to work. Is there some way to do this?

@peteragarclover
Copy link

peteragarclover commented Sep 5, 2023

I ran into this issue as well. I would like to migrate to Storycap from Loki as it seems to be significantly faster, but the large screenshots make comparing changes difficult.

I'm aware of the clip option, which looks helpful, but it requires hard coded x/y/width/height.

In Loki, they have a chromeSelector option which they use to automatically determine the clip dimensions:

https://github.com/oblador/loki/blob/02c143c91b450273a8a5468b86d4a8fbd7827bc6/packages/target-chrome-core/src/create-chrome-target.js#L262-L276

In Loki you can provide chromeSelector: "body > *" which will only capture the component root elements (e.g. React root element plus any React Portals). This means the screenshot is still wide, but only as tall as the rendered component, not the entire body element.

Perhaps a similar feature could be added to Storycap? Perhaps an option, like clipSelector?

Storycap already queries the page using the Puppeteer Page API where it specifies the clip option for the screenshot call. This could be a convenient place to automatically calculate the value for clip based on a clipSelector.

// Get PNG image buffer
const rawBuffer = await this.page.screenshot({
fullPage: emittedScreenshotOptions.fullPage,
omitBackground: emittedScreenshotOptions.omitBackground,
captureBeyondViewport: emittedScreenshotOptions.captureBeyondViewport,
clip: emittedScreenshotOptions.clip ?? undefined,

In addition to #506, mentioned above, I found a suggestion in #186 to use Jimp to post-process the images, however, using Jimp significantly increases the total build time. If the original screenshot only captured the rendered div/s, that would be really helpful.

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