I find myself in a dilemma where I require my functional browser tests to verify the status code of each page response, and if a 503 error is encountered, try to reload the page a certain number of times before declaring failure.
Even though I have experimented with utilizing Playwright network events, it seems that modifying the Page state (such as triggering a reload) disrupts any future interactions, leading to errors like
Execution context was destroyed, most likely because of a navigation.
.
For instance:
page.on('response', async (response) => {
if (response.request().resourceType() !== 'document') return;
if (response.status() === 503) {
await page.reload();
}
}
(I have omitted the retry attempts logic for simplicity)
Upon executing this code, any further attempts to engage with the page will trigger the Execution context was destroyed
error.
I am uncertain if this is the correct approach to tackle this issue. Any suggestions?