Skip to content

Commit

Permalink
fix: fix URL.canParse not available
Browse files Browse the repository at this point in the history
Fix ARGOS-BROWSER-BD
  • Loading branch information
gregberge committed Feb 10, 2025
1 parent d289442 commit f4ac861
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion apps/frontend/src/pages/Build/BuildDetailToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const BuildDetailToolbar = memo(function BuildDetailToolbar({
<MediaTypeIndicator mediaType={mediaType} className="size-4" />
)}
{viewport && <ViewportIndicator viewport={viewport} />}
{url && URL.canParse(url) ? (
{url && checkIsValidURL(url) ? (
<UrlIndicator
url={url}
previewUrl={previewUrl}
Expand Down Expand Up @@ -181,6 +181,25 @@ export const BuildDetailToolbar = memo(function BuildDetailToolbar({
);
});

/**
* Check if a URL can be parsed.
*/
function checkIsValidURL(url: string) {
// If browser does not support URL, return false.
if (typeof URL !== "function") {
return false;
}
// If browser does not support URL.canParse, try to parse the URL.
if (typeof URL.canParse !== "function") {
try {
new URL(url);
} catch {
return false;
}
}
return URL.canParse(url);
}

function resolveDiffMetadata(diff: Diff) {
return (
(diff.status === ScreenshotDiffStatus.Removed
Expand Down

0 comments on commit f4ac861

Please sign in to comment.