Repository navigation
Description
Clear and concise description of the problem
I'm using the Playwright provider and trying to use screenshots for rendering tests with the following vite.config.js test config:
{
browser: {
ui: true,
provider: playwright({
launchOptions: {
args: ['--enable-gpu', '--force-device-scale-factor=1'],
},
}),
enabled: true,
instances: [{browser: 'chromium'}],
viewport: {width: 512, height: 512},
},
}In my tests, I capture a screenshot with await expect(page.elementLocator(target)).toMatchScreenshot(); and the target element has CSS dimensions of 512x512. The problem is that the vitest iframe with the Browser UI has an arbitrary width depending on the --tester-transform scale that is applied, and the screenshot dimensions are based on this scaled element's dimensions instead of dimensions that I control.
I can get tests to pass by running them in headless mode or by setting browser.ui to false. Is there an existing way to configure things so that screenshots captured using headed tests with browser.ui set to true will have a fixed or known dimension?
Suggested solution
I'm not sure what a good solution would be. Maybe another option to disable scaling of the tester-ui element?
{
viewport: {width: 512, height},
scaleViewport: false, // this would make it so tester-ui doesn't have a scale transform applied
}Alternative
No response
Additional context
# npm ls vitest
├─┬ @vitest/browser-playwright@4.0.16
│ ├─┬ @vitest/browser@4.0.16
│ │ └── vitest@4.0.16 deduped
│ └── vitest@4.0.16 deduped
└── vitest@4.0.16
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Activity
philholden commentedon Jan 14, 2026
Similar issue. With the UI enabled I get sub-pixel issues with SVGs. The dividers on the three pane layout do not snap to pixels. The columns have percentage widths. This means the iframe is nearly always rendered on a sub-pixel e.g. doing getBoundingClientRect().x on the parent of the iframe I get: 676.3203125
It would be helpful if the dividers snapped to pixels. If too hard shift the iframe wrapper div back to the nearest pixel boundary using relative positioning e.g. {position: relative, left: -0.3203125} (needs to be updated on resize of screen or dragging of left divider).
Third (easiest) option move the browser to the first panel.
hon2a commentedon Jan 26, 2026
I'm facing the same issue even when running tests with
ui: falseand/orheadless: true, see #9124 (comment). I haven't been able to find a configuration that'd let me take screenshots of arbitrarily large viewport without scaling them down.veykos commentedon Feb 6, 2026
I have the same issue - using
in headless mode takes the proper size screenshots - for example my viewport is 1280 x 720, the element is taking 1280x88 and the screenshot is 1280x88.
Turning off headless mode the screenshot size is 1966×136px.
This makes it so test are almost not runnable in UI mode except with
expect.softwhich still throws warnings but at least I can check if the actual test is passing.larsswanstrommyh commentedon Mar 11, 2026
Me too having this problem. All tests green in with headless, all tests red with UI (or vice verse depending on how the reference screenshots were taken).
Reference screenshot, 333×17px,

(headless: true)Actual screenshot , 403×20px,

(headless: false)craigwalkeruk commentedon Mar 16, 2026
I have the same issue, even when working locally on my retina display and switching to a montior the scaling changes due to
-tester-transformmoving the goal posts.I'm now working in a docker image to for consistentcy but it kind defeats the pourpose of having the UI and the diff slider etc if it the scale will break the test on diferent machines.
I've created a test project with my setup: https://github.com/craigwalkeruk/green-surf-co-angular/tree/8cd8efe9d8a85476107d5c3e5656854705dec375
You can see I'm working around other challenages if your curiouis with this command
Hope it helps