brenden / node-webshot

Easy website screenshots in Node.js
2.12k stars 285 forks source link

How to use 'takeShotOnCallback' exactly in NODE app #164

Open hemangmehta opened 8 years ago

hemangmehta commented 8 years ago

I am using high chart in my html page. I want to take screen shot once chart fully loaded. For now i have used 'renderDelay' option. but i want to use takeShotOnCallback for consistancy.

Can anyone help me out how to use takeShotOnCallback exactly. I am not able to find example in doc too.

I am using below options for now. var options = { width: 'all', height: 'all', renderDelay: 5000 };

Thanks, Hemang

guojindai commented 8 years ago

try the options:

  {
    ...
    takeShotOnCallback: true,
    // Phantom callbacks
    onLoadFinished: function () {
      window.callPhantom('takeShot');
    },
  },
songyanho commented 7 years ago

You may add the takeShotOnCallback to options in such way

var options = {
    width: 'all',
    height: 'all',
    renderDelay: 5000,
    takeShotOnCallback: true
}

In the page that you taking snapshot, you may manually trigger window.callPhantom('takeShot'). So PhantomJS would take a snapshot after renderDelay once it is triggered.

I believe that PhantomJS will inject function as callPhantom function is not default window function. You can use try:catch to handle exception if user views page directly and only trigger it successfully when PhantomJS views the page