Use Ionic plugin in web working

How can I use Ionic Plugin in Web Worker? Particularly org.apache.cordova.contacts

if it helps.

Inspired by “ Can Angular be run on 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 loads it, but navigator.contacts.find

is undefined after running. :(

Is there an easier way? My ultimate goal is to connect phone contacts asynchronously.

(I need to do this because it navigator.contacts.find()

is a blocking call and it takes about 1 minute to load the entire contact list).

+3


source to share





All Articles