CaptureHandler tutorial

CaptureHandler allows you to take screenshot of pages. It relies on Chrome’s puppeteer (requires node 9.X) and ensure node is in your path. It can be configured in gramex as below:

  pattern: /$YAMLURL/capture
  handler: CaptureHandler
    engine: chrome  # engine
    timeout: 10     # default request timeout for capturing
    port: 9900      # default port number

Configure CaptureHandler in front-end (or) To encode URL using JavaScript:

var url = g1.url.parse(location.href); // fetch current url using g1 library
// trigger the screenshot
var capture_url = url.join('capture')
  .update({'url': location.href, 'exp': 'pdf', 'delay': 10000, 'd': 'true'})
// or 
$('.custom-pdf').attr('href', capture_url.toString())

To encode URLs using a python template:

{% from six.moves.urllib_parse import urlencode %}
<a href="capture?{{ urlencode(url='...', header='header text') }}"

Schedule CaptureHandler

CaptureHandler can be used as a service via python. YAML configuration for which is as follows:

  function: app.screenshot_scheduler
  dates: '-'
  hours: '2'      # 2nd hour of the day
  minutes: '30' # 30th minute

corresponding screenshot_scheduler function in

def screenshot_scheduler():
    params = {'url': '', 'delay': 4000, 'ext': 'png'}
    url = '' + urlencode(params)

Supported Arguments

Arguments supported by CaptureHandler:

For PDF:



For detailed documentation, visit CaptureHandler.