PWS (v7.0.0) is a drop-in replacement for the browser WebSocket API that adds automatic reconnection with exponential backoff (max 5 min) and configurable ping timeout to detect half-open connections. It works in both browsers and Node.js (requires the 'ws' library). Unlike alternatives like reconnecting-websocket, PWS closely mimics the standard WebSocket interface and triggers reconnect on browser 'online' events. Released by porsager with regular updates.
npm install pwsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows browser usage with PersistentWebSocket class, including onopen, onmessage, and onerror events.
Use PWS(url, WebSocket) without 'new'.
Use import PWS from 'pws' or import { PersistentWebSocket } from 'pws'.Pass options as second argument: new PersistentWebSocket(url, { pingTimeout: 30000 }).Upgrade to latest version and review API changes.
Remove 'new': const ws = PWS(url, WebSocket);
Run 'npm install pws' or check spelling.
Add import: import { PersistentWebSocket } from 'pws';Install 'ws' package: npm install ws, then require it and pass as second argument to PWS factory.