Skip to content

Commit 6f78e52

Browse files
committed
fix: abort controller fallback
1 parent d1c4a67 commit 6f78e52

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export async function getLinkPreview(
404404
}
405405

406406
const timeout = options?.timeout ?? 3000; // 3 second timeout default
407-
const controller = new (AbortController || AbortControllerPolyfill)();
407+
const controller = createAbortController();
408408
const timeoutCounter = setTimeout(() => controller.abort(), timeout);
409409

410410
const fetchOptions = {
@@ -488,3 +488,10 @@ export async function getPreviewFromContent(
488488

489489
return parseResponse(response, options);
490490
}
491+
492+
493+
function createAbortController(): AbortController | AbortControllerPolyfill {
494+
return typeof AbortController == 'undefined'
495+
? new AbortControllerPolyfill()
496+
: new AbortController();
497+
}

0 commit comments

Comments
 (0)