Is there a way to block this at the browser level? Ex: block access to localhost for all domains (except from localhost itself)?
Ublock allows you to block websocket requests. eg. *$websocket will block all websocket connections. You probably want to operate on a whitelist on a site by site basis. Blocking localhost or 127.0.0.1 isn't reliable because sites can use dns rebinding attacks to bypass your filters.
*$websocket
Tested with https://websocketstest.com/