Playwright: How to Remove or Disable Timeout (With Examples)
By default, Playwright applies timeouts to most actions like click(), waitForSelector(), and assertions. In some cases, you may want to remove, increase, or customize these timeouts β for example, when testing a slow-loading app or debugging flakiness.
This guide explains how to remove timeouts in Playwright, how to set them to 0 (infinite), and when to override them.
β Quick Answer: Set Timeout to 0
await page.locator('#my-element').click({ timeout: 0 });
This disables the timeout for the click() action β Playwright will wait indefinitely.
π§ͺ Method 1: Set Timeout Per Action
await page.click('#submit', { timeout: 0 }); // no timeout
await page.waitForSelector('.loading', { timeout: 15000 }); // 15 seconds
- β Precise control
- π‘ Recommended for slow elements or debugging
π§ͺ Method 2: Set Timeout Per Locator
const button = page.locator('#my-button').setTimeout(0);
await button.click();
- β Reusable locator without timeout
- β Cleaner for page object models
π§ͺ Method 3: Set Timeout for Whole Test
If using Playwright Test:
test('long test', async ({ page }) => {
test.setTimeout(0); // no timeout
await page.goto('https://example.com');
// long-running steps...
});
- β Useful for long E2E flows
- β Disables the entire test timeout β use with caution
π§ͺ Method 4: Override Global Timeout in Config
In playwright.config.ts:
import { defineConfig } from '@playwright/test';
export default defineConfig({
timeout: 0, // disable test-level timeout globally
});
Or increase timeout globally:
timeout: 60000, // 60 seconds
π§ͺ Method 5: Page-Wide Timeout Override (Advanced)
page.setDefaultTimeout(0); // No timeout for all page actions
page.setDefaultNavigationTimeout(0); // For navigations only
Use when:
- Working with slow network
- Performing manual debugging
- Testing transitional UI
π§° Comparison Table
| Scope | Method | Timeout Control | Recommended Use Case |
|---|---|---|---|
| Per Action | click({ timeout: 0 }) | β High | Disable timeout for one step |
| Per Locator | locator().setTimeout(0) | β Medium | Reusable locators |
| Whole Test | test.setTimeout(0) | β High | Long-running E2E scenarios |
| Global Config | timeout: 0 in config | β High | Disable timeouts project-wide |
| Page-wide | page.setDefaultTimeout(0) | β Medium | Debugging or network slowness |
π§ Pro Tips
- Donβt forget to re-enable timeouts after debugging!
- Use longer timeouts instead of
0in CI/CD to avoid hangs:
page.setDefaultTimeout(60000); // 60 seconds
- Use
DEBUG=pw:apito trace actions and delays in development
β Common Mistakes
| Mistake | Fix |
|---|---|
Using timeout: 0 in production | Use longer timeouts like 30000 (30s) instead |
Forgetting await | Always await async actions |
| Removing timeouts globally | Only disable timeouts during local debugging |
π Conclusion
To remove or disable timeout in Playwright:
- Use
timeout: 0in action options or locator settings - Use
setTimeout(0)for tests orsetDefaultTimeout(0)for global actions - Prefer increased timeouts over total removal for stability in CI