DEV Community

Akira
Akira

Posted on

1

How to disconnect WebSocket from Chrome Developer tool

Sometimes, you may need to test how your application behaves when a WebSocket connection is disconnected. Here’s a step-by-step guide to disconnecting a WebSocket via the Chrome Console.

First, enter queryObjects(WebSocket) in the Chrome Console to retrieve the WebSocket object.

websocket object

Next, right-click on the WebSocket object, select Store as global variable from the modal that appears.

right-click modal

This action will store the WebSocket object in a temporary variable, typically named temp1.

variable which stores the websocket object

Finally, to close the WebSocket connection, use the command temp1.close(). This will disconnect the WebSocket, allowing you to observe your application’s response to the disconnection.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay