From acc9e18ea3655c11bc473c3a1cb65554d62bd2a8 Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Wed, 12 Nov 2025 12:34:05 -0500 Subject: [PATCH] Try avoiding URL.canParse for older version of Safari --- .../universal/src/lib/php-request-handler.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/php-wasm/universal/src/lib/php-request-handler.ts b/packages/php-wasm/universal/src/lib/php-request-handler.ts index 3d3dfddcdf..dc1023ec97 100644 --- a/packages/php-wasm/universal/src/lib/php-request-handler.ts +++ b/packages/php-wasm/universal/src/lib/php-request-handler.ts @@ -360,7 +360,7 @@ export class PHPRequestHandler implements AsyncDisposable { * @param request - PHP Request data. */ async request(request: PHPRequest): Promise { - const isAbsolute = URL.canParse(request.url); + const isAbsolute = looksLikeAbsoluteUrl(request.url); const originalRequestUrl = new URL( // Remove the hash part of the URL as it's not meant for the server. request.url.split('#')[0], @@ -929,3 +929,22 @@ export function applyRewriteRules(path: string, rules: RewriteRule[]): string { } return path; } + +/** + * Checks if the given URL looks like an absolute URL. + * + * @param url - The URL to check. + * @returns `true` if the URL looks like an absolute URL, `false` otherwise. + */ +function looksLikeAbsoluteUrl(url: string): boolean { + try { + // NOTE: We could just use URL.canParse() but are avoiding it here + // because we've seen users with older Safari versions that don't support it. + // Maybe Playground will break in other ways for them, + // but since this is an easy, low-risk change, let's give it a try. + new URL(url); + return true; + } catch { + return false; + } +}