You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/04/03 12:35:02 UTC

[GitHub] [cordova] alejo-0204 commented on issue #93: Loading cordova.js in a web worker and use a bluetooth plugin to process in a different thread

alejo-0204 commented on issue #93: Loading cordova.js in a web worker and use a bluetooth plugin to process in a different thread
URL: https://github.com/apache/cordova/issues/93#issuecomment-479469900
 
 
   Thanks @raphinesse, 
   I found a example of your suggested approach before, when I modify **demo_workers.js** and run the application, works (no warnings), but the problem is that i realize that have to handle all the possibles scenarios and situations, that means a lot of possible failure scenarios and not standard approach. I would like to found a solution that don't involves recreate the DOM and window.
   
   After the below implementation cordova.js show this message:
   
   `cordova.js:1945 Could not find cordova.js script tag. Plugin loading may fail.`
   
   Because it is expecting to get **/cordova.js** when call **document.getElementsByTagName('script');**
   
   And it is necessary to fire the event **deviceready** that means create the logic for  **document.dispatchEvent** `cordova.js:227`
   
   # /www files:
   
   **demo_workers.js**
   ```
   self.window = self;
   self.window.Event = function() {};
   self.window.prompt = 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() {}
       }
     },
     dispatchEvent: () => {}
   };
   
   importScripts("cordova.js");
   importScripts("bluetooth.js");
   
   app.initialize();
   
   onmessage = function(e) {
     app.onMessage(e.data);
   };
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org