Skip to content

Commit 11b14fc

Browse files
authored
Merge pull request #162 from Birowsky/fallback-to-polyfill
fallback to abort-controller polyfill
2 parents 55353ce + 6f78e52 commit 11b14fc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cheerio from "cheerio";
22
import { fetch } from "cross-fetch";
3-
import AbortController from "abort-controller";
3+
import AbortControllerPolyfill from "abort-controller";
44
import urlObj from "url";
55
import { CONSTANTS } from "./constants";
66

@@ -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();
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)