Skip to content

Instantly share code, notes, and snippets.

@joekrump
Created July 31, 2024 16:13
Show Gist options
  • Save joekrump/604302dda5f382e82ca11dc2146ee723 to your computer and use it in GitHub Desktop.
Save joekrump/604302dda5f382e82ca11dc2146ee723 to your computer and use it in GitHub Desktop.
Playwright mock slow network request
const urlPattern = "**/some_endpoint";
const delayMS = 1000
await page.route(urlPattern, async (route) => {
const resolve = (route: Route) => route.continue();
const res = new Promise(() => resolve);
setTimeout(async () => {
await resolve(route);
}, delayMS);
return await res;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment