Rayrun
← Back to Discord Forum

Route fetch and fulfill with 304 Not Modified cached

Hi, i m using the example from https://playwright.dev/docs/api/class-route#route-fetch to modify a response. The .fetch() method seems to handle this quit fine in chromium, firefox and edge, but in webkit i have the problem that in some cases the route is cached and simply responses with 304. The body is empty, therefor .json() throws. So what i did is fetching again if it returns 304:

let response = await route.fetch();
if (response.status() === 304) {
   const headers = route.request().headers();
   headers['Cache-Control'] = 'no-cache';
   response = await route.fetch({ headers });
}

But shouldnt the cache be deactivated in the first place or .fetch handle it for me?

response was cached (and remain unchanged) before i use page.route

This thread is trying to answer question "Should the cache be deactivated initially or should .fetch handle it when a 304 status is returned?"

0 replies

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.