diff --git a/src/utils/getEnvironment.js b/src/utils/getEnvironment.js index 3b4f100..03f5663 100644 --- a/src/utils/getEnvironment.js +++ b/src/utils/getEnvironment.js @@ -3,12 +3,12 @@ const isElectron = require('is-electron'); module.exports = (key) => { const env = {}; - if (isElectron()) { - env.type = 'electron'; + if (typeof WorkerGlobalScope !== 'undefined') { + env.type = 'webworker'; } else if (typeof window === 'object') { env.type = 'browser'; - } else if (typeof importScripts === 'function') { - env.type = 'webworker'; + } else if (isElectron()) { + env.type = 'electron'; } else if (typeof process === 'object' && typeof require === 'function') { env.type = 'node'; } diff --git a/src/worker-script/browser/index.js b/src/worker-script/browser/index.js index 2e177a8..06fd336 100644 --- a/src/worker-script/browser/index.js +++ b/src/worker-script/browser/index.js @@ -29,5 +29,4 @@ 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 6034cc6..5166ab8 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 || adapter.isWebWorker ? fetch : adapter.fetch)(`${path}/${lang}.traineddata${gzip ? '.gz' : ''}`); + const resp = await (isWebWorker ? fetch : adapter.fetch)(`${path}/${lang}.traineddata${gzip ? '.gz' : ''}`); data = await resp.arrayBuffer(); } else { data = await adapter.readCache(`${langPath}/${lang}.traineddata${gzip ? '.gz' : ''}`);