A technique for measuring wavefront errors in an optical system that receives light from a spatially extended, arbitrarily structured, incoherent source is described. If we place a suitable transparent mask at an image plane of the system, the structure in the light source serves as a tracer for wavefront errors. The slope of the wavefront error can be detected in the form of intensity variations in a pupil image that follows the mask. One-dimensional numerical simulations of the method as well as the analytical treatment of the proposed principle are presented. The application of the technique as a wavefront sensor in an adaptive optical system for solar observations, in which aberrations are caused by atmospheric turbulence in the light path, is discussed as an example.