[BUG] Unable to set viewport width and capture fullpage screenshot
See original GitHub issueContext:
- Playwright Version: 1.20.2
- Operating System: Linux (running inside the Playwright docker container)
- Node.js version: 16
- Browser: All
Code Snippet
// @ts-check
const playwright = require('playwright');
(async () => {
for (const browserType of ['chromium', 'webkit', 'firefox']) {
/** @type {import('playwright').Browser} */
const browser = await playwright[browserType].launch();
const context = await browser.newContext({ viewport: { width: 320, height: 1000 }});
const page = await context.newPage();
await page.goto('https://playwright.dev');
await page.screenshot({ path: `example-${browserType}.png` });
await browser.close();
}
})();
Reproduction link on Playwright playground: https://try.playwright.tech/?l=javascript&s=hmy3u0h
Note that the screenshots have the https://playwright.dev
page cut off and it does not show the full page.
Describe the bug
It seems that setting the viewport explicitly disallows taking full page screenshots. As far as I can tell this means it’s not possible to take full page screenshots at any viewport width than the default. There’s no way to not pass a width to the viewport
option of test.use
(Playwright will throw an error about expecting undefined
to be a number
).
No warning or anything will happen but the screenshot generated will be the height passed to test.use
rather than the full page.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
1164757 - Capture full size screenshot is broken - Monorail
Issue 1164757: Capture full size screenshot is broken: Incorrect pixel dimensions · 1. Navigate to https://developer.mozilla.org/en-US/ · 2. CTRL+ ...
Read more >Full page screen shot isn't full page - Firefox Screenshots
I am unable to take a full page screenshot using Developer Tools “Take a screenshot of the entire page” or using the 'screenshot...
Read more >When trying to capture a screenshot my screen shifts or resizes
When trying to capture a screen shot the screen will resize if more than one monitor is attached to the computer and the...
Read more >Puppeteer Screenshot Full Page Not Working. Possible Fixes ...
The problem with lazy loading is that generally it will affect screenshot operations since the default rendered behavior is to capture the image ......
Read more >How to take a full-page screenshot in Google Chrome -- 4 ways
A full-screen capture on Google Chrome is easier said than done. Follow this how-to for flawless screenshots, every time.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The workaround we used was to remove the
overflow: hidden
before callingscreenshot
. Here’s the utility function we wrote to ease that: https://github.com/WordPress/openverse-frontend/blob/32ce30625757aaab6e0c50cb3655e683f1a4730f/test/playwright/utils/page.ts#L3-L13However, I think we might not need it any more. A few months ago we significantly restructured the HTML of our app (here’s one of the PRs that was involved in that, not sure if it would be helpful) and managed to remove the fixed height (or something?). Sorry, it’s been a while since we addressed the issue so I don’t remember exactly, but it did take quite a bit of working as you can see in the PR. It’s probably pretty application specific in the end 😕 I hate to say it (because I know it can be difficult), but you might need to look into restructuring your app’s HTML like we ended up having to.
Thanks! I think I found a workaround for my use-case. Instead of removing the
overflow: hidden
I just stretch the viewport:My
.page-wrap
is basicallySo I figure I need to stretch that element before I can screenshot it properly.