Further editing about other causes of oil foaming
It never occurred to me to add reasons other than lecithin leaching into oil as a cause of foaming. I hope most people don't re-use their oil for frying more than a few times since it's harmful to a person's health which I'll explain a little. Since this site isn't about health but cooking, it'll be brief.
Frying, in itself, chemically changes oil. Water, plus other components in the food (what they are isn't listed), can cause 'soaps' to form, which causes foaming.
A second effect is oxidation leading to saponification. From Surfactant Science and Technology, page 261
...polyunsaturated acids such as linoleic and linolenic acids are particularly susceptible to oxidation, introducing peroxide and hydroxyl groups that enhance the amphiphilic character of the materials with the observed results.
(Amphiphilic means a molecule having one end that can attach to water and the other end to fats like soap does.)
Another contributing factor is oil polymerization. When fats are subjected to frying temperatures, they'll become polymerized. (Good for seasoning cast irons pans but but for our health.) Fats that at present high in polyunsaturated fatty acids are more prone to this. Polymerized fats are thicker (more viscous) and will tend to form more stable foams during frying. The more the same fat's been used for frying, the more polymerized it will be and therefore foam more.
I remember reading why food particles can also increase foaming but can't find it now. (Doesn't help I've had a headache for 2 days.)
While the saponification of frying oil (formation of 'soaps' though it's not the same type as soaps used in cleaning) might seem unpalatable, what's important is that using old oil that's been subjected to frying temperatures repeatedly causes free radicals to form. Most people understand their harmful effects. I'd suggest if your oil starts foaming and you didn't add lecithin to your oil, by intention or through leaching from egg-containing batter, discard it or recycle it at an appropriate depot.
Personal experience
I didn't think to include this but it may be of some value. I use liquid sunflower lecithin in baking and mix a small amount into regular oil specifically for greasing baking pans to allow baked goods to lift easily without sticking. I've occasionally added a little of this oil to a frying pan with regular oil for frying when I want a crispy exterior but absolutely no sticking of food to pan. At such times, the oil will foam if I add a bit too much. It's how I first learned of this. The more lecithin there was, the more the oil foamed. It's easily tested in your own kitchen.
Edited to include links
I actually thought it was fairly well known that foaming when frying was caused by lecithin in the oil but it seems it isn't. Here are some links about this.
...frying a comestible in a frying medium which comprises an oil or fat and an amount of an emulsifier effective to foam the fat or oil during frying. The amount of fat or oil and emulsifier need be present in an amount effective to foam the fat or oil at a level sufficient to cook the comestible in the foaming frying medium. The emulsifier may be incorporated into the frying medium as part of a dry coating mix which is coated onto the comestible prior to frying.
Appropriate emulsifiers include citric acid esters of mono and diglycerides, phosphated mono and diglycerides, sodium stearyl fumarate and sodium sulfo-acetate derivatives of mono and diglycerides. However, the preferred emulsifier is lecithin (a phospholipid). Lecithin is preferred due to its ability to sustain a desired level of foam for relatively long periods of time while preventing sticking and burning, as well as foaming without substantial splattering.
From Foam frying US 4188410 A
The leaching of lecithin from egg yolk batters and/or doughnut mixes will cause foaming. Moreover phospholipids (lecithins) may cause darkening of the oil at higher frying temperature.
From the book Frying of Food: Oxidation, Nutrient and Non-Nutrient Antioxidants page 255
I'm also including the link that user110084 listed as it was one of the links I'd previously seen.
During egg-frying, phospholipids of the egg migrated to the frying oil. As the results an increase of foaming tendency of the oils were observed. The higher the migration of phospholipids was, the higher the foaming tendency of the oil was. Added soya lecithin or egg yolk lecithin promoted the foaming tendency of oil during heating, ...
From Science of Cookery: Foaming Tendency of Frying Oil by Egg-frying
The foaming action is caused by two reactions working together - lecithin from the batter (containing a whole egg) migrating into the oil during frying and the vigorous bubbling of the oil as moisture present in the food is vaporized.
If you fry a piece of potato in oil, the oil also bubbles vigorously but the bubbles break when they reach the surface. Lecithin, found only in the yolk, not the white, serves to stabilize the bubbles of water vapour for a short while although they will break down after you've finished frying.
Vegetable oils all contain a certain amount of lecithin naturally. The amounts vary and I don't know how much. Lecithin helps prevent splattering when frying but very little is needed. I don't do deep-frying but I'd imagine if one were to fry something that contained water in pure mineral oil (not that it would be edible), it would splatter a lot.
Next time, if you were to use egg white only, you wouldn't find it foaming. If you save and strain your oil for frying again, it would still have enough the lecithin from the batter to foam again.