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 <29594728+0x2E@users.noreply.github.com>

* Fix Safari iOS URL.parse compatibility issue #186

Co-authored-by: 0x2E <29594728+0x2E@users.noreply.github.com>

* Remove frontend/package-lock.json from PR as requested

Co-authored-by: 0x2E <29594728+0x2E@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: 0x2E <29594728+0x2E@users.noreply.github.com>
This commit is contained in:
Copilot
2025-07-28 00:35:41 +08:00
committed by GitHub
parent 650554cf16
commit c87c038278
+11 -6
View File
@@ -23,13 +23,18 @@ export function debounce(func: Function, wait: number): EventListener {
export function tryAbsURL(url: string, base?: string): string {
if (!url) return url;
let parsed = URL.parse(url, base);
if (!parsed) {
try {
const parsed = new URL(url, base);
return parsed.href;
} catch {
if (url.startsWith('//')) {
url = 'https:' + url;
try {
const parsed = new URL('https:' + url, base);
return parsed.href;
} catch {
return url;
}
}
parsed = URL.parse(url, base);
return url;
}
return parsed?.href || url;
}