wch / webshot

Take screenshots of web pages from R
http://wch.github.io/webshot/
227 stars 40 forks source link

Allow setting custom headers #78

Open colearendt opened 5 years ago

colearendt commented 5 years ago

Related to #77 , it would be nice to be able to set arbitrary headers (i.e. not just userAgent). Unfortunately, per

It seems that pageSettings does not work for setting arbitrary headers (at least not with the incantations I tried), and passing the headers to .open() does not send the headers with follow-on requests. As a result, the preferred (and workable) approach was to add the following to webshot.js before casper.start():

casper.on('started', function () {
  this.page.customHeaders = {
    "Header" : "Value" 
  };
});

This is also anecdotally related to #49 , because I am using headers for authentication to RStudio Connect (in lieu of clicking through auth and then saving a cookie).