Repository: cypress-io/cypress
File: packages/server/lib/browsers/electron.ts (TypeScript)

Code before:
      }
    }

    await Promise.all([
      setProxy(),
      this._clearCache(win.webContents),
    ])

    if (cdpAutomation) {
      const browserCriClient = this._getBrowserCriClient()
      const pageCriClient = browserCriClient?.currentlyAttachedTarget

      if (!pageCriClient) throw new Error('Missing pageCriClient in _launch')

      await Promise.all([
        pageCriClient.send('Page.enable'),
        pageCriClient.send('ServiceWorker.enable'),
        this.connectProtocolToBrowser({ protocolManager }),
        cdpSocketServer?.attachCDPClient(cdpAutomation),
        handleVideo({ pageCriClient, cdpAutomation, videoApi, options }),
        this._handleDownloads(win, options.downloadsFolder, automation),
        utils.initializeCDP(pageCriClient, automation),
        // 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
        pageCriClient.send('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }),
        pageCriClient.send('Network.clearBrowserCache'),
      ])
    }

    // enabling can only happen once the window has loaded
    await this._enableDebugger()

    // Note that these calls have to happen before we load the page so that we don't miss out on any events that happen quickly
    if (cdpAutomation) {
      // These calls need to happen prior to loading the URL so we can be sure to get the frames as they come in
      await cdpAutomation._handlePausedRequests(browserCriClient?.currentlyAttachedTarget)
      cdpAutomation._listenForFrameTreeChanges(browserCriClient?.currentlyAttachedTarget)
    }

    await win.loadURL(url)

    return win
  },

  _enableDebugger () {
    debug('debugger: enable Console and Network')
    const browserCriClient = this._getBrowserCriClient()

    return browserCriClient?.currentlyAttachedTarget?.send('Console.enable')
  },

  _handleDownloads (win, dir, automation) {

Review comment (performance):
```suggestion
        // Note that we are omitting `file_systems` as it is very non-performant to clear:
        // https://github.com/cypress-io/cypress/pull/32703
        pageCriClient.send('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }),
```

Code after:
      }
    }

    await Promise.all([
      setProxy(),
      this._clearCache(win.webContents),
    ])

    if (cdpAutomation) {
      const browserCriClient = this._getBrowserCriClient()
      const pageCriClient = browserCriClient?.currentlyAttachedTarget

      if (!pageCriClient) throw new Error('Missing pageCriClient in _launch')

      await Promise.all([
        pageCriClient.send('Page.enable'),
        pageCriClient.send('ServiceWorker.enable'),
        this.connectProtocolToBrowser({ protocolManager }),
        cdpSocketServer?.attachCDPClient(cdpAutomation),
        handleVideo({ pageCriClient, cdpAutomation, videoApi, options }),
        this._handleDownloads(win, options.downloadsFolder, automation),
        utils.initializeCDP(pageCriClient, automation),
        // 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
        // Note that we are omitting `file_systems` as it is very non-performant to clear:
        // https://github.com/cypress-io/cypress/pull/32703
        pageCriClient.send('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }),
        pageCriClient.send('Network.clearBrowserCache'),
      ])
    }

    // enabling can only happen once the window has loaded
    await this._enableDebugger()

    // Note that these calls have to happen before we load the page so that we don't miss out on any events that happen quickly
    if (cdpAutomation) {
      // These calls need to happen prior to loading the URL so we can be sure to get the frames as they come in
      await cdpAutomation._handlePausedRequests(browserCriClient?.currentlyAttachedTarget)
      cdpAutomation._listenForFrameTreeChanges(browserCriClient?.currentlyAttachedTarget)
    }

    await win.loadURL(url)

    return win
  },

  _enableDebugger () {
    debug('debugger: enable Console and Network')
    const browserCriClient = this._getBrowserCriClient()

    return browserCriClient?.currentlyAttachedTarget?.send('Console.enable')
  },