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

Code before:
        return true
      case 'remote:debugger:protocol':
        return this.sendDebuggerCommandFn(data.command, data.params, data.sessionId)
      case 'take:screenshot':
        debugVerbose('capturing screenshot')

        if (this.focusTabOnScreenshot) {
          try {
            await this.activateMainTab()
          } catch (e) {
            debugVerbose('Error while attempting to activate main tab: %O', e)
          }
        }

        return this.sendDebuggerCommandFn('Page.captureScreenshot', { format: 'png' })
        .catch((err) => {
          throw new Error(`The browser responded with an error when Cypress attempted to take a screenshot.\n\nDetails:\n${err.message}`)
        })
        .then(({ data }) => {
          return `data:image/png;base64,${data}`
        })
      case 'reset:browser:state':
        return Promise.all([
          this.sendDebuggerCommandFn('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }),
          this.sendDebuggerCommandFn('Network.clearBrowserCache'),
        ])
      case 'reset:browser:tabs:for:next:spec':
        return this.sendCloseCommandFn(data.shouldKeepTabOpen)
      case 'focus:browser:window':
        return this.sendDebuggerCommandFn('Page.bringToFront')
      case 'get:heap:size:limit':
        return this.sendDebuggerCommandFn('Runtime.evaluate', { expression: 'performance.memory.jsHeapSizeLimit' })
      case 'collect:garbage':
        return this.sendDebuggerCommandFn('HeapProfiler.collectGarbage')
      case 'key:press':
        return cdpKeyPress(toSupportedKey(data.key), this.sendDebuggerCommandFn, this.executionContexts, (await this.send('Page.getFrameTree')).frameTree)
      case 'get:aut:url':
        return cdpGetUrl(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame())
      case 'reload:aut:frame':
        return cdpReloadFrame(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame(), data.forceReload)
      case 'navigate:aut:history':
        return cdpNavigateHistory(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame(), data.historyNumber)
      case 'get:aut:title':
        return cdpGetFrameTitle(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame())
      default:
        throw new Error(`No automation handler registered for: '${message}'`)
    }
  }
}


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

Code after:
        return true
      case 'remote:debugger:protocol':
        return this.sendDebuggerCommandFn(data.command, data.params, data.sessionId)
      case 'take:screenshot':
        debugVerbose('capturing screenshot')

        if (this.focusTabOnScreenshot) {
          try {
            await this.activateMainTab()
          } catch (e) {
            debugVerbose('Error while attempting to activate main tab: %O', e)
          }
        }

        return this.sendDebuggerCommandFn('Page.captureScreenshot', { format: 'png' })
        .catch((err) => {
          throw new Error(`The browser responded with an error when Cypress attempted to take a screenshot.\n\nDetails:\n${err.message}`)
        })
        .then(({ data }) => {
          return `data:image/png;base64,${data}`
        })
      case 'reset:browser:state':
        return Promise.all([
          // Note that we are omitting `file_systems` as it is very non-performant to clear:
          // https://github.com/cypress-io/cypress/pull/32703
          this.sendDebuggerCommandFn('Storage.clearDataForOrigin', { origin: '*', storageTypes: 'cookies,indexeddb,local_storage,shader_cache,service_workers,cache_storage,interest_groups,shared_storage' }),
          this.sendDebuggerCommandFn('Network.clearBrowserCache'),
        ])
      case 'reset:browser:tabs:for:next:spec':
        return this.sendCloseCommandFn(data.shouldKeepTabOpen)
      case 'focus:browser:window':
        return this.sendDebuggerCommandFn('Page.bringToFront')
      case 'get:heap:size:limit':
        return this.sendDebuggerCommandFn('Runtime.evaluate', { expression: 'performance.memory.jsHeapSizeLimit' })
      case 'collect:garbage':
        return this.sendDebuggerCommandFn('HeapProfiler.collectGarbage')
      case 'key:press':
        return cdpKeyPress(toSupportedKey(data.key), this.sendDebuggerCommandFn, this.executionContexts, (await this.send('Page.getFrameTree')).frameTree)
      case 'get:aut:url':
        return cdpGetUrl(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame())
      case 'reload:aut:frame':
        return cdpReloadFrame(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame(), data.forceReload)
      case 'navigate:aut:history':
        return cdpNavigateHistory(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame(), data.historyNumber)
      case 'get:aut:title':
        return cdpGetFrameTitle(this.sendDebuggerCommandFn, this.executionContexts, await this._getAutFrame())
      default:
        throw new Error(`No automation handler registered for: '${message}'`)
    }
  }
}