From 8c180b9cfd89a088f90af9effa918c690fa9bb62 Mon Sep 17 00:00:00 2001 From: mmmray <142015632+mmmray@users.noreply.github.com> Date: Sun, 13 Oct 2024 07:22:15 +0200 Subject: [PATCH] Browser Dialer: Revert changes to event listeners (#3906) https://github.com/XTLS/Xray-core/issues/3882#issuecomment-2396167708 This does not fix the linked issue, just a random bug I found. --- transport/internet/browser_dialer/dialer.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/transport/internet/browser_dialer/dialer.html b/transport/internet/browser_dialer/dialer.html index 241d2102..558db627 100644 --- a/transport/internet/browser_dialer/dialer.html +++ b/transport/internet/browser_dialer/dialer.html @@ -24,7 +24,10 @@ // arraybuffer is significantly faster in chrome than default // blob, tested with chrome 123 ws.binaryType = "arraybuffer"; - ws.addEventListener("message", (event) => { + // note: this event listener is later overwritten after the + // handshake has completed. do not attempt to modernize it without + // double-checking that this continues to work + ws.onmessage = function (event) { clientIdleCount -= 1; let [method, url, protocol] = event.data.split(" "); switch (method) { @@ -134,10 +137,10 @@ }; check(); - }); - ws.addEventListener("error", (event) => { + }; + ws.onerror = function (event) { ws.close(); - }); + }; }; let checkTask = setInterval(check, 1000);