环境是vue2
把老项目的一些功能迁出来独立到新项目 然后就用了新版的cli5和"webpack": "^5.44.0",然后发现一直报错
WebSocketClient.js?5586:13 Mixed Content: The page at xxxxxxx was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'xxxxxxxxxx'. This request has been blocked; this endpoint must be available over WSS.
app.js:546 Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
一顿分析发现是在https页面里用了ws 没用wss 所以浏览器报错了
我没写ws啊 然后又是一顿分析发现
开发时跑vue的时候 本地的服务器还会跑一个websocketClient,这玩意是用来检测你代码改动即时在前端页面生效的,就是这个ws触发了报错 晕 老项目里咋没有触发 奇怪,难道是版本问题?
这次新建项目用了新版的webpack 导致webpack-dev-server的版本也变了 然后可能就是搞出了这个幺蛾子
后来咋解决的:
就无脑在index.HTML加了
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">