Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
Get Cordova plugin file to fully work in a web worker

I'm running an app with Cordova that has an extremely heavy optional file download. When run on the main thread iOS will shut down the app because it is running too long. In order to solve this, I decided to use web workers so it could run on a separate thread, (the error I was getting said to run the process on a separate thread). Since then I've had difficulties getting the plugins to work in a separate worker. Thus far I've been able to load Cordova and its plugin scripts and am able to call the modules but they are failing to call the native code because the native code relies on window.webkit.messageHandlers.cordova. As far as I can tell, when swift exposes the js methods it only exposes it to the main thread and there is no way to access the native code from the worker. Is there any other way to call native code from the worker that I'm missing?

(self as any).window = self;
(self as any).window.document = self;
(self as any).document = self;
(self as any).window.webkit = (window as any).webkit || {
  messageHandlers: {}
};
// import the scripts from their location in the www folder
const pathToCordovaPluginFile = "../plugins/cordova-plugin-file/www/";
importScripts(
  "../cordova.js",
  pathToCordovaPluginFile + "requestFileSystem.js",
  pathToCordovaPluginFile + "FileError.js",
  pathToCordovaPluginFile + "FileSystem.js",
  pathToCordovaPluginFile + "fileSystems.js",
  pathToCordovaPluginFile + "DirectoryEntry.js",
  pathToCordovaPluginFile + "Entry.js",
  pathToCordovaPluginFile + "DirectoryReader.js",
  pathToCordovaPluginFile + "Metadata.js"

  // pathToCordovaPluginFile + "File.js",
  // pathToCordovaPluginFile + "FileEntry.js",
  // pathToCordovaPluginFile + "FileReader.js",
  // pathToCordovaPluginFile + "FileWriter.js",
);

const getFileSystem = (PERSISTENT: number) => {
  try {
    const requestFileSystem: Window["requestFileSystem"] = cordova.require(
      "cordova-plugin-file.requestFileSystem"
    );
    return new Promise<FileSystem>((resolve, reject) =>
      requestFileSystem(PERSISTENT, 0, resolve, reject)
    );
  } catch {
    console.error("unable to request file system");
  }
};

(my code is technically in typescript not javascript)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

AFAIK web workers are NOT available on iOS WKWebView for iOS < 14

More information here and here

You should consider modifying the plugin to run your download on a sub native thread.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda