Both are common during a cardiac arrest and resuscitation. When the heart stops, muscles throughout the body relax, including those that normally keep the stomach contents down. Chest compressions can also push air into the stomach, and the pressure of CPR itself can trigger vomiting. Foam around the mouth happens when air mixes with saliva and fluid in the airway as the person gasps or as compressions move air in and out of the lungs.
Neither vomiting nor foaming means anything was done wrong, and neither caused the cardiac arrest. They are distressing to see, but they are normal bodily responses to the heart stopping. If you witnessed this and the images stay with you, that is a normal reaction to an abnormal event, and support is available.