title: nodejs jsdom TypeError: Object [object global] has no method 'postMessage'
body: <p>This is a page from my Nodejs Express app, routers/index.js page
  I am trying to parse some sites - here are two pieces of code as an example. 
  After getting the page I use jsdom module to work with data. But there is one problem - othersite.com in this example works fine, while site.com crashes after parsing and rendering the page (as it seems to me) with an error:</p>
  
  <pre><code>http://s7.addthis.com/static/r07/core159.js:4
  ){!_ate.bro.ie6&amp;&amp;!_ate.bro.ie7&amp;&amp;W&amp;&amp;W.contentWindow&amp;&amp;W.contentWindow.postMessag
                                                                      ^
  TypeError: Object [object global] has no method 'postMessage'
      at Object.r [as msg] (http://s7.addthis.com/static/r07/core159.js:4:6291)
      at Object.window._ate.m.initPostMessage (http://s7.addthis.com/static/r07/core159.js:7:11410)
      at null._onTimeout (http://s7.addthis.com/static/r07/core159.js:7:7874)
      at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
  </code></pre>
  
  <p>There are other conditional blocks that produce the same error, though there is not so much code there.<br>
  Can anyone tell me what's the problem? </p>
  
  <pre><code>router.get('/', function(req, res) {
  var url_parts = url.parse(req.url, true),
      query = url_parts.query,
      video_url,
      file_url,
      videoTitle,
      embedCode,
      remoteAddr = req.connection.remoteAddress,
      base64_encode = require('base64').encode;
  if (query.link) {
          var pathObj = url.parse(query.link, true);
          var options = {
              host: pathObj.host,
              port: 80,
              path: pathObj.path,
              headers: {
                  "X-forwarder-for" : "90.90.90.90" // just sample ip
              }
          };
          http.get(options, function(response){
  
              var allChunk = '';
              response.on('data', function(chunk) {
                      allChunk += chunk;
              });
              response.on('end', function(){
                  var doc = jsdom.jsdom(allChunk);
                  var serializedChunk = doc.documentElement.outerHTML;
                  jsdom.env(
                      serializedChunk,
                      ["http://code.jquery.com/jquery.js"],
                      function (errors, window) {
                          remoteAddr = remoteAddr;
                          videoTitle = window.$('title').text();
                          var rawHtml = window.$('body').html();
                          var handler = new htmlparser.DefaultHandler(function (error, dom) {});
                          var parser = new htmlparser.Parser(handler);
                          parser.parseComplete(rawHtml);
                          var objectDom = handler.dom;
                          if (query.link.indexOf('site.com') != -1) {
                              var blockHTML = window.$('#player embed').attr('flashvars');
                              var flash_vars_url = url.parse('/?' + blockHTML, true);
                              var queryFlashVars = flash_vars_url.query;
                              file_url = queryFlashVars.flv_url;
                              embedCode = window.$('input[name="media_embed_code"]').val();
                              res.render('link', { title: 'source link', link: file_url, videoTitle: videoTitle, embedCode: embedCode, sourceLink: query.link });
                          } else if (query.link.indexOf('othersite.com') != -1) {
                              file_url = window.$('.downloadList li a').attr('href');
                              var embedObject = /\$\('#clip_text'\).val\(*"([^"]*)/g.exec(rawHtml);
                              embedCode = embedObject[1];
                              res.render('link', { title: 'source link', link: file_url, videoTitle: videoTitle, embedCode: embedCode, sourceLink: query.link });
  
                          } else {
                              res.status(404);
                              res.render('error', {
                                  message: 'Not found',
                                  error: {}
                              });
                          }
  
                      }
                  );
  
              });
          }).on("error", function(e){
              console.log("Got error: " + e.message);
          }).end();
  } else {
      res.render('index', { title: 'title' });
  }
  </code></pre>
  
  <p>});</p>
  
  <p>I will be grateful for any help.</p>