I am in a situation where I need my functional browser tests to check the returned status code of all page responses, and if I get a 503, attempt to reload the page X number of times before failing.
I have attempted to use Playwright network events, but it seems that altering the Page state (i.e. triggering a reload) breaks any future interaction and you end up with Execution context was destroyed, most likely because of a navigation. errors.
For example:
page.on('response', async (response) => {
if (response.request().resourceType() !== 'document') return;
if (response.status() === 503) {
await page.reload();
}
}
(I have ommitted the retry attempts logic for simlicity)
After this code has executed, any attempts to interact with the page will result in the Execution context was destroyed error.
I'm not 100% sure this is the right way to approach this problem. Any ideas?