Skip to content

Commit 07e4cfb

Browse files
authored
Merge pull request #1562 from argos-ci/fix-can-parse-not-available
fix: fix `URL.canParse` not available
2 parents d289442 + f4ac861 commit 07e4cfb

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

apps/frontend/src/pages/Build/BuildDetailToolbar.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const BuildDetailToolbar = memo(function BuildDetailToolbar({
135135
<MediaTypeIndicator mediaType={mediaType} className="size-4" />
136136
)}
137137
{viewport && <ViewportIndicator viewport={viewport} />}
138-
{url && URL.canParse(url) ? (
138+
{url && checkIsValidURL(url) ? (
139139
<UrlIndicator
140140
url={url}
141141
previewUrl={previewUrl}
@@ -181,6 +181,25 @@ export const BuildDetailToolbar = memo(function BuildDetailToolbar({
181181
);
182182
});
183183

184+
/**
185+
* Check if a URL can be parsed.
186+
*/
187+
function checkIsValidURL(url: string) {
188+
// If browser does not support URL, return false.
189+
if (typeof URL !== "function") {
190+
return false;
191+
}
192+
// If browser does not support URL.canParse, try to parse the URL.
193+
if (typeof URL.canParse !== "function") {
194+
try {
195+
new URL(url);
196+
} catch {
197+
return false;
198+
}
199+
}
200+
return URL.canParse(url);
201+
}
202+
184203
function resolveDiffMetadata(diff: Diff) {
185204
return (
186205
(diff.status === ScreenshotDiffStatus.Removed

0 commit comments

Comments
 (0)