playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Question] Is there any way to enable http cache when using route ?

Open Syuking opened this issue 4 years ago • 34 comments

image

Chromium will cache js & css files ,but the cache is disabling when using route action So,Is there any way to enable http cache when using route ? Cause i hope to reduce the number of requests

Syuking avatar Jun 18 '21 07:06 Syuking

Cause i hope to reduce the number of requests

@Syuking Does it hit performance of the page loading in your tests?

aslushnikov avatar Jun 23 '21 00:06 aslushnikov

Cause i hope to reduce the number of requests

@Syuking Does it hit performance of the page loading in your tests?

maybe, i just want to try for this

Syuking avatar Jun 24 '21 07:06 Syuking

It would be nice if it was possible to mock responses on some routes while keeping non-matched routes in cache.

Use case: replace the content of some files/scripts loaded by a website with local versions, without slowing down the navigation by having to http load everything else everytime.

As a workaround I use a MITM proxy but that is not ideal.

rigwild avatar Aug 20 '21 11:08 rigwild

I need this too!

oren-sarid avatar Oct 17 '21 11:10 oren-sarid

I need this too!

OKing0 avatar Oct 20 '21 11:10 OKing0

As I detail it in #10414, it's possible to enable/disable http cache with Network.setCacheDisabled from Chrome DevTools Protocol. But I find it not very readable. So for more readability, just like the API Puppeteer: page.setCacheEnabled we could have this API in Playwright.

LeMoussel avatar Nov 19 '21 07:11 LeMoussel

I would like this, too. I want to use page.route() to abort requests to images and other unnecessary resources, but it defeats the purpose if I then lose the ability to cache scripts etc.

Is there a technical reason why using route disables the http cache?

MLWeber avatar Jan 13 '22 21:01 MLWeber

Any update on this? My usecase is also the same i want to mock some files but at the same time check if cache was hit for others on reload.

Pk-T avatar Mar 05 '22 17:03 Pk-T

also need this

coader avatar Mar 14 '22 04:03 coader

I really need this feature

Rumatoid avatar Mar 29 '22 09:03 Rumatoid

I found this._client.send('Network.setCacheDisabled', { cacheDisabled: true }), in files, that disable cache after enabling routing I have just comment this line and build playwright, and cache enabled

Sorry for my English

Rumatoid avatar Mar 29 '22 21:03 Rumatoid

I found this._client.send('Network.setCacheDisabled', { cacheDisabled: true }), in files, that disable cache after enabling routing I have just comment this line and build playwright, and cache enabled

Sorry for my English

is any way to config this without rebuild?

coader avatar Apr 21 '22 09:04 coader

https://github.com/microsoft/playwright/commit/aabdac83804bfb28fba0a93a5d4f61ce17920f41 related to this change?

dgtlmoon avatar Aug 29 '22 09:08 dgtlmoon

Is there any new? I really need this too. As a service, it will be more effective~

roy-k avatar Sep 06 '22 13:09 roy-k

Would be happy to have this option back as well.

pavliy avatar Oct 08 '22 00:10 pavliy

+1

lifeart avatar Nov 17 '22 16:11 lifeart

I also need this feature.

thiagodangelo avatar Nov 22 '22 13:11 thiagodangelo

+1

andobolocco avatar Jan 25 '23 21:01 andobolocco

I also need this feature.

lagunovsky avatar Jan 28 '23 20:01 lagunovsky

+1

SwannG avatar Jan 31 '23 10:01 SwannG

Workaround

// package.json

"scripts": {
+   "prepare": "node prepare.js",
}
// prepare.js

import path from 'path'
import {readFileSync, writeFileSync} from 'fs'

const modules = path.resolve(`node_modules`)
const destination = path.join(modules, 'playwright-core', 'lib', 'server', 'chromium', 'crNetworkManager.js')
const buffer = readFileSync(destination)
writeFileSync(destination, buffer.toString().replace('cacheDisabled: true', 'cacheDisabled: false'))

lagunovsky avatar Jan 31 '23 11:01 lagunovsky

+1

xmarek avatar Mar 06 '23 03:03 xmarek

I'm sorely missing the Page.setCacheEnabled API too. We want to use Playwright to run automated tests for our analytics script, and there are cases where the testing code is much simpler when it can explicitly enable or disable the cache within a single test case.

josephwynn-sc avatar Apr 18 '23 21:04 josephwynn-sc

Seems that using page.context().on('response', handler) does not affect caching (requests are still cached). Can someone confirm this?

hgezim avatar Jun 16 '23 21:06 hgezim

@aslushnikov What kind of feedback do you need for this? I also need this feature to reduce network traffic and not warm up the planet)

zomchak-code avatar Aug 02 '23 20:08 zomchak-code

I also need this feature to make it more efficient, faster! And of course I want to reduce network traffic and not contribute to warming up the planet

sjoerd222888 avatar Aug 18 '23 07:08 sjoerd222888

Is there a reason why Playwright disables the cache when using page.route?

OliverJAsh avatar Sep 11 '23 18:09 OliverJAsh

need this

zhzehong avatar Nov 07 '23 13:11 zhzehong

+1

achsal2 avatar Nov 17 '23 01:11 achsal2

It definitely seems like something a route should allow when you are using playwright for integration testing. Keeping it alive before a resolver bot gets it.

jcarlsonautomatiq avatar Nov 29 '23 12:11 jcarlsonautomatiq