Skip to content

Commit a2adeab

Browse files
fix: improve the performance of resetting the browser state by not resetting file_systems (#32703)
* fix: improve the performance of resetting the browser state by removing file_systems which is not something we need to reset * fix test * add changelog entry * fix electron * Apply suggestions from code review
1 parent a88da66 commit a2adeab

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ _Released 10/21/2025 (PENDING)_
1111

1212
- An error is no longer thrown during command execution when the application under test overwrites the `window.$` property with a non-function. Fixes [#1502](https://github.com/cypress-io/cypress/issues/1502). Fixed in [#32682](https://github.com/cypress-io/cypress/pull/32682).
1313
- When running `cypress` in Cypress development environments, or when `ELECTRON_ENABLE_LOGGING` is otherwise set to 1, certain messages written to `stderr` will no longer be bracketed with verbose tags. Addresses [#32569](https://github.com/cypress-io/cypress/issues/32569). Addressed in [#32674](https://github.com/cypress-io/cypress/pull/32674).
14+
- Improve performance of time between specs by not resetting the `file_systems` `StorageType` state when executing the CDP command `Storage.clearDataForOrigin`. Fixed in [#32703](https://github.com/cypress-io/cypress/pull/32703).
1415

1516
**Misc:**
1617

packages/server/lib/browsers/cdp_automation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,9 @@ export class CdpAutomation implements CDPClient, AutomationMiddleware {
639639
})
640640
case 'reset:browser:state':
641641
return Promise.all([
642-
this.sendDebuggerCommandFn('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'all' }),
642+
// Note that we are omitting `file_systems` as it is very non-performant to clear:
643+
// https://github.com/cypress-io/cypress/pull/32703
644+
this.sendDebuggerCommandFn('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }),
643645
this.sendDebuggerCommandFn('Network.clearBrowserCache'),
644646
])
645647
case 'reset:browser:tabs:for:next:spec':

packages/server/lib/browsers/electron.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ export = {
341341
this._handleDownloads(win, options.downloadsFolder, automation),
342342
utils.initializeCDP(pageCriClient, automation),
343343
// Ensure to clear browser state in between runs. This is handled differently in browsers when we launch new tabs, but we don't have that concept in electron
344-
pageCriClient.send('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'all' }),
344+
// Note that we are omitting `file_systems` as it is very non-performant to clear:
345+
// https://github.com/cypress-io/cypress/pull/32703
346+
pageCriClient.send('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }),
345347
pageCriClient.send('Network.clearBrowserCache'),
346348
])
347349
}

packages/server/test/unit/browsers/cdp_automation_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,12 @@ context('lib/browsers/cdp_automation', () => {
560560

561561
describe('reset:browser:state', function () {
562562
it('sends Storage.clearDataForOrigin and Network.clearBrowserCache', async function () {
563-
this.sendDebuggerCommand.withArgs('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'all' }).resolves()
563+
this.sendDebuggerCommand.withArgs('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }).resolves()
564564
this.sendDebuggerCommand.withArgs('Network.clearBrowserCache').resolves()
565565

566566
await this.onRequest('reset:browser:state')
567567

568-
expect(this.sendDebuggerCommand).to.be.calledWith('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'all' })
568+
expect(this.sendDebuggerCommand).to.be.calledWith('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' })
569569
expect(this.sendDebuggerCommand).to.be.calledWith('Network.clearBrowserCache')
570570
})
571571
})

packages/server/test/unit/browsers/electron_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ describe('lib/browsers/electron', () => {
517517
it('expects the browser to be reset', function () {
518518
return electron._launch(this.win, this.url, this.automation, this.options, undefined, undefined, { attachCDPClient: sinon.stub() })
519519
.then(() => {
520-
expect(this.pageCriClient.send).to.be.calledWith('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'all' })
520+
expect(this.pageCriClient.send).to.be.calledWith('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' })
521521
expect(this.pageCriClient.send).to.be.calledWith('Network.clearBrowserCache')
522522
})
523523
})

0 commit comments

Comments
 (0)