{"id":27480044,"url":"https://github.com/zoonru/puphpeteer","last_synced_at":"2025-04-16T12:03:20.304Z","repository":{"id":45667872,"uuid":"303375151","full_name":"zoonru/puphpeteer","owner":"zoonru","description":"A Puppeteer bridge for PHP, supporting the entire API.","archived":false,"fork":true,"pushed_at":"2025-04-08T11:29:03.000Z","size":2671,"stargazers_count":171,"open_issues_count":7,"forks_count":46,"subscribers_count":2,"default_branch":"zoon","last_synced_at":"2025-04-08T11:46:55.803Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"rialto-php/puphpeteer","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoonru.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-12T11:49:19.000Z","updated_at":"2025-04-08T11:29:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zoonru/puphpeteer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fpuphpeteer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fpuphpeteer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fpuphpeteer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fpuphpeteer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoonru","download_url":"https://codeload.github.com/zoonru/puphpeteer/tar.gz/refs/heads/zoon","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249236947,"owners_count":21235347,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-16T12:01:57.106Z","updated_at":"2025-04-16T12:03:20.297Z","avatar_url":"https://github.com/zoonru.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# PuPHPeteer\n\n\u003cimg src=\"https://user-images.githubusercontent.com/817508/100672192-dd258500-3361-11eb-845f-e8b5109752e4.png\" style=\"max-width:100%;\" width=\"190px\" align=\"right\"\u003e\n\n[![PHP Version](https://img.shields.io/packagist/php-v/zoon/puphpeteer.svg?style=flat-square)](http://php.net/)\n[![Composer Version](https://img.shields.io/packagist/v/zoon/puphpeteer.svg?style=flat-square\u0026label=Composer)](https://packagist.org/packages/zoon/puphpeteer)\n\nA [Puppeteer](https://github.com/GoogleChrome/puppeteer/) bridge for PHP, supporting the entire API. Based on [Rialto](https://github.com/zoonru/rialto/), a package to manage Node resources from PHP.\n\nHere are some examples [borrowed from Puppeteer's documentation](https://github.com/GoogleChrome/puppeteer/blob/master/README.md#usage) and adapted to PHP's syntax:\n\n**Example** - navigating to https://example.com and saving a screenshot as *example.png*:\n\n```php\nuse Nesk\\Puphpeteer\\Puppeteer;\n\n$puppeteer = new Puppeteer;\n$browser = $puppeteer-\u003elaunch();\n\n$page = $browser-\u003enewPage();\n$page-\u003egoto('https://example.com');\n$page-\u003escreenshot(['path' =\u003e 'example.png']);\n\n$browser-\u003eclose();\n```\n\n**Example** - evaluate a script in the context of the page:\n\n```php\nuse Nesk\\Puphpeteer\\Puppeteer;\nuse Nesk\\Rialto\\Data\\JsFunction;\n\n$puppeteer = new Puppeteer;\n\n$browser = $puppeteer-\u003elaunch();\n$page = $browser-\u003enewPage();\n$page-\u003egoto('https://example.com');\n\n// Get the \"viewport\" of the page, as reported by the page.\n$dimensions = $page-\u003eevaluate(JsFunction::createWithBody(\"\n    return {\n        width: document.documentElement.clientWidth,\n        height: document.documentElement.clientHeight,\n        deviceScaleFactor: window.devicePixelRatio\n    };\n\"));\n\nprintf('Dimensions: %s', print_r($dimensions, true));\n\n$browser-\u003eclose();\n```\n\n## Requirements and installation\n\nThis package requires PHP \u003e= 7.3 and Node \u003e= 8.\n\nInstall it with these two command lines:\n\n```shell\ncomposer require zoon/puphpeteer\nnpm install git+https://git@github.com/zoonru/puphpeteer.git#zoon\n```\n\n## Use with browserless\n\n```shell\ndocker run --rm  -p 3000:3000 ghcr.io/browserless/chrome\n```\n\n```php\n$puppeteer = new Nesk\\Puphpeteer\\Puppeteer;\n\n$options = [\n    'headless' =\u003e false,\n    'stealth'=\u003e true,\n    'timeout'=\u003e 5000,\n    'args' =\u003e [\n        '--window-size=1366,768',\n    ],\n];\n\n$browser = $puppeteer-\u003econnect(['browserWSEndpoint' =\u003e 'ws://127.0.0.1:3000/chrome?launch='.urlencode(json_encode($options, JSON_UNESCAPED_UNICODE))]);\n$page = $browser-\u003enewPage();\n$page-\u003egoto('https://www.example.com');\n$page-\u003escreenshot(['path' =\u003e 'example.png']);\n$browser-\u003eclose();\n```\n\n## Notable differences between PuPHPeteer and Puppeteer\n\n### Puppeteer's class must be instantiated\n\nInstead of requiring Puppeteer:\n\n```js\nconst puppeteer = require('puppeteer');\n```\n\nYou have to instantiate the `Puppeteer` class:\n\n```php\n$puppeteer = new Puppeteer;\n```\n\nThis will create a new Node process controlled by PHP.\n\nYou 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:\n\n```php\n[\n    // Logs the output of Browser's console methods (console.log, console.debug, etc...) to the PHP logger\n    'log_browser_console' =\u003e false,\n]\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003e⏱ Want to use some timeouts higher than 30 seconds in Puppeteer's API?\u003c/strong\u003e\u003c/summary\u003e \u003cbr\u003e\n\nIf you use some timeouts higher than 30 seconds, you will have to set a higher value for the `read_timeout` option (default: `35`):\n\n```php\n$puppeteer = new Puppeteer([\n    'read_timeout' =\u003e 65, // In seconds\n]);\n\n$puppeteer-\u003elaunch()-\u003enewPage()-\u003egoto($url, [\n    'timeout' =\u003e 60000, // In milliseconds\n]);\n```\n\u003c/details\u003e\n\n### No need to use the `await` keyword\n\nWith PuPHPeteer, every method call or property getting/setting is synchronous.\n\n### Some methods have been aliased\n\nThe following methods have been aliased because PHP doesn't support the `$` character in method names:\n\n- `$` =\u003e `querySelector`\n- `$$` =\u003e `querySelectorAll`\n- `$eval` =\u003e `querySelectorEval`\n- `$$eval` =\u003e `querySelectorAllEval`\n\nUse these aliases just like you would have used the original methods:\n\n```php\n$divs = $page-\u003equerySelectorAll('div');\n// Runs the `//h2` as the XPath expression.\n$xpath = $page-\u003equerySelectorAll('::-p-xpath(//h2)');\n// div element that has Checkout as the inner text.\n$text = $page-\u003equerySelector('div ::-p-text(Checkout)');\n```\n\n### Evaluated functions must be created with `JsFunction`\n\nFunctions 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.\n\n```php\nuse Nesk\\Rialto\\Data\\JsFunction;\n\n$pageFunction = JsFunction::createWithParameters(['element'])\n    -\u003ebody(\"return element.textContent\");\n```\n\n### Exceptions must be caught with `-\u003etryCatch`\n\nIf 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`.\n\nTo avoid that, you can ask Node to catch these errors by prepending your instruction with `-\u003etryCatch`:\n\n```php\nuse Nesk\\Rialto\\Exceptions\\Node;\n\ntry {\n    $page-\u003etryCatch-\u003egoto('invalid_url');\n} catch (Node\\Exception $exception) {\n    // Handle the exception...\n}\n```\n\nInstead, a `Node\\Exception` will be thrown, the Node process will stay alive and usable.\n\n### Puppeteer plugins\n\nPuppeteer-extra and puppeteer-extra-plugin-stealth plugins already added in npm requirements.\n\nTo use them, override js inclusion with js_extra option\n```php\n    $puppeteer = new Puppeteer([\n        'js_extra' =\u003e /** @lang JavaScript */ \"\n            const puppeteer = require('puppeteer-extra');\n            const StealthPlugin = require('puppeteer-extra-plugin-stealth');\n            puppeteer.use(StealthPlugin());\n            instruction.setDefaultResource(puppeteer);\n        \"\n    ]);\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n\n## Logo attribution\n\nPuPHPeteer's logo is composed of:\n\n- [Puppet](https://thenounproject.com/search/?q=puppet\u0026i=52120) by Luis Prado from [the Noun Project](http://thenounproject.com/).\n- [Elephant](https://thenounproject.com/search/?q=elephant\u0026i=954119) by Lluisa Iborra from [the Noun Project](http://thenounproject.com/).\n\nThanks to [Laravel News](https://laravel-news.com/) for picking the icons and colors of the logo.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoonru%2Fpuphpeteer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoonru%2Fpuphpeteer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoonru%2Fpuphpeteer/lists"}