Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Websocket onerror callback not does not fire vanillajs

My websocket onerror callback does not fire when I disconnect the browser which is on a seperate computer from the websocket server on another computer by turning off the wifi connection and sending a message. The message just doesn't send but no error is fired. Here is my code snippet below.

const logged_in_user_id = 2;

WEBSOCKET_URL = `wss://${window.location.host}/ws/${logged_in_user_id}/`;

const realTimeDataSocket = new WebSocket(WEBSOCKET_URL)

realTimeDataSocket.addEventListener("open", function() {
    console.log("Websocket is opened.");
    realTimeDataSocket.send(JSON.stringify({
        "event": "online",
        "message": "This user is online"
    }))
});

realTimeDataSocket.addEventListener("close", function() {
    console.log("Websocket was closed.");
});

realTimeDataSocket.addEventListener("error", function() {
    console.log("Websocket was closed due to an error.");
});

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!