It depends on the density and thickness of the foam whether the sensor will detect the media surface through the foam. Dry, airy foam does not pose a problem, while very wet, dense foam may affect the sensor performance.