Repository: cypress-io/cypress
File: packages/driver/src/cypress/cy.ts (TypeScript)

Code before:
    cy[name] = function (...args) {
      ensureRunnable(cy, name)

      // for privileged commands, we send a message to the server that verifies
      // them as coming from the spec. the fulfillment of this promise means
      // the message was received. the implementation for those commands
      // checks to make sure this promise is fulfilled before sending its
      // websocket message for running the command to ensure prevent a race
      // condition where running the command happens before the command is
      // verified
      const privilegeVerification = Cypress.emitMap('command:invocation', { name, args })

      // this is the first call on cypress
      // so create a new chainer instance
      const chainer = new $Chainer(cy.specWindow)

      if (cy.state('chainerId')) {
        cy.linkSubject(chainer.chainerId, cy.state('chainerId'))
      }

      let userInvocationStack = $stackUtils.captureUserInvocationStack(cy.specWindow.Error)

      if (cy.state('originUserInvocationStack')) {
        // console.log('originUserInvocationStack', cy.state('originUserInvocationStack'))
        // console.log('userInvocationStack', userInvocationStack)
        userInvocationStack = $stackUtils.mergeCrossOriginUserInvocationStack(userInvocationStack, cy.state('originUserInvocationStack'))
      }

      callback(chainer, userInvocationStack, args, privilegeVerification, true)

      // if we are in the middle of a command
      // and its return value is a promise
      // that means we are attempting to invoke
      // a cypress command within another cypress
      // command and we should error
      const ret = cy.state('commandIntermediateValue')

      if (ret) {
        const current = cy.state('current')

        // if this is a custom promise
        if ($utils.isPromiseLike(ret) && $utils.noArgsAreAFunction(current.get('args'))) {
          $errUtils.throwErrByPath(
            'miscellaneous.command_returned_promise_and_commands', {
              args: {
                current: current.get('name'),
                called: name,
              },
            },
          )
        }

Review comment (suggestion):
```suggestion
        userInvocationStack = $stackUtils.mergeCrossOriginUserInvocationStack(userInvocationStack, cy.state('originUserInvocationStack'))
```

Code after:
    cy[name] = function (...args) {
      ensureRunnable(cy, name)

      // for privileged commands, we send a message to the server that verifies
      // them as coming from the spec. the fulfillment of this promise means
      // the message was received. the implementation for those commands
      // checks to make sure this promise is fulfilled before sending its
      // websocket message for running the command to ensure prevent a race
      // condition where running the command happens before the command is
      // verified
      const privilegeVerification = Cypress.emitMap('command:invocation', { name, args })

      // this is the first call on cypress
      // so create a new chainer instance
      const chainer = new $Chainer(cy.specWindow)

      if (cy.state('chainerId')) {
        cy.linkSubject(chainer.chainerId, cy.state('chainerId'))
      }

      let userInvocationStack = $stackUtils.captureUserInvocationStack(cy.specWindow.Error)

      if (cy.state('originUserInvocationStack')) {
        userInvocationStack = $stackUtils.mergeCrossOriginUserInvocationStack(userInvocationStack, cy.state('originUserInvocationStack'))
      }

      callback(chainer, userInvocationStack, args, privilegeVerification, true)

      // if we are in the middle of a command
      // and its return value is a promise
      // that means we are attempting to invoke
      // a cypress command within another cypress
      // command and we should error
      const ret = cy.state('commandIntermediateValue')

      if (ret) {
        const current = cy.state('current')

        // if this is a custom promise
        if ($utils.isPromiseLike(ret) && $utils.noArgsAreAFunction(current.get('args'))) {
          $errUtils.throwErrByPath(
            'miscellaneous.command_returned_promise_and_commands', {
              args: {
                current: current.get('name'),
                called: name,
              },
            },
          )
        }
      }