Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Syuking opened this issue Jun 18, 2021 · 32 comments
Open

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

Syuking opened this issue Jun 18, 2021 · 32 comments

Comments

@Syuking
Copy link

Syuking commented Jun 18, 2021

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 Syuking changed the title Is there any way to enable http cache when using route ? [Question] [Question] Is there any way to enable http cache when using route ? Jun 18, 2021
@aslushnikov
Copy link
Collaborator

aslushnikov commented Jun 23, 2021

Cause i hope to reduce the number of requests

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

@Syuking
Copy link
Author

Syuking commented Jun 24, 2021

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

@rigwild
Copy link

rigwild commented Aug 20, 2021

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.

@oren-sarid
Copy link

I need this too!

1 similar comment
@OKing0
Copy link

OKing0 commented Oct 20, 2021

I need this too!

@LeMoussel
Copy link

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.

@MLWeber
Copy link

MLWeber commented Jan 13, 2022

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?

@Pk-T
Copy link

Pk-T commented Mar 5, 2022

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.

@coader
Copy link

coader commented Mar 14, 2022

also need this

@Rumatoid
Copy link

I really need this feature

@Rumatoid
Copy link

Rumatoid commented Mar 29, 2022

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

@coader
Copy link

coader commented Apr 21, 2022

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?

@dgtlmoon
Copy link

aabdac8 related to this change?

@roy-k
Copy link

roy-k commented Sep 6, 2022

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

@pavliy
Copy link

pavliy commented Oct 8, 2022

Would be happy to have this option back as well.

@lifeart
Copy link

lifeart commented Nov 17, 2022

+1

@thiagodangelo
Copy link

I also need this feature.

@andobolocco
Copy link

+1

@lagunovsky
Copy link

I also need this feature.

@SwannG
Copy link

SwannG commented Jan 31, 2023

+1

@lagunovsky
Copy link

lagunovsky commented Jan 31, 2023

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'))

@xmarek
Copy link

xmarek commented Mar 6, 2023

+1

@josephwynn-sc
Copy link

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.

@hgezim
Copy link

hgezim commented Jun 16, 2023

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

@zomchak-code
Copy link

@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)

@sjoerd222888
Copy link

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

@OliverJAsh
Copy link

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

@zhzehong
Copy link

zhzehong commented Nov 7, 2023

need this

@achsal2
Copy link

achsal2 commented Nov 17, 2023

+1

@jcarlsonautomatiq
Copy link

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.

@tonybruess
Copy link

It would be great to know why the cache is disabled when using route() at the very least

@mr-anton-t
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests