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

ElementHandle screenshot does not count padding (or add options to count the padding/margin) #1010

Closed
entrptaher opened this issue Oct 11, 2017 · 1 comment · Fixed by #1017

Comments

@entrptaher
Copy link
Contributor

entrptaher commented Oct 11, 2017

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 0.12.0-alpha
  • Platform / OS version:
  • URLs (if applicable): http://example.com

What steps will reproduce the problem?
Take screenshot using ElementHandler.

Please include code that reproduces the issue.

await page.goto("http://example.com");
const title = await page.$('h1');
const screenshot = await title.screenshot({path: "justTitle.png"});

What is the expected result?
Take screenshot of the highlighted area as from chrome. When I mean highlighted, I mean the margin/padding.

image

What happens instead?
justtitle

@ebidel
Copy link
Contributor

ebidel commented Oct 11, 2017

I've meant to file the same bug :) To screenshot just the element, it's a bit painful right now. You need to figure out the element margin and adjust theclip property accordingly.

It would be nice for us to provide an option. For now, here's a workaround that works for me:

await page.goto("http://example.com");
const title = await page.$('h1');

const styles = await page.evaluate(el => window.getComputedStyle(el), title);

const clip = Object.assign({}, await title.boundingBox());
clip.y += parseFloat(styles.marginTop) || 0;
clip.x += parseFloat(styles.marginLeft) || 0;

const screenshot = await title.screenshot({path: "tweet.png", clip});

aslushnikov pushed a commit that referenced this issue Oct 13, 2017
…er in element.boxModel (#1017)

This patch starts relying on border quad to compute element's bounding box.

Fixes #1010
ithinkihaveacat pushed a commit to ithinkihaveacat/puppeteer that referenced this issue Oct 31, 2017
…er in element.boxModel (puppeteer#1017)

This patch starts relying on border quad to compute element's bounding box.

Fixes puppeteer#1010
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

Successfully merging a pull request may close this issue.

2 participants