Skip to content

Commit 7a06d96

Browse files
authored
fix: Error in environments that do not support URL.canParse (#75)
1 parent 21d7766 commit 7a06d96

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib/seam/connect/seam-http-request.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class SeamHttpRequest<
153153
}
154154

155155
const getUrlPrefix = (input: string): string => {
156-
if (URL.canParse(input)) {
156+
if (canParseUrl(input)) {
157157
const url = new URL(input).toString()
158158
if (url.endsWith('/')) return url.slice(0, -1)
159159
return url
@@ -166,3 +166,13 @@ const getUrlPrefix = (input: string): string => {
166166
`Cannot resolve origin from ${input} in a non-browser environment`,
167167
)
168168
}
169+
170+
// UPSTREAM: Prefer URL.canParse when it has wider support.
171+
// https://caniuse.com/mdn-api_url_canparse_static
172+
const canParseUrl = (input: string): boolean => {
173+
try {
174+
return new URL(input) != null
175+
} catch {
176+
return false
177+
}
178+
}

0 commit comments

Comments
 (0)