Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayBuffer/WebSocket issue with version 3.2.2 (unexpected base64 conversion!) #447

Closed
epeios-q37 opened this issue Aug 10, 2024 · 2 comments

Comments

@epeios-q37
Copy link

epeios-q37 commented Aug 10, 2024

Hello,

The below file opens a WebSocket on a site (wss://echo.websocket.org) which simply echoes what is send, and sends a text as ArrayBuffer.
When using version 3.2.1, the response is a blob containing the sent text, which is the expected behavior.
When using version 3.2.2 , the response is a text which is the sent text encoded in base64, which is wrong.

Below the steps to reproduce the issue.

  • Create an HTML file with below content;
  • open this file in a web browser;
  • open the JS console (the browser one or the eruda one);
  • you should see, as expected:
Blob (correct):  This is the text used for testing!

Now:

  • change in the file at line 5 3.2.1 to 3.2.2 (switching to the latest version);
  • reload the file in the web browser;
  • reopen, if needed, the JS console;
  • you will see:
Text (wrong):  VGhpcyBpcyB0aGUgdGV4dCB1c2VkIGZvciB0ZXN0aW5nIQ==
Base64 decoded above text:  This is the text used for testing!

Maybe the problem only affects ArrayBuffer or only WebSocket, but I couldn't reproduce the problem without involving both (I very rarely use JS)...

The bug_eruda.html file (HTML files can not be joined to issues ):

<!DOCTYPE html>
<html>
  <head>
    <!-- Version 3.2.1 works, version 3.2.2 fails! -->
    <script src="https://cdn.jsdelivr.net/npm/eruda@3.2.1/eruda.min.js"></script>
    <script>
      function test() {
        const text = "This is the text used for testing!"

        const enc = new TextEncoder();
        const ws = new WebSocket("wss://echo.websocket.org");

        function logBlob(blob) {
          const reader = new FileReader()

          function onLoadEnd (e) {
            reader.removeEventListener('loadend', onLoadEnd, false)
            console.log("Blob (correct): ", reader.result);
          }

          reader.addEventListener('loadend', onLoadEnd, false)
          reader.readAsText(blob)
        }

        ws.onmessage = function (event) {
          if ( event.data.type === "")
            logBlob(event.data);
          else if ( !event.data.startsWith("Request")) {  // To skip the first response of 'echo.websocket.org'.
            console.log("Text (wrong): ", event.data);
            console.log("Base64 decoded above text: ", atob(event.data));
           }
        }

        ws.onopen = function () {
          ws.send(enc.encode(text));
        };
      }
    </script>
    </head>
  <body onload="eruda.init();test();">
  </body>
</html>
@surunzi
Copy link
Member

surunzi commented Aug 10, 2024

v3.2.3 fixes this issue.

@epeios-q37
Copy link
Author

Thanks for this quick fix!

@surunzi surunzi closed this as completed Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants