Skip to content

fix(browser): iframe scale#9745

Open
macarie wants to merge 21 commits intovitest-dev:mainfrom
macarie:fix/scale-iframe
Open

fix(browser): iframe scale#9745
macarie wants to merge 21 commits intovitest-dev:mainfrom
macarie:fix/scale-iframe

Conversation

@macarie
Copy link
Copy Markdown
Member

@macarie macarie commented Feb 25, 2026

Description

Highly WIP and needs a lot of testing, but so far seems to work with Playwright with chromium, firefox, and webkit.

Have to look into WebdriverIO (🫣)

Fixes #9124
Fixes #9363

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 25, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5ea6c4c
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69cd9f0b99fc760008ffc7e8
😎 Deploy Preview https://deploy-preview-9745--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@macarie macarie force-pushed the fix/scale-iframe branch 2 times, most recently from 22cdbd6 to b1916ae Compare March 3, 2026 11:14
@sheremet-va
Copy link
Copy Markdown
Member

Any news here? 👀

@macarie
Copy link
Copy Markdown
Member Author

macarie commented Mar 15, 2026

From my testing seems to be working fairly well with Playwright, but I've had no time to implement the WebdriverIO version yet. Hopefully this week 🤞🏼

@macarie macarie force-pushed the fix/scale-iframe branch 3 times, most recently from 77883ff to 6e15663 Compare March 18, 2026 20:35
@macarie macarie force-pushed the fix/scale-iframe branch from 4182a00 to 5ea6c4c Compare April 1, 2026 22:41
/>
<span class="pointer-events-none" text-sm>
{{ viewport[0] }}x{{ viewport[1] }}px
<span v-if="scale < 1">({{ (scale * 100).toFixed(0) }}%)</span>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can add this back now if necessary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we remove it? The window is still scaled

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it initially when I wasn't sure about what approach to go with. I'll add it back 👍🏼

@macarie
Copy link
Copy Markdown
Member Author

macarie commented Apr 2, 2026

I moved the scaling part to be CSS-only, which allowed removing some JS. I think resizing the browser window and the panels now feels more fluid and less janky, especially on old(er) hardware.

When taking screenshots a bit of CSS is injected to remove the scaling from the iframe and making it escape the pane. This should fix the "low resolution" issues, removing the scaling also leads to not having to deal with different sub pixel sizes and GPU rendering differences.

In headless mode (with no UI), Playwright now uses the set viewport, same as WebdriverIO, this should allow capturing screenshots larger than the default viewport size. In UI mode this is not done to prevent having flashing windows (more than we already have), so it's up to the user to make sure the rendered elements fit in the window.

@macarie macarie marked this pull request as ready for review April 2, 2026 09:34
Comment on lines +14 to +19
iframe {
position: absolute !important;
inset: 0 !important;
z-index: ${Number.MAX_SAFE_INTEGER} !important;
transform: none !important;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have to opacity: 0 everything else. When the iframe doesn't have a background, the UI peeks through.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be fixed by setting a background color. I'm not sure if it should change with the theme or if it should stay white tho 🤔

}

const SCREENSHOT_STYLES = /* css */`
iframe {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be [data-vitest=true]?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be more specific. Do you prefer data-vitest or its name (or both)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use data-vitest everywhere in locators), but I’m not sure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used data-vitest, looks like it's the one that's used in some other places too.

/>
<span class="pointer-events-none" text-sm>
{{ viewport[0] }}x{{ viewport[1] }}px
<span v-if="scale < 1">({{ (scale * 100).toFixed(0) }}%)</span>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we remove it? The window is still scaled

enabled: true,
screenshotFailures: false,
provider: playwright(),
provider: ${provider.name}(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runInlineTests can inject these automatically if you just pass down an object instead of a file content string (so passing down provider in the test will correctly specify it in the config)

}

// we can safely use `a` as both vertical and horizontal scale are the same
const scale = new DOMMatrix(getComputedStyle(iframe).transform).a
Copy link
Copy Markdown
Member

@sheremet-va sheremet-va Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an explanation (as a comment) of what is going on here? I've never seen this usage before

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the comment, does this version explain it better? 🤔


expect(vitest.stdout).toContain('✓ |chromium| basic.test.ts > screenshot-snapshot')
for (const instance of instances) {
expect(`✓ |${instance.browser}| basic.test.ts > screenshot-snapshot`)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't test anything?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should throw an error if expect was called without a matcher

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, messed up with the multi-cursor (again) 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should throw an error if expect was called without a matcher

That would be nice, or maybe a lint issue 👀

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 this pull request may close these issues.

Screenshot dimensions page.screenshot is extremely low resolution with a large viewport

3 participants