javascript - Vite.js (Vue): Unwanted Page Reload Happens Only On Samsung Internet - Stack Overflow

I have a weird problem with Vite.js and it only happens on Samsung Internet when I'm on developmen

I have a weird problem with Vite.js and it only happens on Samsung Internet when I'm on development server...

Problem: page reloads automatically 3 seconds in a loop and I don't set nor write any intervals... the page reload happens at browser level.

These are unwanted reloads and I want to get rid of them.

Any Idea why it happens?

I have a weird problem with Vite.js and it only happens on Samsung Internet when I'm on development server...

Problem: page reloads automatically 3 seconds in a loop and I don't set nor write any intervals... the page reload happens at browser level.

These are unwanted reloads and I want to get rid of them.

Any Idea why it happens?

Share Improve this question asked Feb 7, 2022 at 11:44 Hasan ParastehHasan Parasteh 5498 silver badges33 bronze badges 3
  • 1 @tony19 first I installed the app using: npm init vite@latest my-vue-app -- --template vue-ts and then run npm run dev -- --host. After that navigate to the network IP address via a Samsung Mobile Browser. I tested in latest 3 version of Samsung Internet Browser and it was there... – Hasan Parasteh Commented Feb 7, 2022 at 13:26
  • 1 @Ehrlich_Bachman I just created the vite application and changed nothing..I created an issue in vite.js github too... – Hasan Parasteh Commented Feb 7, 2022 at 13:27
  • 1 @mahatmanich I found the problem and it was not for Samsung Internet...I ran a debugger on Samsung Internet and the problem as exactly like this: client.ts:28 WebSocket connection to 'ws://<local-ip>:3000/' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR – Hasan Parasteh Commented Feb 10, 2022 at 10:25
Add a ment  | 

2 Answers 2

Reset to default 4 +100

It seems Samsung Internet browser disallows insecure websockets.

A workaround is to enable HTTPS in Vite with server.https, so that it creates a secure Websocket:

// vite.config.js
import { defineConfig } from 'vite'

export default defineConfig({
  ⋮
  server: {
    https: true,
  }
})

Verified with Vite 2.7.13 and Samsung Internet 16.0.6.23

Edited asnwer:

Ok so, I looked closer to this problem and I found some possible solutions.

Samsung Internet (same as Chrome) doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server). However the same should work fine with Firefox.

Another reason for this error could be "overloading" the same port. Maybe other app, which you are running, uses port 3000. The solution would be to stop that process or again change the port.

Testing solution: Does the code works if you do this?

// Original line
new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr')


// Replace with exact url with port that you are running the app
new WebSocket("ws://localhost:3000")

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744208539a4563224.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信