diff --git a/main.py b/main.py
index d89c250..118c5b1 100644
--- a/main.py
+++ b/main.py
@@ -168,38 +168,11 @@ def api_scan(request: Request):
@app.get("/browse", response_class=HTMLResponse)
def browse(request: Request, ip: str, port: int = 80):
- """Wrapper page that loads the proxied LAN device in an iframe."""
+ """Redirect straight into the full-page proxy (no iframe)."""
if not get_session(request):
return RedirectResponse("/login")
scheme = "https" if port in (443, 8443, 8006) else "http"
- proxy_root = f"/proxy/{scheme}/{ip}/{port}/"
- return HTMLResponse(f"""
-
-
-
- Browse {ip}:{port} — TailScan
-
-
-
-
-
← TailScan
-
|
-
{scheme}://{ip}:{port}
-
(proxied via exit node)
-
-
-
-""")
+ return RedirectResponse(f"/proxy/{scheme}/{ip}/{port}/")
@app.api_route("/proxy/{scheme}/{ip}/{port}/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
@@ -240,25 +213,86 @@ async def proxy(request: Request, scheme: str, ip: str, port: int, path: str):
content_type = resp.headers.get("content-type", "")
content = resp.content
- # Rewrite absolute URLs in HTML so links stay proxied
+ # Rewrite HTML: fix links + inject JS interceptor for SPA navigation
if "text/html" in content_type:
proxy_base = f"/proxy/{scheme}/{ip}/{port}"
+ origin = f"{scheme}://{ip}:{port}"
text = content.decode("utf-8", errors="replace")
- # href="/foo" → href="/proxy/http/ip/port/foo"
+
+ # Rewrite root-relative href/src/action="/path" → proxied
text = re.sub(
- r'(href|src|action)=["\']/((?!proxy/|/).*?)["\']',
- lambda m: f'{m.group(1)}="{proxy_base}/{m.group(2)}"',
+ r'(href|src|action)=(["\'])/(?!/)',
+ lambda m: f'{m.group(1)}={m.group(2)}{proxy_base}/',
text
)
- # absolute http://ip:port/path → proxied
+ # Rewrite absolute origin URLs → proxied
text = re.sub(
- rf'{scheme}://{re.escape(ip)}:{port}(/[^"\']*)?',
+ rf'{re.escape(origin)}(/[^"\'> ]*)?',
lambda m: f"{proxy_base}{m.group(1) or '/'}",
text
)
+
+ # Inject JS interceptor before (or at top of body) to handle:
+ # - fetch() / XHR with root-relative or absolute URLs
+ # - window.location / history.pushState navigation
+ # - dynamically inserted /