The Network Information API will give you this information, but it's not available in all browsers, and it may be inaccurate. Some Wifi connections are slower than mobile (5G), or a Wifi connection may just be a tethered mobile connection.
Instead, I would recommend either giving the user a setting that they can choose, or making a fetch request and timing the result to see the speed and using that to determine your network bandwidth. If you do that though, remember, the user may change connections anywhere in the middle.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…