Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): use wss:// when page is served over HTTPS #391

MergedPatrickBauer(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/391/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

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

  1. Run t3 --host 0.0.0.0 --port 3773
  2. Put it behind an HTTPS reverse proxy (nginx, Tailscale Serve, etc.)
  3. 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.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: f15e2e8d-15c0-49ff-999c-bab10caefdfd

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • ✅ Review completed - (🔄 Check again to review again)
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Post copyable unit tests in a comment

      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
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. hwanseoc(GitHub profile, opens in a new tab)commented

      fixes #328

Sign in to join this conversation.