-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[BUG] chromium and webkit screenshot ignoring screenshot: clip: height option property #1030
Comments
I'm expecting that I shouldn't need to manually scroll to the element just to screenshot it. However, I tried const question = await page.$("h6[id^='1']")
// await question.scrollIntoViewIfNeeded() // NOT WORKING since already ratio == 1, ARGHH!
const {x: xStart, y: yStart, width: widthStart} = await question.boundingBox()
const limit = await page.$("h6[id^='2']")
const {x: xEnd, y: yEnd} = await limit.boundingBox()
// await page.$eval("h6[id^='1']", (node, y) => {
// window.scrollTo(0, y)
// }, yStart) Commit ref: |
I now tried changing the page viewport height, it changed the output of webkit significantly, but chromium output stayed the same: const page = await context.newPage({
viewport: {
height: 2000,
}
}) Commit ref: |
const limit = await page.$("h6[id^='2']");
await limit.screenshot({path:...}); |
Ah, I think I understand what you are doing - you need a whole section. Let me see if we can help you here. |
Ok, poked at it. Thank you for a nice repo with the script.
We will hunt all three problems to make sure it works as expected. For now, Following worked for me on 0.11.1 on Firefox and WebKit. Chromium made first 14 snippets. I guess you can delete them dynamically to capture all in Chromium as well. const path = require("path")
const { chromium, webkit, firefox } = require("playwright");
(async () => {
const browserType = webkit;
const browser = await browserType.launch()
// I'm using deviceScaleFactor = 2 to make images render in high dpi
const page = await browser.newPage({ viewport:
{ width: 800, height: 600, deviceScaleFactor: 2 }
})
// Playwright does not yet support file:// in Firefox
// I had to serve this on localhost for Firefox to work
await page.goto(`http://localhost:5000/index.html`)
const count = await page.evaluate(() => document.querySelectorAll("h6").length)
for (let i = 0; i < count; ++i) {
const topic = await page.evaluateHandle(index =>
document.querySelectorAll("h6").item(index), i)
console.log(`Capturing ${await topic.evaluate(e => e.innerText)}`)
// Create a transparent box, we will be screenshotting it.
const box = await topic.evaluateHandle(question => {
let limit = question
while (limit && limit.nextElementSibling && limit.nodeName !== "DETAILS")
limit = limit.nextElementSibling
const questionRect = question.getBoundingClientRect()
const limitRect = limit.getBoundingClientRect()
const box = document.createElement("div")
const y = document.documentElement.scrollTop + questionRect.y - 5;
const height = limitRect.y - questionRect.y;
box.style = `pointer-events: none; position: absolute; left: 0; right: 0; top: ${y}px; height: ${height}px;`
document.body.appendChild(box)
return box;
}, topic)
await box.screenshot({ path: `./${browserType.name()}_${i + 1}.png` })
await box.evaluate(e => e.remove())
}
console.log("FINISH")
await browser.close()
})() |
Very nice, didn't think about the |
Context:
Code Snippet
Full repo:
https://github.com/aesyondu/javascript-questions/tree/tmp/playwright-sample
Specific commit:
aesyondu/javascript-questions@4d9b189
index.js
Describe the bug
Using screenshot: clip: height, the height is ignored, and is capped at 177px. However, if I change it to height: 10, it becomes 10px.
Couldn't test with firefox due to the
page.goto: file
bug. It's already reported.The text was updated successfully, but these errors were encountered: