sidorares / crconsole

Remote JavaScript console for Chrome/Webkit
MIT License
262 stars 23 forks source link

.Screen for full document height #33

Open oltkkol opened 6 years ago

oltkkol commented 6 years ago

Any chance to use .screen for full loaded document height + width?

oltkkol commented 6 years ago

solution I'd like to add:

this.repl.defineCommand('screentofile', {
  help: 'saves screenshot to given file',
  action: function(fileName) {
    var fullPage = true;

    self.client.send('Page.getLayoutMetrics', function(err, res){
      var metrics = res;
      var width   = Math.ceil( fullPage? metrics.contentSize.width : metrics.layoutViewport.clientWidth );
      var height  = Math.ceil( fullPage? metrics.contentSize.height: metrics.layoutViewport.clientHeight);
      var clip    = {x: 0, y: 0, width, height, scale: 1 };

      self.client.Page.captureScreenshot( { clip }, function(err, res) {
        var binData = Buffer.from(res.data, 'base64');

        fs.writeFile(fileName, binData, function(err) {
          if(err) {
              self.writeLn( err );
          }
        }); 

        self.writeLn(fileName);
      });
    });
  }
});
sidorares commented 6 years ago

hi! yes, probably a good feature to add. Similar puppeteer code: https://github.com/GoogleChrome/puppeteer/blob/bd73e4b7b814f0a9df97158f9102e486618c6075/lib/Page.js#L678-L690