Comments (10)
Interesting example, thanks for sharing. On observing the page, I noticed that the bottom parts of the page load after scrolling. To replicate this behavior through Playwright, I've added a method scrollFullPage
to your code snippet, executed right before taking a screenshot.
const pw = require('playwright');
(async () => {
const browser = await pw.chromium.launch({ headless: false }); // or 'chromium', 'firefox'
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://www.waze.com/');
await scrollFullPage(page);
await page.screenshot({
path: 'example.png',
fullPage : true
});
await browser.close();
})();
async function scrollFullPage(page) {
await page.evaluate(async () => {
await new Promise(resolve => {
let totalHeight = 0;
const distance = 100;
const timer = setInterval(() => {
const scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight){
clearInterval(timer);
resolve();
}
}, 100);
});
});
}
from playwright.
Interesting example, thanks for sharing. On observing the page, I noticed that the bottom parts of the page load after scrolling. To replicate this behavior through Playwright, I've added a method
scrollFullPage
to your code snippet, executed right before taking a screenshot.const pw = require('playwright'); (async () => { const browser = await pw.chromium.launch({ headless: false }); // or 'chromium', 'firefox' const context = await browser.newContext(); const page = await context.newPage(); await page.goto('https://www.waze.com/'); await scrollFullPage(page); await page.screenshot({ path: 'example.png', fullPage : true }); await browser.close(); })(); async function scrollFullPage(page) { await page.evaluate(async () => { await new Promise(resolve => { let totalHeight = 0; const distance = 100; const timer = setInterval(() => { const scrollHeight = document.body.scrollHeight; window.scrollBy(0, distance); totalHeight += distance; if (totalHeight >= scrollHeight){ clearInterval(timer); resolve(); } }, 100); }); }); }
Thanks @arjun27 , it worked for the given example. I appreciate your help. Will try with some other examples and let you know how I go.
This project looks interesting, anyway I can contribute to the project? Say some doco, tutorial etc?
from playwright.
Can scrollFullPage() be implemented with a flag option? I use gsap animations that load the website content when the user scrolls. In my case fullPage: true
is not enough.
from playwright.
Any chance this can be implemented as a method since there are many scenarios where we're in need of taking full page screenshots.
This was a limitation in Puppeteer and it would be a definite plus point for a lot of users imho.
Issue - GoogleChrome/rendertron#108 (Puppeteer doesn't support full page screenshot)
from playwright.
Thanks @zac11. Full page screenshots are supported with the fullPage: true
flag. Can you share any examples where the flag does not work for you? Thanks!
from playwright.
It's definitely due to the website animating in all images when inside the viewport. A fullpage screenshot scrolls too fast for the code to show the images. This isn't a puppeteer/playwright limitiation.
I wonder if turning off CSS transitions before taking the screenshot would help?
* {
transition: unset !important;
}
from playwright.
Thanks @zac11. Full page screenshots are supported with the
fullPage: true
flag. Can you share any examples where the flag does not work for you? Thanks!
There's this page https://extrasalt.org/ where even with the fullPage
flag enabled, playwright doesn't capture the entire page SS. Only a part of it. Attaching the screenshot captured.
from playwright.
Interesting example, thanks for sharing. On observing the page, I noticed that the bottom parts of the page load after scrolling. To replicate this behavior through Playwright, I've added a method
scrollFullPage
to your code snippet, executed right before taking a screenshot.const pw = require('playwright'); (async () => { const browser = await pw.chromium.launch({ headless: false }); // or 'chromium', 'firefox' const context = await browser.newContext(); const page = await context.newPage(); await page.goto('https://www.waze.com/'); await scrollFullPage(page); await page.screenshot({ path: 'example.png', fullPage : true }); await browser.close(); })(); async function scrollFullPage(page) { await page.evaluate(async () => { await new Promise(resolve => { let totalHeight = 0; const distance = 100; const timer = setInterval(() => { const scrollHeight = document.body.scrollHeight; window.scrollBy(0, distance); totalHeight += distance; if (totalHeight >= scrollHeight){ clearInterval(timer); resolve(); } }, 100); }); }); }Thanks @arjun27 , it worked for the given example. I appreciate your help. Will try with some other examples and let you know how I go.
This project looks interesting, anyway I can contribute to the project? Say some doco, tutorial etc?
overflow-y: initial !important;
the default overflow will affect the fullscreen args
from playwright.
I have some problem about screenshot. I don't know why mine is a little fuzzy? Viewport size is 480×1080.
from playwright.
Similar issue here, I couldn't understand why the bottom of my page gets cropped while running Argos (visual regression tests)
It turns out a widget on the page (the docs 👍 👎 rating widget) produces a layout shift when loading and it messes up with the fullPage screenshot. The bottom cropped part is exactly 109px which is the height this widget takes in practice.
Screenshotting code, using Playwright 1.30:
await handle.screenshot({
path: resolve(screenshotFolder, `${name}.png`),
type: "png",
fullPage: true,
mask: [page.locator('[data-visual-test="blackout"]')],
animations: "disabled",
...options,
});
Considering the widget is visible on both screenshots, it looks to me that there might be some kind of race condition happening in the playwright screenshotting logic. My intuition is:
- We call
screenshot()
- Screenshot computes the final height
- The widget appears on the page
- Playwright takes the screenshot
Example page I found this issue on: https://deploy-preview-3780--react-native.netlify.app/architecture/overview
from playwright.
Related Issues (20)
- [Bug]: Since v1.43, "Error: Error: browserType.launch: Executable doesn't exist" HOT 2
- Can't get parallel running for multiple tests in same file - Playwright HOT 2
- [Bug]: Adding an assertion in a fixture does not trigger retries HOT 1
- [Bug]: No tests passing for a simple component (component testing) HOT 1
- [Feature]: Allow page to listen for custom events `page.on(CUSTOM_EVENT, () =>` HOT 5
- [Bug]: Unable to run playwright tests using github actions HOT 8
- [Bug]: Timing issues with dynamically generated tests. (Updated, originally thought this was a globbing issue) HOT 6
- [Question] Why is 'setDownloadBehavior' required for connect_over_cdp? Any workaround? HOT 1
- [Bug]: playwright tests do not show in test tab in vscode, no errors, cli works HOT 5
- [Bug]: invoke beforeall method with condition skip in loop will skip entire test instead of respective each loop tests HOT 5
- [Bug]: Arch Linux & your OS is not officially supported by Playwright HOT 1
- [Bug]: @tags added using new syntax as per v1.42 is not shown in UI mode HOT 1
- [Feature]: Set proxy in Page HOT 1
- [Bug]: Missing projects/tests when using multiple projects (folders) from 1.43.x HOT 2
- [Regression]: Missing requests on trace file using page.Context.Tracing.StartAsync HOT 3
- [Bug]: Windows: Error with emoji in filename: `Error: ENOENT: no such file or directory, access` HOT 3
- [Regression]: Tests fails in parallel run when click on dropdown options performed HOT 2
- [Bug]: Corepack eneable pnpm does not work in playwright image 1.43.X anymore HOT 5
- [Feature]: pytest-playwright - auto slow down considering cpu load HOT 1
- [Bug]: Results of test run in UI Mode disappear after short delay with "Did not run" message HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.