From 3f98fdeb0f7ca95890a046b466d43f6d0f345279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Couton?= Date: Mon, 12 Oct 2020 22:12:08 +0200 Subject: [PATCH] Fix fetch when running in electron webview --- src/worker-script/browser/index.js | 1 + src/worker-script/index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/worker-script/browser/index.js b/src/worker-script/browser/index.js index 06fd336..2e177a8 100644 --- a/src/worker-script/browser/index.js +++ b/src/worker-script/browser/index.js @@ -29,4 +29,5 @@ worker.setAdapter({ gunzip, fetch: () => {}, ...cache, + isWebWorker: typeof window === 'undefined' && typeof importScripts === 'function', }); diff --git a/src/worker-script/index.js b/src/worker-script/index.js index 5166ab8..6034cc6 100644 --- a/src/worker-script/index.js +++ b/src/worker-script/index.js @@ -99,7 +99,7 @@ const loadLanguage = async ({ } if (path !== null) { - const resp = await (isWebWorker ? fetch : adapter.fetch)(`${path}/${lang}.traineddata${gzip ? '.gz' : ''}`); + const resp = await (isWebWorker || adapter.isWebWorker ? fetch : adapter.fetch)(`${path}/${lang}.traineddata${gzip ? '.gz' : ''}`); data = await resp.arrayBuffer(); } else { data = await adapter.readCache(`${langPath}/${lang}.traineddata${gzip ? '.gz' : ''}`);