We present a method for detecting electromagnetic (EM) modes that couple to a superconducting qubit in a circuit quantum electrodynamics architecture. Based on measurement-induced dephasing, this technique allows the measurement of modes that have a high quality factor (Q) and may be difficult to detect through standard transmission and reflection measurements at the device ports. In this scheme, the qubit itself acts as a sensitive phase meter, revealing modes that couple to it through measurements of its coherence time. Such modes are indistinguishable from EM modes that do not couple to the qubit using a vector network analyzer. Moreover, this technique provides useful characterization parameters including the quality factor and the coupling strength of the unwanted resonances. We demonstrate the method for detecting both high-Q coupling resonators in planar devices as well as spurious modes produced by a 3D cavity.