PHPackages                             shanginn/cloudflare-browser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. shanginn/cloudflare-browser

ActiveLibrary[API Development](/categories/api)

shanginn/cloudflare-browser
===========================

A strongly-typed, modern PHP SDK for the Cloudflare Browser Rendering REST API

0.2.1(3mo ago)117MITPHPPHP &gt;=8.2CI passing

Since Feb 1Pushed 3mo agoCompare

[ Source](https://github.com/shanginn/cloudflare-browser-sdk-php)[ Packagist](https://packagist.org/packages/shanginn/cloudflare-browser)[ RSS](/packages/shanginn-cloudflare-browser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (4)Used By (0)

Cloudflare Browser Rendering PHP SDK
====================================

[](#cloudflare-browser-rendering-php-sdk)

A strongly-typed, modern PHP SDK for the Cloudflare Browser Rendering REST API. Built with `amphp/http-client` for performance and `crell/serde` for robust object serialization.

Features
--------

[](#features)

- **Full Coverage**: Supports `/content`, `/screenshot`, `/pdf`, `/scrape`, `/json`, `/snapshot`, `/links`, and `/markdown` endpoints.
- **Strong Typing**: Uses Request DTOs and specific Response objects.
- **AI Extraction**: Seamless integration with `spiral/json-schema-generator` to extract structured data from webpages into PHP objects.
- **Custom Exceptions**: Granular error handling for API errors.

Installation
------------

[](#installation)

```
composer require shanginn/cloudflare-browser
```

Documentation
-------------

[](#documentation)

📚 **[View the full Wiki Documentation](../../wiki)** for detailed guides on all endpoints.

### Quick Links

[](#quick-links)

- [Getting Started &amp; REST API Overview](../../wiki/REST-API)
- [Fetching HTML Content](../../wiki/content-endpoint)
- [Capturing Screenshots](../../wiki/screenshot-endpoint)
- [Generating PDFs](../../wiki/pdf-endpoint)
- [Taking Snapshots](../../wiki/snapshot-endpoint)
- [Scraping Elements](../../wiki/scrape-endpoint)
- [AI Structured Data Extraction](../../wiki/json-endpoint)
- [Retrieving Links](../../wiki/links-endpoint)
- [Extracting Markdown](../../wiki/markdown-endpoint)

Basic Usage
-----------

[](#basic-usage)

### Setup

[](#setup)

```
use Shanginn\CloudflareBrowser\CloudflareClient;
use Shanginn\CloudflareBrowser\CloudflareBrowser;

$accountId = getenv('CLOUDFLARE_ACCOUNT_ID');
$apiToken = getenv('CLOUDFLARE_API_TOKEN');

$client = new CloudflareClient($accountId, $apiToken);
$browser = new CloudflareBrowser($client);
```

### Take a Screenshot

[](#take-a-screenshot)

```
use Shanginn\CloudflareBrowser\Requests\ScreenshotRequest;

$pngData = $browser->screenshot(new ScreenshotRequest(
    url: 'https://example.com',
    screenshotOptions: ['fullPage' => true]
));

file_put_contents('screenshot.png', $pngData);
```

See the [Screenshot Documentation](../../wiki/screenshot-endpoint) for more examples including:

- Custom HTML screenshots
- Authenticated pages
- Full-page captures
- Element-specific screenshots
- High-resolution captures

### Scrape Elements

[](#scrape-elements)

```
use Shanginn\CloudflareBrowser\Requests\ScrapeRequest;

$results = $browser->scrape(new ScrapeRequest(
    url: 'https://news.ycombinator.com',
    elements: [
        ['selector' => '.titleline > a']
    ]
));

foreach ($results as $group) {
    foreach ($group->results as $element) {
        echo "Found: {$element->text} ({$element->attributes['href'] ?? ''})\n";
    }
}
```

See the [Scraping Documentation](../../wiki/scrape-endpoint) for more details.

Advanced Usage
--------------

[](#advanced-usage)

### AI Structured Data Extraction

[](#ai-structured-data-extraction)

Define your target data structure using a PHP class and attributes. The SDK will generate the JSON schema and map the AI response back to your object.

**1. Define Schema:**

```
use Spiral\JsonSchemaGenerator\Attribute\Field;

class ProductSchema
{
    public function __construct(
        #[Field(title: 'Product Title', description: 'The main name of the item')]
        public string $title,

        #[Field(title: 'Price', description: 'Current price')]
        public float $price,
    ) {}
}
```

**2. Extract:**

```
use Shanginn\CloudflareBrowser\Requests\JsonRequest;

/** @var ProductSchema $product */
$product = $browser->json(
    new JsonRequest(
        url: 'https://example-shop.com/item/123',
        prompt: 'Extract the main product details'
    ),
    ProductSchema::class
);

echo "Product: {$product->title} - \${$product->price}\n";
```

See the [JSON Endpoint Documentation](../../wiki/json-endpoint) for more examples including array extraction and custom AI models.

### Generating PDFs

[](#generating-pdfs)

```
use Shanginn\CloudflareBrowser\Requests\PdfRequest;
use Shanginn\CloudflareBrowser\Requests\Common\Viewport;

$pdfData = $browser->pdf(new PdfRequest(
    url: 'https://example.com',
    viewport: new Viewport(width: 1200, height: 800)
));

file_put_contents('page.pdf', $pdfData);
```

See the [PDF Documentation](../../wiki/pdf-endpoint) for more examples including:

- Custom headers and footers
- Page format options (A4, A5, Letter, etc.)
- Blocking images/resources
- Dynamic placeholders (page numbers, dates, titles)

### Fetch HTML Content

[](#fetch-html-content)

```
$html = $browser->content('https://example.com');
echo $html;
```

See the [Content Documentation](../../wiki/content-endpoint) for handling JavaScript-heavy pages and blocking resources.

### Extract Markdown

[](#extract-markdown)

```
$markdown = $browser->markdown('https://example.com');
echo $markdown;
```

See the [Markdown Documentation](../../wiki/markdown-endpoint) for more details.

### Get All Links

[](#get-all-links)

```
$links = $browser->links('https://example.com');

// Or get only internal links
$internalLinks = $browser->links(
    url: 'https://example.com',
    excludeExternal: true
);
```

See the [Links Documentation](../../wiki/links-endpoint) for more details.

### Take a Snapshot

[](#take-a-snapshot)

```
use Shanginn\CloudflareBrowser\Requests\SnapshotRequest;

$snapshot = $browser->snapshot(new SnapshotRequest(
    url: 'https://example.com'
));

echo "Title: " . $snapshot->title . "\n";
echo "Content: " . $snapshot->content . "\n";
```

See the [Snapshot Documentation](../../wiki/snapshot-endpoint) for more examples.

Authentication
--------------

[](#authentication)

Before you begin, make sure you [create a custom API Token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/) with the following permissions:

- `Browser Rendering - Edit`

Set these environment variables:

- `CLOUDFLARE_ACCOUNT_ID` - Your Cloudflare Account ID
- `CLOUDFLARE_API_TOKEN` - Your Cloudflare API Token

Monitoring Usage
----------------

[](#monitoring-usage)

You can monitor Browser Rendering usage in two ways:

- In the Cloudflare dashboard, go to the **Browser Rendering** page to view aggregate metrics. [Go to **Browser Rendering**](https://dash.cloudflare.com/?to=/:account/workers/browser-rendering)
- `X-Browser-Ms-Used` header: Returned in every REST API response, reporting browser time used for that request (in milliseconds).

Troubleshooting
---------------

[](#troubleshooting)

If you have questions or encounter an error, see the [Browser Rendering FAQ and troubleshooting guide](https://developers.cloudflare.com/browser-rendering/faq/).

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance82

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

98d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/311e425711f60c09486c23252696fbe4dfa77e9b0dd5517bc89b288ac2f58655?d=identicon)[shanginn](/maintainers/shanginn)

---

Top Contributors

[![shanginn](https://avatars.githubusercontent.com/u/3357943?v=4)](https://github.com/shanginn "shanginn (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shanginn-cloudflare-browser/health.svg)

```
[![Health](https://phpackages.com/badges/shanginn-cloudflare-browser/health.svg)](https://phpackages.com/packages/shanginn-cloudflare-browser)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M650](/packages/sylius-sylius)[api-platform/symfony

Symfony API Platform integration

323.2M67](/packages/api-platform-symfony)[api-platform/serializer

API Platform core Serializer

223.4M31](/packages/api-platform-serializer)[fschmtt/keycloak-rest-api-client-php

PHP client to interact with Keycloak's Admin REST API.

4684.7k2](/packages/fschmtt-keycloak-rest-api-client-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
