Problem#
When running T3 Code in web mode (t3 --host 0.0.0.0) behind a reverse proxy or Tailscale Serve (HTTPS), the WebSocket connection fails with:
Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
The client always constructs a ws:// URL regardless of whether the page was loaded over HTTP or HTTPS.
Fix#
Derive the WebSocket protocol from window.location.protocol:
`${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.hostname}:${window.location.port}`
Applied in both wsTransport.ts and Sidebar.tsx.
Reproduction#
- Run
t3 --host 0.0.0.0 --port 3773
- Put it behind an HTTPS reverse proxy (nginx, Tailscale Serve, etc.)
- Open the HTTPS URL in Chrome → WebSocket connection blocked
Note
Default to wss on HTTPS pages for WebSocket URLs in Sidebar.getServerHttpOrigin and wsTransport.WsTransport to fix protocol mismatch#
Adjust fallback WebSocket URL selection to use wss when window.location.protocol is https: and ws otherwise, updating Sidebar.getServerHttpOrigin in Sidebar.tsx and the WsTransport constructor in wsTransport.ts.
📍Where to Start#
Start with the WsTransport constructor logic in wsTransport.ts, then review Sidebar.getServerHttpOrigin in Sidebar.tsx.
Macroscope summarized fea0bd8.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
f15e2e8d-15c0-49ff-999c-bab10caefdfdYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip
Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Share your feedback on Discord.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share