High severity intermediate · Fix: 2-5 min

TimeoutError

asyncio.exceptions.TimeoutError

What this error means
The browser page navigation timed out because the page did not load within the specified timeout period.

Stack trace

traceback
asyncio.exceptions.TimeoutError: Timeout 30000ms exceeded.
  File "/usr/local/lib/python3.9/site-packages/playwright/_impl/_page.py", line 1234, in goto
    await self._main_frame.goto(url, timeout=timeout)
  File "/usr/local/lib/python3.9/site-packages/playwright/_impl/_frame.py", line 567, in goto
    raise TimeoutError(f"Timeout {timeout}ms exceeded.")
QUICK FIX
Increase the navigation timeout by passing a higher timeout value to page.goto(), e.g., timeout=60000.

Why it happens

This error occurs when the browser automation script waits for a page to load or navigate but the page does not finish loading within the specified timeout duration. It can happen due to slow network, heavy page resources, or incorrect URL causing the navigation to hang.

Detection

Monitor navigation calls with try/except blocks catching TimeoutError and log the URL and elapsed time to detect slow or stuck page loads before the script crashes.

Causes & fixes

1

The page takes longer than the default 30 seconds to load due to slow network or heavy resources.

✓ Fix

Increase the timeout parameter in the navigation call, e.g., page.goto(url, timeout=60000), to allow more time for the page to load.

2

The URL is incorrect or leads to a page that never finishes loading (e.g., infinite redirect or server hang).

✓ Fix

Verify the URL is correct and accessible. Use page.wait_for_load_state('networkidle') after navigation to confirm page load completion.

3

The page triggers dialogs, alerts, or requires user interaction blocking navigation completion.

✓ Fix

Handle dialogs and popups explicitly in the script using page.on('dialog', handler) to prevent navigation from stalling.

Code: broken vs fixed

Broken - triggers the error
python
from playwright.async_api import async_playwright
import asyncio

async def run():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        # This line causes TimeoutError if page load is slow
        await page.goto('https://example.com')
        await browser.close()

asyncio.run(run())
Fixed - works correctly
python
import os
from playwright.async_api import async_playwright
import asyncio

async def run():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        # Increased timeout to 60 seconds to prevent navigation timeout
        await page.goto('https://example.com', timeout=60000)
        await browser.close()

asyncio.run(run())
Increased the timeout parameter in page.goto() to 60000ms to allow more time for slow page loads and prevent TimeoutError.

Workaround

Wrap the navigation call in try/except TimeoutError, then retry navigation with a longer timeout or fallback to a simpler page URL.

Prevention

Use explicit waits for network idle or specific page elements after navigation and increase timeouts based on expected page complexity to avoid premature timeouts.

Python 3.9+ · playwright >=1.30.0 · tested on 1.35.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.