Thursday, 16 March 2017

JSDom analyze differently on Heroku and in local

I've something really weird. I want to get some info on a webpage (this one for example). When I test from my local, no problem, I get all the details I want.

But when I push my script to heroku, jsom provides me only a completely blank page without any DOM insisde, so no data. I don't understand why.

Here is the main parts of package.json :

{
  "engines": {
    "node": "5.8.0",
    "npm": "3.7.3"
  },
  "dependencies": {
    "co": "4.6.0",
    "co-body": "2.0.0",
    "co-pg": "1.3.1",
    "jsdom": "9.12.0",
    "koa": "0.21.0",
    "koa-bodyparser": "2.0.0",
    "koa-logger": "1.3.1"
  },
  "devDependencies": {
  }
}

And here is how I create the request from jsdom :

jsdom.env({
    url: 'https://www.manomano.fr/perceuse/perceuse-visseuse-makita-18-v-li-ion-4-ah-d-13-mm-90249',
    userAgent : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36',
    scripts: [],
    done: function (err, window) {
        // err is null, on local or on prod on Heroku
        /**
          * Concerning window :
          * 
          * In production 
          * window.document.querySelector('body').innerHTML === ''
          * 
          * In local
          * I got the whole HTML as 
          * I can have navigating with my browser.
         **/
    }
});

I have tried with or without the useragent property. And trid too with the "classical" call :

jsdom.env('https://www.manomano.fr/perceuse/perceuse-visseuse-makita-18-v-li-ion-4-ah-d-13-mm-90249', [same options], [sameCallback]);

Any idea on what's happening ? Off course, there is no more info in logs on heroku... I'm completely stuck on this problem for the moment. I do similar thinks in the same app (really the same, not just a clone/fork) with other websites and no problem, no differences between prod heroku and my local.

Thanks in advance to everybody and any idea !



via MathRobin

No comments:

Post a Comment