···11---
22-title: Browser mode | Guide
22+title: Browser Mode | Guide
33---
4455-# Browser mode (experimental)
55+# Browser Mode (experimental)
6677This page provides information about the experimental browser mode feature in the Vitest API, which allows you to run your tests in the browser natively, providing access to browser globals like window and document. This feature is currently under development, and APIs may change in the future.
88···8787```
88888989In this case, Vitest will run in headless mode using the Chrome browser.
9090+9191+## Limitations
9292+### Thread Blocking Dialogs
9393+9494+When using Vitest Browser, it's important to note that thread blocking dialogs like `alert` or `confirm` cannot be used natively. This is because they block the web page, which means Vitest cannot continue communicating with the page, causing the execution to hang.
9595+9696+In such situations, Vitest provides default mocks with default returned values for these APIs. This ensures that if the user accidentally uses synchronous popup web APIs, the execution would not hang. However, it's still recommended for the user to mock these web APIs for better experience. Read more in [Mocking](/guide/mocking).
+7-1
test/browser/specs/runner.test.mjs
···1717 const browserResult = await readFile('./browser.json', 'utf-8')
1818 const browserResultJson = JSON.parse(browserResult)
19192020- assert.ok(browserResultJson.testResults.length === 5, 'Not all the tests have been run')
2020+ assert.ok(browserResultJson.testResults.length === 6, 'Not all the tests have been run')
21212222 for (const result of browserResultJson.testResults)
2323 assert.ok(result.status === 'passed', `${result.name} has failed`)
···4848 assert.match(stderr, /hello from console.warn/, 'prints console.info')
4949 assert.match(stderr, /Timer "invalid timeLog" does not exist/, 'prints errored timeLog')
5050 assert.match(stderr, /Timer "invalid timeEnd" does not exist/, 'prints errored timeEnd')
5151+})
5252+5353+test('popup apis should log a warning', () => {
5454+ assert.ok(stderr.includes('Vitest encountered a \`alert\("test"\)\`'), 'prints warning for alert')
5555+ assert.ok(stderr.includes('Vitest encountered a \`confirm\("test"\)\`'), 'prints warning for confirm')
5656+ assert.ok(stderr.includes('Vitest encountered a \`prompt\("test"\)\`'), 'prints warning for prompt')
5157})