Downloads
Stars
Version
This package provides fluent SDK for the Capture server. Capture is a Node server on AWS that takes screenshots with a variety of options. This package requires access to a Capture server endpoint before it be used.
Why is the Capture server endpoint not included in the package? Capture is a private Node server that runs Puppeteer with a specific set of features that are used for our internal products. We do not publish the URL, as its not intended for public consumption. You may however deploy your own Capture server and endpoint.
Install via Composer
composer require actengage/capture-sdk
Publish the config file
php artisan vendor:publish --tag=capture-config
Set the endpoint URL in your ENV file.
CAPTURE_ENDPOINT=http://localhost:3000/
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')->request();
Call allow you to execute methods on the Puppeteer page
instance before the screenshot has been taken. This is a convenient way to execute a sequence of actions that are explicitly built into the server options (mainly for edge cases). The first argument is the method name, and all other arguments are passed to the method in Puppeteer.
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->call('$', 'header#nav > .logo')
->request();
Clip a portion of an image using width
, height
, x
, and y
coordinates. There is no clipping by default.
use Actengage\Capture\DataTypes\Clip;
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->clip(new Clip(800, 600, 400, 300))
->request();
Encoding changes how the response is composed, either using binary
or base64
. Defaults to binary
.
use Actengage\Capture\DataTypes\Encoding;
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->encoding(Encoding::Binary)
->request();
Take full page screenshots. Defaults to false
.
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->fullPage(true)
->request();
Pass a custom headers that are included by Puppeteer in its HTTP request. Defaults to {"Accept-Language": "en-US"}
.
use Actengage\Capture\DataTypes\Encoding;
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->header('Accept-Language', 'en-US')
->request();
This omits the black background for transparent PNG images. Defaults to true
.
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->omitBackground(true)
->request();
The quality of image that is returned. Must be 1-100
. Defaults to 100
.
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->quality(100)
->request();
The timeout of the Puppeteer request (in milliseconds). Defaults to 25000
.
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->timeout(15000)
->request();
The type of image that is returned, jpeg
or png
. Defaults to jpeg
.
use Actengage\Capture\DataTypes\Type;
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->type(Type::PNG)
->request();
The viewport dimensions. Defaults to {"width": 1200, "height": 800}
.
use Actengage\Capture\DataTypes\Viewport;
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->viewport(new Viewport(1200, 800))
->request();
How long should Puppeteer wait before returning a response. Defaults to ['load', 'networkidle2']
.
use Actengage\Capture\DataTypes\WaitUntil;
use Actengage\Capture\Facades\Screenshot;
$response = Screenshot::make('https://google.com')
->waitUntil([WaitUntil::Load, WaitUntil::NetworkIdle2])
->request();