Registry / security / react-native-websocket-self-signed

react-native-websocket-self-signed

JSON →
library0.5.0jsnpmunverified

A React Native package (v0.5.0, released under MIT) that enables WebSocket (wss://) connections with self-signed SSL/TLS certificates by bypassing certificate validation. It uses a singleton pattern to manage connections and supports multiple concurrent WebSocket instances. Alternative to manually patching native modules for development or internal apps where strict certificate verification is not required. Includes TypeScript declarations. WARNING: Bypassing SSL validation exposes to MITM attacks and must never be used in production.

npm install react-native-websocket-self-signed
INSTALL
IMPORT
SIG · REACT-NATIVE-WEBSO
R
react-native-websocket-self-signed
securityjavascriptv0.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import WebSocketWithSelfSignedCert from 'react-native-websocket-self-signed'
✗ const WebSocketWithSelfSignedCert = require('react-native-websocket-self-signed')
ESM default import; CommonJS require may not work in some bundlers. TypeScript types are included.
WebSocketWithSelfSignedCert
✓ import WebSocketWithSelfSignedCert from 'react-native-websocket-self-signed'
The package exports a class as default; named import 'WebSocketWithSelfSignedCert' does not exist (use default import).
getInstance
✓ const ws = WebSocketWithSelfSignedCert.getInstance(url)
Static factory method to get or create a WebSocket instance per URL. Available since v0.4.0.

Shows how to import, create a WebSocket instance for a URL (singleton per URL), and handle events.

import WebSocketWithSelfSignedCert from 'react-native-websocket-self-signed'; const url = 'wss://localhost:8443'; const ws = WebSocketWithSelfSignedCert.getInstance(url); ws.onopen = () => { console.log('Connected to', url); ws.send('Hello, server!'); }; ws.onmessage = (event) => { console.log('Received:', event.data); }; ws.onerror = (error) => { console.error('WebSocket error:', error.message); }; ws.onclose = (event) => { console.log('Connection closed:', event.code, event.reason); };
Debug
Known issues
breakingIn v0.4.0, the API changed from a single connection to multiple connections using getInstance(url). Code using the old global singleton will break.
fix
Update to use WebSocketWithSelfSignedCert.getInstance(url) for each WebSocket URL.
affects: <0.4.0
deprecatedThis package bypasses SSL/TLS certificate validation, which is a security risk.
fix
Do not use in production. Only for development or internal apps where risk is acceptable.
affects: all
gotchaOn iOS, the expo-dev-client network inspector intercepts requests preventing this library from working in dev builds.
fix
Disable network inspector via expo-build-properties plugin in app.json (see README).
affects: all
gotchaOn Android emulator, use wss://10.0.2.2:port instead of localhost to connect to host machine.
fix
Replace localhost with 10.0.2.2 for Android emulator connections.
affects: all
gotchaThe getInstance method may cause race conditions if called before native module is ready (e.g., in component mount before React Native initialization).
fix
Ensure getInstance is called after React Native initialization (e.g., inside useEffect or after app startup).
affects: >=0.4.0
Errors
Common errors & fixes
Error: WebSocket connection to 'wss://...' failed: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be ... which could put your confidential information at risk."
iOS default URLSession does not trust self-signed certificates.
fix
Use this library to bypass validation, or install a proper certificate.
TypeError: Cannot read property 'getInstance' of undefined
CommonJS require() used instead of default import; bundler may not resolve default export correctly.
fix
Use import WebSocketWithSelfSignedCert from 'react-native-websocket-self-signed'
Network request failed - The request timed out.
On Android emulator, using localhost instead of 10.0.2.2.
fix
Replace 'localhost' with '10.0.2.2' in the WebSocket URL.
TypeError: WebSocketWithSelfSignedCert.getInstance is not a function
Trying to use getInstance on older version <0.4.0 where global singleton was used directly.
fix
Update package to v0.4.0+ and use getInstance(url).
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies
reactrequiredpeer dependency required for React Native integration
react-nativerequiredpeer dependency required for React Native native modules
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
react-native-websocket-self-signed — npm install react-native-websocket-self-signed · libregistry