32

Does socket.io have a client side debug mode where you can literally see everything that the server has sent over to you?

Now you achieve the same effect with the following code:

socket.on('HELLO', function(arg1, arg2) { console.log('HELLO', arg1, arg2) ... 
socket.on('WORLD', function(arg1) { console.log('WORLD', arg1) ... 

It would be really convenient if I can do this easily without putting console.log everywhere.

6 Answers 6

39

Paste this to console, click enter and refresh your page:

localStorage.debug = '*';

To get only debug info with incoming data from socket, paste this instead:

localStorage.debug = 'socket.io-client:socket';
Sign up to request clarification or add additional context in comments.

3 Comments

I have enabled the logs by entering this code into my web browser but now I am not able to disable it. Whenever I start my application, I also see the socket debug logs that I no longer require. How can I remove/disable these socket logs? I am using the socket client in React Native.
just unset the value by localStorage.removeItem('debug') or open some tools you use to run the project and remove debug from local storage, you may try localStorage.debug = '' too
There does not appear to be an option for this if you are using JavaScript modules in the browser since the only ESM version is minified and does not include the debug tooling.
7

You can see it easily in a webkit browser's web inspector (chrome, safari, chromium) To do this

  • right click on the page
  • Go to Inspect element
  • Click on the network tab
  • Reload the page with the network tab opened.
  • You can see all the resources with http get request and their responses getting loaded.
  • Find the first request to the socket.io server.
  • This will get back a list of available message transports.
  • Socket.io client will pick up the first available transport. (Websockets if supported by your browser)
  • Now in the second request you will see all the responses coming back in a 'frames' tab.

Reference image for web inspector

Comments

3

Since version 1.0 of Socket.io you can set "debug" property in your localStorage to "*". Then you will get all client logs. You can even filter, because it uses https://github.com/visionmedia/debug under the hood. It is all nicely documented here: http://socket.io/docs/logging-and-debugging/

1 Comment

documentation is not that nice. If you want only see those lines with new data coming from socket, set debug flag to "socket.io-client:socket". I hope this may help as example of filters (mentioned in docs w/o example).
2

If you're on Nodejs, place this code at top of the script:

process.env.DEBUG="*"

const io = require('socket.io-client')

...

OS's terminal "set" doesn't always work.

Comments

1

If you are on command prompt, enter the following 2 commands :

set DEBUG=* node yoursocketioprogram.js

Now you will see all the messages in debug() inside socket.io-client

Comments

0

It seems it's not currently possible without logging them manually as you've described.

I have posted an issue in Socket.io-client — GitHub regarding this. (https://github.com/LearnBoost/socket.io-client/issues/460).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.