fix: websocket

This commit is contained in:
msojocs 2024-01-01 19:12:04 +08:00
parent 41619f7700
commit 6753c062e7
2 changed files with 34 additions and 0 deletions

24
docs/FixWebSocket.md Normal file
View File

@ -0,0 +1,24 @@
# WebSocket修复
自 nw0.76.0 开始调试器的WebSocket无法建立链接。
## 原因
旧版本似乎不会对websocket请求进行拦截而在某一版本开始chrome支持websocket请求拦截
## 解决
文件路径:`cache/core.wxvpkg.ext/f67cdfd87843382519d9c48d8a0bd4dc.js`
添加以下内容:
```javascript
(this._onBeforeRequest = (e) => {
console.warn('----webview request for:', e)
if (/^wss?:\/\//i.test(e.url)) return void 0; // add
if ("function" == typeof this.onBeforeRequest)
return this.onBeforeRequest(e);
}),
```

View File

@ -125,6 +125,16 @@ else
warn "theme位置未找到"
fi
# fix WebSocket for nw >= v0.76.0
notice "fix WebSocket"
find_result=$( grep -lr "this._onBeforeRequest=e=>{if" "$tmp_dir/core.wxvpkg" )
echo "WebSocket: $find_result"
if [[ -n $find_result ]];then
sed -i 's#this._onBeforeRequest=e=>{if#this._onBeforeRequest=(e)=>{/*for nw >= v0.76.0*/if (/^wss?:\\/\\//i.test(e.url)) return void 0;if#' $find_result
else
warn "WebSocket位置未找到"
fi
# fix update check
notice "fix update check"
sed -i 's#</body><script src=../js/core#</body><script src="../js/unpack/hackrequire/index.js"></script><script src=../js/core#' "$package_dir/html/whatsnew.html"