chrome-php/chrome
Control headless Chrome from PHP. chrome-php/chrome launches Chromium/Chrome, lets you navigate pages, evaluate JavaScript, take screenshots/PDFs, intercept network events, and automate workflows via the DevTools protocol—ideal for scraping, testing, and rendering.
symfony/dom-crawler (for static HTML) or puppeteer (Node.js) in PHP stacks.ChromeBrowserService) for dependency injection.| Risk Area | Mitigation Strategy |
|---|---|
| Chromium Dependency | Use Docker (e.g., chromium:latest) or system packages (apt-get install chromium). |
| Memory Leaks | Set maxMemory in Chrome options; kill stale processes via pkill -f chrome. |
| Timeouts/Flakes | Implement retries with exponential backoff for CDP commands. |
| JS Execution Safety | Sanitize inputs if running untrusted JS (e.g., via addInitScript). |
| Laravel Caching | Cache Chrome instances (e.g., singleton pattern) if reused frequently. |
ps aux)?puppeteer (Node.js) or playwright-php a better fit for async needs?symfony/dom-crawler + guzzle suffice?Chrome::navigate(), Chrome::screenshot().php artisan scrape:products).chrome-php workers.composer require chrome-php/chrome.alpine/chromium).pestphp/phpunit for browser tests.app/Services/ChromeBrowserService.php:
class ChromeBrowserService {
public function __construct(private Chrome $chrome) {}
public function generatePdf(string $url): string { ... }
}
Chrome::navigate('https://example.com')->waitForSelector('#content')->screenshot();
class GeneratePdfJob implements ShouldQueue {
public function handle() {
$pdf = Chrome::navigate($url)->pdf();
Storage::put($pdfPath, $pdf);
}
}
chrome-php/chrome for CDP breaking changes.chromium:120.0).chrome->on('error', fn($e) => Log::error($e)).chrome->debug() or attach to Chrome’s remote debugging port (--remote-debugging-port=9222).playwright-php if needed.chrome-php, cdp).generate-pdf:batch).maxMemory in Chrome options (e.g., --max-memory=4GB).Semaphore in Laravel).htop/docker stats.| Failure Scenario | Mitigation |
|---|---|
| Chromium Crashes | Implement health checks; restart stale processes. |
| CDP Timeouts | Retry with jitter; increase timeout in Chrome options. |
| Memory Leaks | Set maxMemory; kill processes after inactivity. |
| Network Issues | Fallback to cached artifacts or static HTML. |
| Queue Backlog | Throttle job dispatch rate; use afterCommit() for critical jobs. |
waitForSelector, evaluate).How can I help you explore Laravel packages today?