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

Code before:
  }

  private _getAutFrame = async () => {
    try {
      if (this.gettingFrameTree) {
        debugVerbose('awaiting frame tree')

        await this.gettingFrameTree
      }

      const frameTree = (await this.send('Page.getFrameTree')).frameTree

      let frame = _.find(frameTree?.childFrames || [], (item: HasFrame) => {
        return item.frame?.name?.startsWith(AUT_FRAME_NAME_IDENTIFIER)
      }) as HasFrame | undefined

      // If we are in E2E Cypress in Cypress testing, we need to get the frame from the child frames of the AUT frame. Else we are reloading what would be the "top" frame under test (with the AUT and reporter_)
      if (process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF && frame) {
        // @ts-expect-error
        frame = _.find(frame?.childFrames || [], (item: HasFrame) => {
          return item.frame?.name?.startsWith(AUT_FRAME_NAME_IDENTIFIER)
        }) as HasFrame | undefined
      }

      if (!frame) {
        // if for whatever reason we cannot identify the AUT frame by name, we will fall back ot the first child frame that exists.
        // The first child frame should always be the AUT frame, followed by the spec frame
        if (frameTree?.childFrames?.[0]) {
          frame = frameTree.childFrames[0]
        } else {
          throw new Error('Could not find AUT frame')
        }
      }

      return frame.frame
    } catch (err) {
      debugVerbose('failed to get aut frame:', err.stack)

      throw new Error('Could not find AUT frame')
    }
  }

  _handlePausedRequests = async (client: CriClient) => {
    // NOTE: only supported in chromium based browsers
    await client.send('Fetch.enable', {
      // only enable request pausing for documents to determine the AUT iframe
      patterns: [{
        resourceType: 'Document',
      }],
    })


Review comment (suggestion):
```suggestion
        // if for whatever reason we cannot identify the AUT frame by name, we will fall back to the first child frame that exists.
```

Code after:
  }

  private _getAutFrame = async () => {
    try {
      if (this.gettingFrameTree) {
        debugVerbose('awaiting frame tree')

        await this.gettingFrameTree
      }

      const frameTree = (await this.send('Page.getFrameTree')).frameTree

      let frame = _.find(frameTree?.childFrames || [], (item: HasFrame) => {
        return item.frame?.name?.startsWith(AUT_FRAME_NAME_IDENTIFIER)
      }) as HasFrame | undefined

      // If we are in E2E Cypress in Cypress testing, we need to get the frame from the child frames of the AUT frame. Else we are reloading what would be the "top" frame under test (with the AUT and reporter_)
      if (process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF && frame) {
        // @ts-expect-error
        frame = _.find(frame?.childFrames || [], (item: HasFrame) => {
          return item.frame?.name?.startsWith(AUT_FRAME_NAME_IDENTIFIER)
        }) as HasFrame | undefined
      }

      if (!frame) {
        // if for whatever reason we cannot identify the AUT frame by name, we will fall back to the first child frame that exists.
        // The first child frame should always be the AUT frame, followed by the spec frame
        if (frameTree?.childFrames?.[0]) {
          frame = frameTree.childFrames[0]
        } else {
          throw new Error('Could not find AUT frame')
        }
      }

      return frame.frame
    } catch (err) {
      debugVerbose('failed to get aut frame:', err.stack)

      throw new Error('Could not find AUT frame')
    }
  }

  _handlePausedRequests = async (client: CriClient) => {
    // NOTE: only supported in chromium based browsers
    await client.send('Fetch.enable', {
      // only enable request pausing for documents to determine the AUT iframe
      patterns: [{
        resourceType: 'Document',
      }],
    })