Revised answer:
Upon further investigation into the issue, I have identified some potential solutions.
It appears that Samsung Internet (similar to Chrome) does not support unsecure websocket (ws) connections to localhost, only secure wss connections. To resolve this, you may need to configure a TLS certificate for your local web/websocket server. On the other hand, Firefox should be able to connect without any issues.
Another possible cause for the error could be port congestion, where another application running on your system is also using port 3000. In such cases, either terminating the conflicting process or changing the port configuration can help alleviate the issue.
You can verify if the changes work by testing the code with the following modification:
// Original line
new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr')
// Replace it with the specific URL and port that corresponds to your app
new WebSocket("ws://localhost:3000")