Skip to content

Commit c87c038

Browse files
Copilot0x2E
andauthored
Fix Safari iOS URL.parse compatibility issue causing TypeError when opening news articles (#188)
* Initial plan * Initial exploration of issue #186 - Safari iOS URL.parse compatibility Co-authored-by: 0x2E <[email protected]> * Fix Safari iOS URL.parse compatibility issue #186 Co-authored-by: 0x2E <[email protected]> * Remove frontend/package-lock.json from PR as requested Co-authored-by: 0x2E <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: 0x2E <[email protected]>
1 parent 650554c commit c87c038

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

frontend/src/lib/utils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ export function debounce(func: Function, wait: number): EventListener {
2323
export function tryAbsURL(url: string, base?: string): string {
2424
if (!url) return url;
2525

26-
let parsed = URL.parse(url, base);
27-
if (!parsed) {
26+
try {
27+
const parsed = new URL(url, base);
28+
return parsed.href;
29+
} catch {
2830
if (url.startsWith('//')) {
29-
url = 'https:' + url;
31+
try {
32+
const parsed = new URL('https:' + url, base);
33+
return parsed.href;
34+
} catch {
35+
return url;
36+
}
3037
}
31-
parsed = URL.parse(url, base);
38+
return url;
3239
}
33-
34-
return parsed?.href || url;
3540
}

0 commit comments

Comments
 (0)