
How We Fixed Firefox's localStorage Race in Playwright: Two Navigation Helpers
TL;DR Firefox's addInitScript can race against page rendering when seeding localStorage for E2E tests. We fixed it by splitting navigation into two helpers: gotoPage (fast, commit ) for interactive flows and gotoAgreementPage (reliable, domcontentloaded ) for data-dependent pages. The Problem We use Playwright's addInitScript to seed localStorage with mock agreement data before each test. This works perfectly in Chromium — the init script runs, sets localStorage, and by the time React mounts, the data is there. Firefox? Not so much. About 25% of our lifecycle tests were failing with "Loading agreement..." stuck on screen. The page rendered before the init script finished writing to localStorage. The Diagnosis Playwright's error context snapshots told the story. On first failure: - paragraph : Loading agreement... On retry (with more time): - heading "Retainer Agreement" - button "Connect Wallet" # Auth data missing too! The page loaded fine on retry, but auth data from localStorage was
Continue reading on Dev.to
Opens in a new tab



