Using the Cloudflare driver | laravel-screenshot | Spatie

 SPATIE

  Laravel Screenshot
=====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-screenshot](https://spatie.be/docs/laravel-screenshot/v1)  Drivers  Using the Cloudflare driver

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-screenshot/v1)

- [ Introduction ](https://spatie.be/docs/laravel-screenshot/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-screenshot/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-screenshot/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-screenshot/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-screenshot/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-screenshot/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-screenshot/v1/about-us)

Basic usage
-----------

- [ Taking screenshots ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/taking-screenshots)
- [ Customizing screenshots ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/customizing-screenshots)
- [ Saving screenshots to disks ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/saving-screenshots-to-disks)
- [ Queued screenshot generation ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/queued-screenshot-generation)
- [ Testing screenshots ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/testing-screenshots)

Drivers
-------

- [ Configuration ](https://spatie.be/docs/laravel-screenshot/v1/drivers/configuration)
- [ Customizing Browsershot ](https://spatie.be/docs/laravel-screenshot/v1/drivers/customizing-browsershot)
- [ Using the Cloudflare driver ](https://spatie.be/docs/laravel-screenshot/v1/drivers/using-the-cloudflare-driver)
- [ Custom drivers ](https://spatie.be/docs/laravel-screenshot/v1/drivers/custom-drivers)

Advanced usage
--------------

- [ Extending with macros ](https://spatie.be/docs/laravel-screenshot/v1/advanced-usage/extending-with-macros)

 Using the Cloudflare driver
===========================

###  On this page

1. [ Setup ](#content-setup)
2. [ Supported features ](#content-supported-features)
3. [ Per-screenshot usage ](#content-per-screenshot-usage)
4. [ Rate limits ](#content-rate-limits)
5. [ Limitations ](#content-limitations)

The Cloudflare driver uses [Cloudflare's Browser Rendering API](https://developers.cloudflare.com/browser-rendering/) to take screenshots. It does not require Node.js or a Chrome binary on your server, making it a great option for cloud-hosted or serverless Laravel applications.

Setup
-----------------------------------------------------------------------

1. Make sure you have a [Cloudflare account](https://dash.cloudflare.com/sign-up)
2. In the Cloudflare dashboard, go to **Manage account &gt; Account API tokens**
3. Create a token with the **Account.Browser Rendering** permission
4. Add the following to your `.env` file:

```
LARAVEL_SCREENSHOT_DRIVER=cloudflare
CLOUDFLARE_API_TOKEN=your-api-token
CLOUDFLARE_ACCOUNT_ID=your-account-id
```

No other dependencies are required. The Cloudflare driver uses Laravel's built-in HTTP client.

Supported features
--------------------------------------------------------------------------------------------------------------

The Cloudflare driver supports all the core screenshot features:

- URL and HTML input
- Viewport size (width, height)
- Device scale factor
- Image format (PNG, JPEG, WebP) and quality
- Full page screenshots
- Element screenshots via CSS selector
- Clip region
- Transparent background
- Wait strategies (network idle, selector, timeout)

Per-screenshot usage
--------------------------------------------------------------------------------------------------------------------

You can use the Cloudflare driver for a specific screenshot while keeping Browsershot as the default:

```
use Spatie\LaravelScreenshot\Facades\Screenshot;

Screenshot::url('https://example.com')
    ->driver('cloudflare')
    ->save('screenshot.png');
```

Rate limits
-----------------------------------------------------------------------------------------

Be aware of Cloudflare's rate limits for the Browser Rendering API. The free plan includes:

- 6 REST API requests per minute
- 10 minutes of Browser Rendering per day

For production use, consider a paid plan with higher limits.

Limitations
-----------------------------------------------------------------------------------------

- The `withBrowsershot()` method has no effect when using the Cloudflare driver
- Cloudflare's API may not support all Chrome-specific options available through Browsershot
