From 3e0e9a437ba721d94027408ecc313e6b4a90bc02 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 18 Sep 2026 15:18:26 +0200 Subject: [PATCH] fix(web): retry importScripts NetworkErrors in attempt to mitigate errors loading models A deeper workaround is applied in 19.0 (see for example #16565, #16586) but for 18.0, this is an attempt to bypass the constant issue of models failing to load with Chrome 152 and later versions, by retrying on failure. Relates-to: #13862 (may fix) --- .../worker-thread/src/main/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/index.ts b/web/src/engine/predictive-text/worker-thread/src/main/index.ts index d0676992e0..56831d142b 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/index.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/index.ts @@ -242,13 +242,25 @@ export default class LMLayerWorker { } } - private loadModelFile(url: string) { + private loadModelFile(url: string, tryCount: number = 0) { // The self/global WebWorker method, allowing us to directly import another script file into WebWorker scope. // If built correctly, the model's script file will auto-register the model with loadModel() above. try { this._importScripts(url); } catch (err) { - this.error("Error occurred when attempting to load dictionary", err); + // #13862: attempt to mitigate NetworkError on Chrome by retrying before giving up + tryCount++; + if(err instanceof Error && err.name == 'NetworkError') { + if(tryCount < 4) { + // increase delay with each retry: 10msec, 100msec, 1000msec + console?.warn(`NetworkError when attempting to load dictionary (attempt ${tryCount} of 4, will retry after ${10 ** tryCount} msec): ${err.toString()}`); + setTimeout(() => this.loadModelFile(url, tryCount), 10 ** tryCount); + } else { + this.error(`NetworkError when attempting to load dictionary (attempt ${tryCount} of 4, giving up): ${err.toString()}`); + } + } else { + this.error("Error occurred when attempting to load dictionary", err); + } } }