Skip to content

Detect Tor Browser and route to .onion URLs (even on clearnet frontend)#160

Open
sh1ftred wants to merge 1 commit into
mainfrom
feature/tor-browser-detection
Open

Detect Tor Browser and route to .onion URLs (even on clearnet frontend)#160
sh1ftred wants to merge 1 commit into
mainfrom
feature/tor-browser-detection

Conversation

@sh1ftred
Copy link
Copy Markdown
Contributor

This PR enhances Tor support by detecting Tor Browser specifically, not just when the frontend is accessed via a .onion address.

Changes:

  • Updated utils/torUtils.ts to detect Tor Browser via navigator.userAgent
  • Added manual Tor mode preference with localStorage (getTorModePreference/setTorModePreference)
  • Modified isTorContext() to check in order:
    1. Manual override from localStorage
    2. .onion hostname check (existing behavior)
    3. Tor Browser detection via user agent (new)

Benefits:

  • Users accessing clearnet URL via Tor Browser now get routed to .onion provider endpoints
  • Users can manually override Tor mode via localStorage if needed
  • Maintains backward compatibility with existing .onion hostname detection

Technical Details:

  • Tor Browser user agent contains 'tor' string
  • Added localStorage key 'routstr_tor_mode' for manual override
  • Auto-detects Tor Browser when no manual override is set

Testing:

  • Test with Tor Browser accessing clearnet URL
  • Test with regular browser accessing clearnet URL
  • Test with .onion URL (existing behavior)
  • Test manual override via localStorage

Fixes #159

- Updated utils/torUtils.ts to detect Tor Browser via navigator.userAgent
- Added manual Tor mode preference with localStorage (getTorModePreference/setTorModePreference)
- Modified isTorContext() to check in order: 1. Manual override from localStorage 2. .onion hostname check (existing behavior) 3. Tor Browser detection via user agent (new)

Benefits:
- Users accessing clearnet URL via Tor Browser now get routed to .onion provider endpoints
- Users can manually override Tor mode via localStorage if needed
- Maintains backward compatibility with existing .onion hostname detection

Technical Details:
- Tor Browser user agent contains 'tor' string
- Added localStorage key 'routstr_tor_mode' for manual override
- Auto-detects Tor Browser when no manual override is set

Fixes #159
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying routstr-chat with  Cloudflare Pages  Cloudflare Pages

Latest commit: d876b17
Status: ✅  Deploy successful!
Preview URL: https://ee7f9e40.routstr-chat.pages.dev
Branch Preview URL: https://feature-tor-browser-detectio.routstr-chat.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Route to .onion URLs when using Tor Browser (even on clearnet frontend)

1 participant