← Back to library
Playwrightnetworkintermediatev1.20+

Abort a request to block third-party scripts

Drop matching outgoing requests before they're sent — keeps analytics and trackers out of test runs.

1test('page works with analytics requests blocked', async ({ page }) => {
2  // route.abort() drops the request — the browser never sends it.
3  // Block analytics early so they don't pollute network logs or fire events.
4  await page.route(/google-analytics\.com|segment\.io|hotjar\.com/, (route) => {
5    route.abort();
6  });
7
8  await page.goto('/home');
9
10  // The page should still render correctly without the blocked resources
11  await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
12});
#route.abort#block#abort#analytics#third-party