@devries-cameron20 / t3code-1 / commits / 9ca66225ca
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): app loads in browsers without URL.canParse or URL.parse (#36973)

Julius Marminge committed Nov 14, 2026 at 15:45 UTC 9ca66225caba57362e11a36a2f64529d14a71dd4
10 files changed +44 -11
apps/web/src/cloud/t3ConnectState.ts
+3 -2
@@ -3,6 +3,7 @@ import type {
3 RelayManagedEndpoint,
4 RelayManagedEndpointProviderKind,
5 } from "@t3tools/contracts/relay";
6 +import { parseUrl } from "@t3tools/shared/url";
7
8 // Require managed discovery: stale tunnel config after a publish-only switch causes endpoint_provider_not_managed.
9 export function isManagedTunnelActive(
@@ -31,9 +32,9 @@ export function t3ConnectMcpUrl(input: {
32 readonly relayEndpoint: RelayManagedEndpoint | undefined;
33 }): string | null {
34 const url = input.thisMachine
34 - ? URL.parse(`https://${input.tunnelHostname ?? ""}`)
35 + ? parseUrl(`https://${input.tunnelHostname ?? ""}`)
36 : input.relayEndpoint?.providerKind === "cloudflare_tunnel"
36 - ? URL.parse(input.relayEndpoint.httpBaseUrl)
37 + ? parseUrl(input.relayEndpoint.httpBaseUrl)
38 : null;
39 return url?.protocol === "https:" && TUNNEL_HOSTNAME.test(url.hostname)
40 ? `${url.origin}/mcp`
apps/web/src/components/chat/optimisticUserMessages.ts
+2 -1
@@ -1,4 +1,5 @@
1 import type { MessageId, ThreadId } from "@t3tools/contracts";
2 +import { parseUrl } from "@t3tools/shared/url";
3 import * as Effect from "effect/Effect";
4 import * as Schema from "effect/Schema";
5 import { AsyncResult, Atom } from "effect/reactivity";
@@ -125,7 +126,7 @@ class ImagePreloadError extends Schema.TaggedError<ImagePreloadError>()("ImagePr
126 host: Schema.String,
127 }) {
128 static fromUrl(url: string) {
128 - const parsed = URL.parse(url, globalThis.location?.href);
129 + const parsed = parseUrl(url, globalThis.location?.href);
130 return new ImagePreloadError({ protocol: parsed?.protocol ?? "", host: parsed?.host ?? "" });
131 }
132 }
apps/web/src/components/files/office/links.ts
+3 -1
@@ -1,4 +1,6 @@
1 // Adapted from opencode (MIT). Copyright (c) 2025 opencode. See LICENSE.opencode.
2 +import { parseUrl } from "@t3tools/shared/url";
3 +
4 import type { WordLink } from "./word-protocol";
5
6 /** The schemes the host opens outside the app; it refuses any other, such as `javascript:`, `file:` or `tel:`. */
@@ -6,7 +8,7 @@ const schemes = new Set(["http:", "https:", "mailto:"]);
8
9 /** A document's link address, normalized, when the host may open it; undefined otherwise, so the link stays text. */
10 export function externalUrl(href: string) {
9 - const url = URL.parse(href);
11 + const url = parseUrl(href);
12
13 return url && schemes.has(url.protocol) ? url.href : undefined;
14 }
apps/web/src/components/preview/PreviewEmptyState.tsx
+2 -1
@@ -1,4 +1,5 @@
1 import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
2 +import { parseUrl } from "@t3tools/shared/url";
3 import { Globe, History, RadioTower } from "lucide-react";
4
5 import type { BrowserHistoryEntry } from "~/browserHistoryStore";
@@ -30,7 +31,7 @@ export function PreviewEmptyState({
31 environmentId,
32 configuredUrls,
33 });
33 - const recents = recentEntries.filter((entry) => URL.canParse(entry.url)).slice(0, 8);
34 + const recents = recentEntries.filter((entry) => parseUrl(entry.url) !== null).slice(0, 8);
35
36 if (servers.length === 0 && recents.length === 0) {
37 return (
packages/shared/package.json
+4
@@ -563,6 +563,10 @@
563 "types": "./src/markdownMath.ts",
564 "import": "./src/markdownMath.ts"
565 },
566 + "./url": {
567 + "types": "./src/url.ts",
568 + "import": "./src/url.ts"
569 + },
570 "./cloneUrl": {
571 "types": "./src/cloneUrl.ts",
572 "import": "./src/cloneUrl.ts"
packages/shared/src/promptLinks.test.ts
+12
@@ -139,4 +139,16 @@ describe("link round trips", () => {
139 expect(promptLinkAppPath("https://evil.test/new?prompt=hi")).toBeNull();
140 expect(promptLinkAppPath("t3code://app/index.html")).toBeNull();
141 });
142 +
143 + it("maps links in browsers without URL.canParse, such as Safari before 17", () => {
144 + const canParse = URL.canParse;
145 + Reflect.deleteProperty(URL, "canParse");
146 + try {
147 + expect(promptLinkAppPath("https://app.t3.codes/new?prompt=hi")).toBe("/new?prompt=hi");
148 + expect(promptLinkAppPath("https://app.t3.codes/")).toBeNull();
149 + expect(promptLinkAppPath("not a url")).toBeNull();
150 + } finally {
151 + URL.canParse = canParse;
152 + }
153 + });
154 });
packages/shared/src/promptLinks.ts
+4 -3
@@ -1,4 +1,5 @@
1 import { DEFAULT_HOSTED_APP_URL } from "./connectAuth.ts";
2 +import { parseUrl } from "./url.ts";
3
4 export const PROMPT_LINK_MAX_PROMPT_LENGTH = 8_000;
5
@@ -188,8 +189,8 @@ export function promptLinkAppPath(
189 value: string,
190 hostedAppUrl: string = DEFAULT_HOSTED_APP_URL,
191 ): string | null {
191 - if (!URL.canParse(value)) return null;
192 - const url = new URL(value);
192 + const url = parseUrl(value);
193 + if (!url) return null;
194 if (APP_SCHEME.test(url.protocol)) {
195 if (url.host === "new" && (url.pathname === "" || url.pathname === "/")) {
196 return `/new${url.search}`;
@@ -197,7 +198,7 @@ export function promptLinkAppPath(
198 const thread = url.host === "threads" ? THREAD_PATH.exec(url.pathname) : null;
199 return thread ? `/${thread[1]}/${thread[2]}${url.search}` : null;
200 }
200 - if (!URL.canParse(hostedAppUrl) || url.origin !== new URL(hostedAppUrl).origin) return null;
201 + if (url.origin !== parseUrl(hostedAppUrl)?.origin) return null;
202 if (url.pathname === "/new") return `/new${url.search}`;
203 // The web app's own thread route is a link only with a prompt, so reloading a tab never asks.
204 const thread = url.pathname.startsWith("/threads/")
packages/shared/src/remote.ts
+4 -2
@@ -1,5 +1,7 @@
1 import * as Schema from "effect/Schema";
2
3 +import { parseUrl } from "./url.ts";
4 +
5 const PAIRING_TOKEN_PARAM = "token";
6 const HOSTED_PAIRING_HOST_PARAM = "host";
7 const HOSTED_PAIRING_LABEL_PARAM = "label";
@@ -193,8 +195,8 @@ export const buildPairingAppLink = (pairingUrl: string): string =>
195
196 /** Reads the pairing URL from a `t3code://pair` link on any app channel scheme. */
197 export const readPairingAppLink = (value: string): string | null => {
196 - if (!URL.canParse(value)) return null;
197 - const url = new URL(value);
198 + const url = parseUrl(value);
199 + if (!url) return null;
200 if (!APP_LINK_PROTOCOL.test(url.protocol) || url.host !== "pair") return null;
201 if (url.pathname !== "" && url.pathname !== "/") return null;
202 return url.searchParams.get(PAIRING_APP_LINK_PARAM)?.trim() || null;
packages/shared/src/url.ts new
+8
@@ -0,0 +1,8 @@
1 +// `URL.parse` and `URL.canParse` are missing before Safari 17/18, and client code ships unpolyfilled.
2 +export function parseUrl(value: string, base?: string): URL | null {
3 + try {
4 + return new URL(value, base);
5 + } catch {
6 + return null;
7 + }
8 +}
packages/source-control-bitbucket/src/shared/definition.ts
+2 -1
@@ -17,6 +17,7 @@ import {
17 repositoryUrlFromPagePath,
18 projectChangeRequestHost,
19 } from "@t3tools/source-control-core/shared/definition";
20 +import { parseUrl } from "@t3tools/shared/url";
21 import { icon } from "./icon.ts";
22
23 const safeShellArgument = /^[A-Za-z0-9._/@+=,-]+$/;
@@ -115,7 +116,7 @@ export const definition = defineSourceControl({
116 reviewSummaryRequired: () => false,
117 checkoutCommandArgument: () => null,
118 isChangeRequestReference: (reference) => {
118 - const url = URL.parse(reference);
119 + const url = parseUrl(reference);
120 return (
121 url !== null &&
122 isBitbucketHost(url.hostname) &&