Puppeteer Launch Options and Page Request Interception: Ensuring Request Capture Across Navigations
0 reputation · 15 Nov 2021, 23:17 UTC
Goal: guarantee that every network request is intercepted after a page navigation, including when working with incognito contexts.
Constraints: request interception must be enabled before any navigation; enabling it after a page has started loading can miss early requests. Incognito pages do not inherit the interception flag from their parent context, requiring a separate setup. Furthermore, the API does not automatically re‑enable interception after a navigation completes, which creates a race condition if a script toggles the flag mid‑navigation.
Questions: What is the recommended pattern to enable interception reliably before each navigation in both regular and incognito pages? How can developers ensure that interception state persists across navigations without manual re‑enabling? Is there a documented way to propagate the interception setting to newly created incognito contexts?