Skip to main content

Playwright: Wait for Network Idle After Action

TypeScript

Click and wait for the matching API response instead of sleeping.

K
Kenechukwu Igwe
Sample Jul 20, 2026
TypeScript · 5 lines
1
2
3
4
5
const [response] = await Promise.all([
  page.waitForResponse((r) => r.url().includes('/api/save') && r.ok()),
  page.getByRole('button', { name: 'Save' }).click(),
]);
expect(await response.json()).toMatchObject({ status: 'ok' });
4 Fire 0 Learned something 2 Saved me time 1 Mind-blown
Sign in to react and star