We propose to use laser spectroscopy of ultracold molecules to establish improved limits on the time independence of electron-to-nuclear and nuclear-nuclear mass ratios by comparing, via an optical frequency comb, the frequencies of suitable sets of transitions in the ground electronic state. Hydrogen molecular ions trapped in a radiofrequency trap, sympathetically cooled by atomic ions, are identified as an accessible system. We show that the dipole-allowed rovibrational transition frequencies of
HD+ are suitable probes for a time dependence of
me∕mp or
mp∕md. Separate bounds on the time independence of these constants can be obtained from a comparison of
HD+ and
H2+ transitions frequencies. Spectroscopy of single molecular ions via a quantum jump method is proposed as an approach toward ultrahigh precision.