You're correct it's possible to have the front end select the right image. That can be done in CSS via "@media(color-gamut: srgb) {}" (p3 and rec2020 are the other supported options) for the different pre-rendered images. In this way you don't need to script anything and the client still only loads the required image.
WebGL/Canvas methods will be possible one day but right now how that will all get implemented is still being worked on. https://github.com/WICG/canvas-color-space/blob/main/CanvasC... the same can be said for general CSS support or any other interface in the browser beyond images and video at the moment https://w3c.github.io/ColorWeb-CG/.