/screenshot

This function will take a screenshot of the page you specified and return the image in .png or .jpg format.

Basic Example


curl -X POST \
"https://chrome.headlesstesting.com/screenshot?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com"}' > screenshot.png

This simple example will run a Puppeteer script on our service and do the following:

  • Start a Headless Chrome Browser (latest version) on our cloud
  • Connect with Puppeteer to the Headless Browser and navigate to the URL you specified
  • Take a screenshot of the page
  • Return the PNG data back to you
  • The PNG data is saved in a file called screenshot.png

Options


You can specify additional options with this function call to customize the screenshot taking.


Puppeteer screenshot options

This function call can use any of the Puppeteer page.screenshot options.


curl -X POST \
"https://chrome.headlesstesting.com/screenshot?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "options":{"fullPage":true}}' > screenshot.png

Authenticate options

You can specify the page.authenticate credentials.


curl -X POST \
"https://chrome.headlesstesting.com/screenshot?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "authenticate":{ "username": "user", "password": "passwd" }}' > screenshot.png

Goto options

You can specify the page.goto options and add timeout and waitUntil settings.


curl -X POST \
"https://chrome.headlesstesting.com/screenshot?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "gotoOptions":{ "waitUntil": "networkidle2" }}' > screenshot.png

Extra Headers

You can specify the page.setExtraHTTPHeaders options to add extra HTTP headers to the request our Headless Browser makes.


curl -X POST \
"https://chrome.headlesstesting.com/screenshot?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "extraHeaders":{ 'foo': 'bar' }}' > screenshot.png

Disable Javascript

You can disable Javascript with the page.setJavaScriptEnabled option.


curl -X POST \
"https://chrome.headlesstesting.com/screenshot?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "javascriptEnabled":false}' > screenshot.png

Add Tags

You can add additional style tags with the page.addStyleTag option.

You can add additional script tags with the page.addScriptTag option.