From 5ba83f3d56dc898728e3e6429344ec171348ebc8 Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Sat, 21 Sep 2024 09:08:45 +0000 Subject: [PATCH] web/polyfills: add polyfill for AbortSignal.timeout --- web/src/lib/polyfills.ts | 1 + web/src/lib/polyfills/abortsignal-timeout.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 web/src/lib/polyfills/abortsignal-timeout.ts diff --git a/web/src/lib/polyfills.ts b/web/src/lib/polyfills.ts index b5917b5c..621c9b2b 100644 --- a/web/src/lib/polyfills.ts +++ b/web/src/lib/polyfills.ts @@ -1 +1,2 @@ import "./polyfills/user-activation"; +import "./polyfills/abortsignal-timeout"; diff --git a/web/src/lib/polyfills/abortsignal-timeout.ts b/web/src/lib/polyfills/abortsignal-timeout.ts new file mode 100644 index 00000000..8d9b3c66 --- /dev/null +++ b/web/src/lib/polyfills/abortsignal-timeout.ts @@ -0,0 +1,10 @@ +import { browser } from "$app/environment"; + +if (browser && 'AbortSignal' in window && !window.AbortSignal.timeout) { + window.AbortSignal.timeout = (milliseconds: number) => { + const controller = new AbortController(); + setTimeout(() => controller.abort("timed out"), milliseconds); + + return controller.signal; + } +}