Skip to content

bug: fixed positioning cannot be used in vitest browser headless mode #7742

@rxliuli

Description

@rxliuli

Describe the bug

Kapture.2025-04-02.at.21.36.47.mp4

Command

pnpm vitest toast.browser.test.ts --project=browser --run # success
pnpm vitest toast.browser.test.ts --project=headless --run # failed

toast.browser.test.ts

import { it } from 'vitest'
import { page } from '@vitest/browser/context'

it('should render', async () => {
  const div = document.createElement('button')
  div.innerHTML = 'Hello'
  div.style.position = 'fixed'
  div.style.bottom = '40px'
  div.style.backgroundColor = 'red'
  document.body.appendChild(div)
  await page.getByText('Hello').click()
}, 5000)

vitest.workspace.ts

import { defineWorkspace } from 'vitest/config'

export default defineWorkspace([
  // If you want to keep running your existing tests in Node.js, uncomment the next line.
  // 'vite.config.ts',
  {
    extends: 'vite.config.ts',
    test: {
      name: 'browser',
      browser: {
        enabled: true,
        provider: 'playwright',
        // https://vitest.dev/guide/browser/playwright
        instances: [{ browser: 'chromium' }],
      },
    },
  },
  {
    extends: 'vite.config.ts',
    test: {
      name: 'headless',
      browser: {
        enabled: true,
        headless: true,
        provider: 'playwright',
        // https://vitest.dev/guide/browser/playwright
        instances: [{ browser: 'chromium' }],
      },
    },
  },
])

Reproduction

Yes, I found this issue when using svelte-sonner, which caused the toast popup to be unclickable because the toast was not within the visible window.

wobsoriano/svelte-sonner#140
https://github.com/rxliuli/svelte-sonner-error-demo

System Info

System:
    OS: macOS 15.3.2
    CPU: (12) arm64 Apple M2 Max
    Memory: 1.60 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - /usr/local/bin/node
    npm: 10.9.2 - /usr/local/bin/npm
    pnpm: 10.5.2 - /usr/local/bin/pnpm
    bun: 1.1.6 - ~/.bun/bin/bun
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 131.1.73.105
    Chrome: 134.0.6998.166
    Edge: 128.0.2739.54
    Safari: 18.3.1

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions