From 4d7b7a96b14dd52a320bc10317144a1f98697d80 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Thu, 11 Sep 2025 13:56:34 +0000 Subject: [PATCH] fix(js/algorithms/fast): handle old browsers Closes #1082 Signed-off-by: Xe Iaso --- web/js/algorithms/fast.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/js/algorithms/fast.ts b/web/js/algorithms/fast.ts index 6f3483b4..178cef84 100644 --- a/web/js/algorithms/fast.ts +++ b/web/js/algorithms/fast.ts @@ -5,13 +5,16 @@ interface ProcessOptions { version: string; } +const getHardwareConcurrency = () => + navigator.hardwareConcurrency !== undefined ? navigator.hardwareConcurrency : 1; + export default function process( options: ProcessOptions, data: string, difficulty: number = 5, signal: AbortSignal | null = null, progressCallback?: ProgressCallback, - threads: number = Math.trunc(Math.max(navigator.hardwareConcurrency / 2, 1)), + threads: number = Math.trunc(Math.max(getHardwareConcurrency() / 2, 1)), ): Promise { console.debug("fast algo");