How do I simulate a websocket disconnect manually? I'm trying to test websocket reconnect logic, and I have no way of doing this other than waiting for the browser's 10 minute websocket timeout.
How do I simulate a websocket disconnect manually? (Firefox or Chrome dev tools)
7k views Asked by dessalines At
2
There are 2 answers
0
berhir
On
I found a solution to test this here: https://stackoverflow.com/a/59916046/2929675
Before the WebSocket connection gets opened, you must execute this script to monkey patch the browsers WebSocket function:
const sockets = [];
const nativeWebSocket = window.WebSocket;
window.WebSocket = function(...args){
const socket = new nativeWebSocket(...args);
sockets.push(socket);
return socket;
};
Now you have access to all WebSocket connections via the sockets array. And when you want to trigger a reconnect, you can call
sockets[0].close();
using the index of the connection you want to close.
It's a bit hacky, but it's the best solution I have found so far.
It looks like there is also some progress in the chromium issue to support this in the dev tools: https://bugs.chromium.org/p/chromium/issues/detail?id=423246
Related Questions in WEBSOCKET
- Resolving ElephantIO ServerConnectionFailureException: Error establishing connection to server
- Django socketio process
- How to decode audio stream using tornado websocket?
- Java and React WebSocket - Error Connection
- Socket.io nodejs server .NET connection
- Troubleshooting WebSocket 502 Error in Python Code
- Getting an error in Socket.io wordle project
- Best practices with realtime data / websockets. Send vs. revalidate data
- My socket.io web socket application is not sending data to some users
- Android 13 & 14 seem to close WebSocket connection, if i put app in background, after ~20s
- Audio bytes chunks getting corrupted during streaming using Django and Websockets
- Odoo live chat not working when using apache reverse proxy
- websocket Fatal error message stating "Failed to listen on tcp://0.0.0.0:8080: Address already in use
- Stomp connection using JWT token in Python
- Symphony Fintech (XTS) market-data socket data integration in PyQt6 using python3
Related Questions in GOOGLE-CHROME-DEVTOOLS
- Is it possible to manipuate 3rd party Chrome Extensions Network Reqeuests?
- How do i load a Chrome extension when manifest.json is in a subfolder (app) instead of main folder
- Reading the user's console errors from a chrome extension
- Chrome Selenium CDP Bidi API - Next Commands sended to Target Session have no effect while the initial one does work
- When I'm typing an Xpath or CSS selector in the console why won't matching results appear while typing? Results only appear after pressing Enter
- JS throttling with Chrome Extension
- How can I disable livewire dev tools on production environment?
- Chrome Devtools how to send/edit websocket messages in binary?
- How do I use Chrome DevTools to remove the script that adds "promoted" labels to LinkedIn job postings?
- Interpreting Chrome memory tool's results for a memory leak?
- Google Chrome 123 Update: Chrome is making preflight check for document/Redirect type GET request
- Chrome DevTools font has been changed to Monospace after update
- Not able to add a custom header using declarative_net_request and rule resources in chrome extension
- Issue with AJAX Request Preview in Chrome DevTools Version 123.0.6312.59
- How do I dig deeper in the Performance panel for a function call that consumes a long time but 90% of the time was just waiting?
Related Questions in FIREBUG
- Chrome devtools, remember expanded element and selection on refresh
- Is there a way to make chrome devtools undetectable?
- Disabled form input and user modification using developer console
- Is there any way to get a Firefox version with FireBug and FirePath
- Ignore debugger; statement but still evaluate my own breakpoints in dev-tools/IDE
- console.log/warn/error - native, vanilla JavaScript more performant alternative?
- Old FireBug required in Firefox 49.0.1
- What browser can update the webpage live as I edit HTML in the inspector?
- Datatable ajax error without error detail
- Old Firebug suggest html class and ID but new built in firebug don't
- What happened to firebug? Is there a good replacement?
- How do I simulate a websocket disconnect manually? (Firefox or Chrome dev tools)
- Why there is long pause between Js file download and ajax request it consist?
- PHP How to log to "FireFox Quantum" Developer Web Console from php script
- Can we install Firebug for Chrome?
Related Questions in FIREFOX-DEVELOPER-TOOLS
- In my range slider the track is coming over on thumb while working fine on Chrome
- Facing the error: "binary is not a Firefox executable" when using Selenium with Firefox WebDriver
- How to break on a *later* subtree modification in DevTools on github.com
- Is there any way to save in PDF automatically the website with window.print() or Ctrl+P in Firefox?
- Firefox developer tools Inspector advanced preferences
- Firefox devtools not showing request details
- Why does Firefox delete part of my CSS selector despite that it actually matches something in the HTML when testing it in the web inspector?
- Restore font size on Firefox developer tool
- Vulnerability: Password Exposed
- Can I show the responses to all the requests at once in the Firefox Network Monitor?
- How to locate the js statement that jumps to another web page?
- Identifying the domains implemented in Firefox RDP which is subset of the Chrome DevTools Protocol (CDP)
- How to force Chrome to use HTTP/1.1 for a particular Website?
- How to intercept an eventhandler in javascript?
- Creating a tab from inside a devtools extension returns successfully with a tab id of -1
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
With SockJS and Stomp:
Closing the underlying socket with:
triggered the stompClient's error handler as if the connection had been interrupted.