PHPackages                             tungtu/puphpeteer - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. tungtu/puphpeteer

ActiveLibrary[Testing &amp; Quality](/categories/testing)

tungtu/puphpeteer
=================

A Puppeteer bridge for PHP, supporting the entire API.

2.1.0(11mo ago)0438MITPHPPHP &gt;=7.3

Since Apr 28Pushed 11mo agoCompare

[ Source](https://github.com/tungtu/puphpeteer)[ Packagist](https://packagist.org/packages/tungtu/puphpeteer)[ RSS](/packages/tungtu-puphpeteer/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (6)Used By (0)

PuPHPeteer
==========

[](#puphpeteer)

[![](https://user-images.githubusercontent.com/817508/100672192-dd258500-3361-11eb-845f-e8b5109752e4.png)](https://user-images.githubusercontent.com/817508/100672192-dd258500-3361-11eb-845f-e8b5109752e4.png)

[![PHP Version](https://camo.githubusercontent.com/7f189bbbfc66eb35e1c57ba653d0910cdcf7f01f966a713ee1e2d3171cf1a482/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e65736b2f707570687065746565722e7376673f7374796c653d666c61742d737175617265)](http://php.net/)[![Composer Version](https://camo.githubusercontent.com/7d50b43d342d7d30bc16b787072dab09786e8bba30073370b3b460c1d65cc3da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65736b2f707570687065746565722e7376673f7374796c653d666c61742d737175617265266c6162656c3d436f6d706f736572)](https://packagist.org/packages/nesk/puphpeteer)[![Node Version](https://camo.githubusercontent.com/8fa99a42a9d6e42003dc07828812dde4b2142964305f01f801eb81655679fa40/68747470733a2f2f696d672e736869656c64732e696f2f6e6f64652f762f406e65736b2f707570687065746565722e7376673f7374796c653d666c61742d737175617265266c6162656c3d4e6f6465)](https://nodejs.org/)[![NPM Version](https://camo.githubusercontent.com/d169754edb021953eee24b67507962711b06d8306ef79ec96973605f289bcb66/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f406e65736b2f707570687065746565722e7376673f7374796c653d666c61742d737175617265266c6162656c3d4e504d)](https://www.npmjs.com/package/@nesk/puphpeteer)[![Build Status](https://camo.githubusercontent.com/fde58d10e748081ab14d2e094e73781de13d90c9d1e347912f0c270fb7f2de4c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e65736b2f707570687065746565722e7376673f7374796c653d666c61742d737175617265266c6162656c3d4275696c64253230537461747573)](https://travis-ci.org/nesk/puphpeteer)

A [Puppeteer](https://github.com/GoogleChrome/puppeteer/) bridge for PHP, supporting the entire API. Based on [Rialto](https://github.com/nesk/rialto/), a package to manage Node resources from PHP.

Here are some examples [borrowed from Puppeteer's documentation](https://github.com/GoogleChrome/puppeteer/blob/master/README.md#usage) and adapted to PHP's syntax:

**Example** - navigating to  and saving a screenshot as *example.png*:

```
use Nesk\Puphpeteer\Puppeteer;

$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();

$page = $browser->newPage();
$page->goto('https://example.com');
$page->screenshot(['path' => 'example.png']);

$browser->close();
```

**Example** - evaluate a script in the context of the page:

```
use Nesk\Puphpeteer\Puppeteer;
use Nesk\Rialto\Data\JsFunction;

$puppeteer = new Puppeteer;

$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto('https://example.com');

// Get the "viewport" of the page, as reported by the page.
$dimensions = $page->evaluate(JsFunction::createWithBody("
    return {
        width: document.documentElement.clientWidth,
        height: document.documentElement.clientHeight,
        deviceScaleFactor: window.devicePixelRatio
    };
"));

printf('Dimensions: %s', print_r($dimensions, true));

$browser->close();
```

Requirements and installation
-----------------------------

[](#requirements-and-installation)

This package requires PHP &gt;= 7.3 and Node &gt;= 8.

Install it with these two command lines:

```
composer require tungtu/puphpeteer
npm install @tungtu/puphpeteer
```

Notable differences between PuPHPeteer and Puppeteer
----------------------------------------------------

[](#notable-differences-between-puphpeteer-and-puppeteer)

### Puppeteer's class must be instantiated

[](#puppeteers-class-must-be-instantiated)

Instead of requiring Puppeteer:

```
const puppeteer = require('puppeteer');
```

You have to instantiate the `Puppeteer` class:

```
$puppeteer = new Puppeteer;
```

This will create a new Node process controlled by PHP.

You can also pass some options to the constructor, see [Rialto's documentation](https://github.com/nesk/rialto/blob/master/docs/api.md#options). PuPHPeteer also extends these options:

```
[
    // Logs the output of Browser's console methods (console.log, console.debug, etc...) to the PHP logger
    'log_browser_console' => false,
]
```

**⏱ Want to use some timeouts higher than 30 seconds in Puppeteer's API?**
If you use some timeouts higher than 30 seconds, you will have to set a higher value for the `read_timeout` option (default: `35`):

```
$puppeteer = new Puppeteer([
    'read_timeout' => 65, // In seconds
]);

$puppeteer->launch()->newPage()->goto($url, [
    'timeout' => 60000, // In milliseconds
]);
```

### No need to use the `await` keyword

[](#no-need-to-use-the-await-keyword)

With PuPHPeteer, every method call or property getting/setting is synchronous.

### Some methods have been aliased

[](#some-methods-have-been-aliased)

The following methods have been aliased because PHP doesn't support the `$` character in method names:

- `$` =&gt; `querySelector`
- `$$` =&gt; `querySelectorAll`
- `$x` =&gt; `querySelectorXPath`
- `$eval` =&gt; `querySelectorEval`
- `$$eval` =&gt; `querySelectorAllEval`

Use these aliases just like you would have used the original methods:

```
$divs = $page->querySelectorAll('div');
```

### Evaluated functions must be created with `JsFunction`

[](#evaluated-functions-must-be-created-with-jsfunction)

Functions evaluated in the context of the page must be written [with the `JsFunction` class](https://github.com/nesk/rialto/blob/master/docs/api.md#javascript-functions), the body of these functions must be written in JavaScript instead of PHP.

```
use Nesk\Rialto\Data\JsFunction;

$pageFunction = JsFunction::createWithParameters(['element'])
    ->body("return element.textContent");
```

### Exceptions must be caught with `->tryCatch`

[](#exceptions-must-be-caught-with--trycatch)

If an error occurs in Node, a `Node\FatalException` will be thrown and the process closed, you will have to create a new instance of `Puppeteer`.

To avoid that, you can ask Node to catch these errors by prepending your instruction with `->tryCatch`:

```
use Nesk\Rialto\Exceptions\Node;

try {
    $page->tryCatch->goto('invalid_url');
} catch (Node\Exception $exception) {
    // Handle the exception...
}
```

Instead, a `Node\Exception` will be thrown, the Node process will stay alive and usable.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Logo attribution
----------------

[](#logo-attribution)

PuPHPeteer's logo is composed of:

- [Puppet](https://thenounproject.com/search/?q=puppet&i=52120) by Luis Prado from [the Noun Project](http://thenounproject.com/).
- [Elephant](https://thenounproject.com/search/?q=elephant&i=954119) by Lluisa Iborra from [the Noun Project](http://thenounproject.com/).

Thanks to [Laravel News](https://laravel-news.com/) for picking the icons and colors of the logo.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance52

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 80.9% 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 ~9 days

Total

5

Last Release

340d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a116401b2422c50211543dfe7bdd0d262b65506490ae193edb970b8168403068?d=identicon)[tungtu](/maintainers/tungtu)

---

Top Contributors

[![nesk](https://avatars.githubusercontent.com/u/817508?v=4)](https://github.com/nesk "nesk (110 commits)")[![spekulatius](https://avatars.githubusercontent.com/u/8433587?v=4)](https://github.com/spekulatius "spekulatius (8 commits)")[![tungtu](https://avatars.githubusercontent.com/u/15995322?v=4)](https://github.com/tungtu "tungtu (7 commits)")[![tungtt1-dev](https://avatars.githubusercontent.com/u/209135282?v=4)](https://github.com/tungtt1-dev "tungtt1-dev (6 commits)")[![erikgaal](https://avatars.githubusercontent.com/u/1234268?v=4)](https://github.com/erikgaal "erikgaal (2 commits)")[![xtrime-ru](https://avatars.githubusercontent.com/u/34161928?v=4)](https://github.com/xtrime-ru "xtrime-ru (2 commits)")[![nickescobedo](https://avatars.githubusercontent.com/u/2837169?v=4)](https://github.com/nickescobedo "nickescobedo (1 commits)")

---

Tags

phptestingwebautomationpuppeteerdeveloper-toolsheadless-chrome

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tungtu-puphpeteer/health.svg)

```
[![Health](https://phpackages.com/badges/tungtu-puphpeteer/health.svg)](https://phpackages.com/packages/tungtu-puphpeteer)
```

###  Alternatives

[zoon/puphpeteer

A Puppeteer bridge for PHP, supporting the entire API.

204192.9k1](/packages/zoon-puphpeteer)[nigelcunningham/puphpeteer

A Puppeteer bridge for PHP, supporting the entire API.

2221.7k](/packages/nigelcunningham-puphpeteer)[playwright-php/playwright

Modern PHP library for Playwright automation: browsing, scraping, screenshots, testing, and more.

7613.0k5](/packages/playwright-php-playwright)[doppiogancio/mocked-client

A simple way to mock a client

2174.9k3](/packages/doppiogancio-mocked-client)[victor-teles/playwright-php

A Playwright bridge for PHP.

203.6k](/packages/victor-teles-playwright-php)

PHPackages © 2026

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