I've found AVIF to be very effective at screenshots with lossy compression.
Text has lots of edges, hard transitions between bright and dark areas. So text requires lots of high-frequency detail, and JPEG adds a lot ringing as it bounces off all those lines and curves.
AVIF seems to follow contours, so it does a good job with line art.
Otherwise, it's hard to beat the Mozilla JPEG encoder.
JPEG XL can represent lossless images that exceed the limits of human vision. I don't expect it to replace FITS for astronomical images, but the future is weird.
(Super huge thanks to Jake Archibald for the SVGOMG web app. Which is also fantastic for line art.
https://jakearchibald.github.io/svgomg/
Squoosh is a web app front end to various image encoders
)
JXL encoder is just very unoptimized, so lossy screenshot is currently pretty bad