FredrikSandell / angular-workers

MIT License
69 stars 25 forks source link

Uncaught TypeError: Cannot read property 'prototype' of undefined #15

Open gweiss27 opened 8 years ago

gweiss27 commented 8 years ago

Is anyone else getting this error?

I am just trying to create a very simple web worker but I can't get past this error.

When I do some debugging, I see I am getting an initialization error with this reason...

message { target: Worker, isTrusted: true, data: "{}", origin: "", lastEventId: "", ports: MessagePortList, eventPhase: 0, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1465518268434703 }

does anyone know what this is and why its an error?

Thanks in advance!

julian-iFactory commented 8 years ago

+1, also getting error in Chrome:

Uncaught TypeError: Cannot read property 'prototype' of undefined

At line 2930 column 33 of angular.js (v1.5.7 from Github) line starting with 'var jqLiteContains ='

// IE9-11 has no method "contains" in SVG element and in Node.prototype. Bug #10259.
var jqLiteContains = window.Node.prototype.contains || function(arg) {
  // jshint bitwise: false
  return !!(this.compareDocumentPosition(arg) & 16);
  // jshint bitwise: true
};

This has been stable for 6 months and broke the moment I upgraded to angular v1.5.7

The error appear to be generated inside the WorkerService BEFORE making the $http request (for comments) in code below

var workerPromise = WorkerService.createAngularWorker(['input', 'output', '$http',
                    function(input, output, $http ) {   
                        var objectKey = input.objectKey;
                        var XSRFToken = input.XSRFToken;
                        var url = input.url;
                        var getComments = $http({
                            method: "get",
                            url: url,
                            headers : { 'X-XSRF-TOKEN' : XSRFToken }
                        });
                        getComments.then(function(response) {
                            output.resolve(response.data); 
                        }, function(error) {
                            output.reject(error);
                        });
                    }
                ]); // End WorkerService.createAngularWorker()
muety commented 8 years ago

+1

SmailHammour commented 7 years ago

+1

ghost commented 7 years ago

+1

mirkodandrea commented 7 years ago

I solved the problem by adding the Node property in the mocked window object defined in the workerTemplate string, inside the function createAngularWorkerTemplate.

var workerTemplate = [
          '',
          '//try {',
          'var window = self;',
          'self.Node = {prototype:[]};', //patch for angular >1.5.7
          'self.history = {};',
          'var document = {',
          '      readyState: \'complete\',',
          '      cookie: \'\',',
          '      querySelector: function () {},',
          '      createElement: function () {',
          '          return {',
          '              pathname: \'\',',
          '              setAttribute: function () {}',
          '          };',
          '      }',
          '};',
          'importScripts(\'<URL_TO_ANGULAR>\');',
          '<CUSTOM_DEP_INCLUDES>',
          'angular = window.angular;',
          'var workerApp = angular.module(\'WorkerApp\', [<DEP_MODULES>]);',
          'workerApp.run([\'$q\'<STRING_DEP_NAMES>, function ($q<DEP_NAMES>) {',
          '  self.addEventListener(\'message\', function(e) {',
          '    var input = e.data;',
          '    var output = $q.defer();',
          '    var promise = output.promise;',
          '    promise.then(function(success) {',
          '      self.postMessage({event:\'success\', data : success});',
          '    }, function(reason) {',
          '      self.postMessage({event:\'failure\', data : reason});',
          '    }, function(update) {',
          '      self.postMessage({event:\'update\', data : update});',
          '    });',
          '    <WORKER_FUNCTION>;',
          '  });',
          '  self.postMessage({event:\'initDone\'});',
          '}]);',
          'angular.bootstrap(null, [\'WorkerApp\']);',
          '//} catch(e) {self.postMessage(JSON.stringify(e));}'
        ];`
SmailHammour commented 7 years ago

Looks like the minified version is still giving this issue.

ramarivera commented 7 years ago

As far as I can see, that issue has been solved in angular pull 13492.

In order to not change angular versions due to the chance any other bug could arise (we were some versions behind) I manually applied the fix that was done in pull 13492. So far, I haven't experienced this issue again. Hope this helps.