andreas-marschke / boomerang-express

A server-side implementation for BoomerangJs-based RUMs capable of using multiple storage-backends
17 stars 2 forks source link

TypeError: restiming.forEach is not a function #7

Open pzystorm opened 7 years ago

pzystorm commented 7 years ago

Following error occured:

TypeError: restiming.forEach is not a function
    at Boomerang.restiming (/home/my/boomerang-express/lib/boomerang/index.js:99:13)
    at null.<anonymous> (/home/my/boomerang-express/lib/boomerang/index.js:83:18)
    at Backend.<anonymous> (/home/my/boomerang-express/lib/datastore/nedb/index.js:80:7)
    at callback (/home/my/boomerang-express/node_modules/nedb/lib/executor.js:30:17)
    at /home/my/boomerang-express/node_modules/nedb/lib/datastore.js:288:12
    at /home/my/boomerang-express/node_modules/nedb/lib/persistence.js:209:12
    at FSReqWrap.oncomplete (fs.js:82:15)
error: Forever detected script exited with code: 0

This is the corresponding code block:

Boomerang.prototype.restiming = function(oid, restiming, user, collection) {
  restiming.forEach(function(timing) {
    timing.refer = oid;
    this.store("resource", user, collection, this.filter.inflate(timing), function() { });
  }, this);
};

If I debug this restiming variable, it is a string (not an array) with the following content:

{  
   "http":{  
      "://localhost:4001/":{  
         "|":"6,dz,dx,8u,8u,,f,f,f*117y,95",
         "boomerang/":{  
            "boomerang.js":"3e5,v,r,c*116x3,95*20",
            "plugins/":{  
               "r":{  
                  "t.js":"3e5,y,x,g*1r7f,95*20",
                  "estiming.js":"3e5,1b,18,y*1up9,95*20"
               },
               "navtiming.js":"3e5,14,12,v*15fs,94*20"
            }
         }
      },
      "s://www.mydomain.de/testpic.png":"*013,32,8,8|1e6"
   }
}

What do I have to do?

andreas-marschke commented 7 years ago

This is a shortcoming of boomerang-express as it doesn't support trie compression used in newer versions of Boomerang. You could have a look at https://github.com/nicjansma/resourcetiming-compression.js and see if you could implement it here for newer versions of boomerang.

pzystorm commented 7 years ago

Ah, thanks, works like a charm. npm install resourcetiming-compression and edited the file lib/boomerang/index.js: Around line 80:

        this.store(beacon.type, beacon.user, beacon.collection, data, function(oid) {
          if (typeof restiming !== "undefined") {
            var ResourceTimingDecompression = require("resourcetiming-compression").ResourceTimingDecompression;
            restiming = ResourceTimingDecompression.decompressResources(JSON.parse(restiming));
            this.restiming(oid, restiming, beacon.user, beacon.collection);
          }
        }.bind(this));
andreas-marschke commented 7 years ago

@pzystorm If you can wrap this in a try/catch and check for older versions that do not use compression I'd be happy to take it as a contribution :)