Ionic in Web Worker


#1

How can I use an ionic plugin in a Web Worker? Specifically, org.apache.cordova.contacts if that helps.

Inspired by “http://stackoverflow.com/questions/26668430/is-it-possible-to-run-angular-in-a-web-worker” I’m trying to do:

self.window = self;
self.window.Event = function() {};
self.window.innerHeight = 1;
self.history = {};
self.document = {
  readyState: 'complete',
  addEventListener: function() {},
  querySelector: function() {},
  getElementsByTagName: function() {
    return [];
  },
  createElement: function() {
    return {
      pathname: '',
      setAttribute: function() {}
    };
  },
  createEvent: function() {
    return {
      initEvent: function() {}
    };
  },
 documentElement: {
    style: {
      transition: ''
    }
  },
  head: {
    children: [],
    appendChild: function(child) {
      importScripts('../../' + child.src);
      child.onload();
    }
  },
  body: {
    classList: {
      add: function() {},
    }
  },
};

importScripts('../../lib.js');
importScripts('../../cordova.js');

This gets it to load, but navigator.contacts.find is undefined after running that. :frowning:

Is there an easier way? My end goal is to ingest the phone’s contacts asynchronously.

(I need to do this because navigator.contacts.find() is a blocking call and to download the whole contact list is taking around 1 minute).


All Phone Contacts Asyncronously