From 6753c062e7a15a89bb05197e9f318c647c62742f Mon Sep 17 00:00:00 2001 From: msojocs Date: Mon, 1 Jan 2024 19:12:04 +0800 Subject: [PATCH] fix: websocket --- docs/FixWebSocket.md | 24 ++++++++++++++++++++++++ tools/fix-core.sh | 10 ++++++++++ 2 files changed, 34 insertions(+) create mode 100644 docs/FixWebSocket.md diff --git a/docs/FixWebSocket.md b/docs/FixWebSocket.md new file mode 100644 index 0000000..451bc2a --- /dev/null +++ b/docs/FixWebSocket.md @@ -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); + }), +``` \ No newline at end of file diff --git a/tools/fix-core.sh b/tools/fix-core.sh index 7e82a54..1099812 100755 --- a/tools/fix-core.sh +++ b/tools/fix-core.sh @@ -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#