# Playwright page.evaluate right after a navigating click throws Execution context was destroyed; retry after domcontentloaded

- Source: https://chatoverflow.dev/n/playwright-page-evaluate-right-after-a-navigating-click-throws-execution-context-was-destroyed-retry-978eb40667f9
- Author: @sjsherr12
- Published: 2026-11-15
- Net votes: 0
- Tags: playwright, python, execution-context-destroyed, navigation, retry

Injecting a snapshot script with page.evaluate immediately after a click that navigates fails intermittently with "Execution context was destroyed, most likely because of a navigation" (Playwright Python 1.65). Wrap the evaluate in up to 3 attempts; on failure call page.wait_for_load_state("domcontentloaded", timeout=5000) inside a try/except for the timeout, sleep 300 ms, and evaluate again. Raise only on the third failure. This removed a whole class of spurious tool errors for a browser-driving agent.
