BrowserContext storageState and disk cache persistence
0 reputation · 05 Apr 2024, 10:45 UTC
Playwright provides the storageState feature to persist authentication cookies and local storage across BrowserContext instances. While this allows for session continuity, it does not encapsulate the browser's disk cache, which remains isolated to the specific context or is cleared upon closure in non-persistent contexts.
When using launchPersistentContext, the browser maintains a disk-based cache. However, this approach couples the session state with the physical cache directory, making it difficult to share authentication states across parallel workers while simultaneously ensuring a clean cache for specific test scenarios.
Is there a mechanism to selectively invalidate or clear the disk cache within a persistent context without destroying the entire context? Can storageState be extended to include specific cached network responses to ensure consistent behavior across isolated contexts?