Antifogging agents are chemicals that force the tiny droplets of water that make up fog to merge into a transparent sheet. An agent is sprayed as liquid on the lens, and when it dries, it forms a clear film.
Normally, water beads up, but with the film, the beads run together. The water is still there, but you can see through it.
Such agents are surfactants chemicals that lower the surface tension of the liquid with which they are in contact, in this case water. Soap and detergents contain surfactants.
A low-cost emergency substitute for commercial antifogging agents is potato juice. In research on land mine removal at the University of Western Australia, potato juice was tested for use in poor countries to keep blast-protection visors from fogging up. It performed as well as some brand-name products.
The researchers cut a slice from a raw potato, rubbed it generously and evenly onto the inside surface of the visor, then wiped away solids and excess juice with a soft cloth.