Integrated photonics facilitates extensive control over fundamental light–matter interactions in manifold quantum systems including atoms1, trapped ions2,3, quantum dots4 and defect centres5. Ultrafast electron microscopy has recently made free-electron beams the subject of laser-based quantum manipulation and characterization6–11, enabling the observation of free-electron quantum walks12–14, attosecond electron pulses10,15–17 and holographic electromagnetic imaging18. Chip-based photonics19,20 promises unique applications in nanoscale quantum control and sensing but remains to be realized in electron microscopy. Here we merge integrated photonics with electron microscopy, demonstrating coherent phase modulation of a continuous electron beam using a silicon nitride microresonator. The high-finesse (Q0 ≈ 106) cavity enhancement and a waveguide designed for phase matching lead to efficient electron–light scattering at extremely low, continuous-wave optical powers. Specifically, we fully deplete the initial electron state at a cavity-coupled power of only 5.35 microwatts and generate >500 electron energy sidebands for several milliwatts. Moreover, we probe unidirectional intracavity fields with microelectronvolt resolution in electron-energy-gain spectroscopy21. The fibre-coupled photonic structures feature single-optical-mode electron–light interaction with full control over the input and output light. This approach establishes a versatile and highly efficient framework for enhanced electron beam control in the context of laser phase plates22, beam modulators and continuous-wave attosecond pulse trains23, resonantly enhanced spectroscopy24–26 and dielectric laser acceleration19,20,27. Our work introduces a universal platform for exploring free-electron quantum optics28–31, with potential future developments in strong coupling, local quantum probing and electron–photon entanglement.