tor-js-gateway

Tor in the browser

Gateway server for tor-js — providing fast bootstrap data, WebSocket-to-socket relay, and WebRTC peer discovery so browsers can connect to the Tor network directly.

»

Fast Bootstrap

Pre-synced consensus, authority certs, and microdescriptors served as a compressed archive. Clients bootstrap in seconds, not minutes.

WebSocket Relay

Bridges browser WebSocket connections to raw TCP sockets on the Tor network, enabling circuit construction from JavaScript.

Peer Discovery — planned

WebRTC signaling so tor-js clients can relay traffic for each other, enabling access even when gateways are blocked.

Bootstrap from this gateway

Download and parse the Tor consensus directly in the browser:

import { bootstrap } from 'https://this-server/torJsGateway.js'; const { consensus, microdescs, authcerts } = await bootstrap( 'https://this-server/bootstrap.zip.br', (ev) => console.log(ev.type), // optional progress callback ); console.log(`Got ${microdescs.length} relay descriptors`);

Connect to a Tor relay

Open a WebSocket that bridges to a raw TCP socket on a consensus relay:

// Connect to a relay's ORPort via the gateway const ws = new WebSocket('wss://this-server/socket/198.51.100.1:9001'); ws.binaryType = 'arraybuffer'; ws.onopen = () => { // Send raw bytes — the gateway relays them to the TCP socket ws.send(new Uint8Array([0x00, 0x07, ...])); }; ws.onmessage = (ev) => { const data = new Uint8Array(ev.data); // Received raw bytes from the relay };

Only addresses advertised in the current Tor consensus are allowed. The gateway rejects connections to non-relay or private IPs.

Run your own gateway
Install from source (requires Rust 1.89+):
cargo install --path . tor-js-gateway init # create config at ~/.config/tor-js-gateway/config.json5 tor-js-gateway # run in foreground tor-js-gateway install # or install as a systemd service
Manage the service with standard systemd commands:
systemctl --user status tor-js-gateway systemctl --user restart tor-js-gateway journalctl --user -u tor-js-gateway -f