Search code examples
javascriptphantomjsgzipcasperjs

How to accept gzip content with casperjs and phantom?


I noticed that casperjs can't read the page , when I add "Accept-Encodeing" : "gzip, deflate" . in casperjs request headers .

It looks like that casperjs can't support gzip . I've searched a lot but I am not sure how to do it .

maybe i need to do it this way :

casper.on("page.download"){
   //decode gzip
}

But I am not sure how to do it ? can you help ! thanks


Solution

  • This is a known bug in phantom, for more than 2 years now. Unlikely to be fixed in the near future.

    • Without modify accept-encoding header, Phantomjs 2 will add "accept-encoding=gzip" header (though, this will not shown in page.onResourceRequested callback), and can decompress gzipped content successfully.
    • While we adding "accept-encoding=gzip" in the requests's header, Phantomjs 2 can't decompress it.

    https://github.com/ariya/phantomjs/issues/13621

    Note that I would have written that as a comment, but due to my user level I cannot comment this post. For whatever reason I must have 50 reputation.