Skip to content

Commit e40f0fc

Browse files
author
lukaw3d
committed
Ignore error that some requests haven't finished before browser closed
1 parent 37a0b86 commit e40f0fc

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

playwright/utils/warnSlowApi.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import { BrowserContext, Page } from '@playwright/test'
33
export async function warnSlowApi(context: BrowserContext | Page) {
44
await context.route('**', async route => {
55
await route.continue()
6-
await (await route.request().response())?.finished()
7-
const url = route.request().url()
8-
const responseTime = route.request().timing().responseEnd
9-
if (responseTime > 500) console.warn('Slow API', `${responseTime}ms`, url)
6+
try {
7+
await (await route.request().response())?.finished()
8+
const url = route.request().url()
9+
const responseTime = route.request().timing().responseEnd
10+
if (responseTime > 500) console.warn('Slow API', `${responseTime}ms`, url)
11+
} catch (e) {
12+
// Ignore error that some requests haven't finished before browser closed.
13+
if (e.message.endsWith('Target page, context or browser has been closed')) return
14+
throw e
15+
}
1016
})
1117
}

0 commit comments

Comments
 (0)