diff --git a/.changeset/lemon-bags-tan.md b/.changeset/lemon-bags-tan.md new file mode 100644 index 00000000000..6e0b3d3d2ca --- /dev/null +++ b/.changeset/lemon-bags-tan.md @@ -0,0 +1,5 @@ +--- +"@atproto/common-web": patch +--- + +ponyfill URL.canParse diff --git a/packages/common-web/src/did-doc.ts b/packages/common-web/src/did-doc.ts index fb45010e8cc..d96eb8acf52 100644 --- a/packages/common-web/src/did-doc.ts +++ b/packages/common-web/src/did-doc.ts @@ -145,13 +145,25 @@ const validateUrl = (urlStr: string): string | undefined => { return undefined } - if (!URL.canParse(urlStr)) { + if (!canParseUrl(urlStr)) { return undefined } return urlStr } +const canParseUrl = + URL.canParse ?? + // URL.canParse is not available in Node.js < 18.17.0 + ((urlStr: string): boolean => { + try { + new URL(urlStr) + return true + } catch { + return false + } + }) + // Types // --------