There are several ways. You could simply add a surface shader after the water, give it a foam color, and set altitude and fuzzy zone very finely, so only tops will get white. Break or mask it by some foam fractal (like warped voronoi ridges), or more elaborate foam of course.
You could also use the displacement to scalar, add a color adjust and use that to determine what area needs to be white. Use as mask for the surface layer, or through the foam voronoi. But the principle is in fact the same.
The problem with foam is that it may start on the roughest crests, but will linger or float off after that, so to have a very natural flow of foam, you'd need more than just the altitudes. Complicated to get that done, if at all possible. You'd need some sort of delay by frame, and translation built in.