- What is chrome-php/chrome used for in a Laravel application?
- chrome-php/chrome is a PHP client for the Chrome DevTools Protocol that controls a headless Chrome or Chromium binary over a WebSocket connection. In Laravel it is typically used for server-side PDF generation, screenshot and OG-image capture, authenticated page scraping, and extracting content from JavaScript-rendered pages. It is a low-level browser-control library rather than a full scraping or automation framework, so it fits best when you scope it to concrete endpoints such as invoices, reports, or preview images. It requires PHP 7.4+ and a Chrome/Chromium 65+ executable.
- How do I install chrome-php/chrome with Composer?
- Install it with composer require chrome-php/chrome; the package is available on Packagist under chrome-php/chrome and uses the MIT license. It has no Laravel framework coupling, so you can use it directly or wrap it in a service provider and config file. You must also provide a Chrome or Chromium executable in every environment, either by setting CHROME_PATH or passing the binary name to BrowserFactory. The library is tested on Linux but is described as compatible with macOS and Windows.
- Which PHP and Laravel versions does chrome-php/chrome support?
- The package requires PHP 7.4 through 8.5 and a Chrome/Chromium 65+ executable, and it is framework-agnostic. Because it has no hard Laravel dependency, it can be used in Laravel applications that run on a supported PHP version; the practical constraint is your Laravel version's PHP requirement, not a package-specific Laravel integration. Always verify the current composer.json constraints before upgrading PHP or Laravel. Chrome 65+ is a minimum, not a guaranteed compatibility matrix, so pin your browser binary in production.
- How can I generate a PDF in Laravel using chrome-php/chrome?
- Create a page, navigate to the URL or local HTML you want to render, call the page's pdf method with options such as printBackground, and save the result to a file or stream it as a response. The browser must be able to reach the URL, so local Laravel routes need a reachable host and authentication must be handled deliberately. PDF fidelity depends on the Chrome version and print CSS, so test invoices and reports against your pinned binary. Wrap browser startup and shutdown in try/finally to avoid orphaned processes.
- How do I take a screenshot of a web page with chrome-php/chrome?
- Start a browser with BrowserFactory, create a page, navigate to the target URL, wait for navigation, then call screenshot and saveToFile or read the binary data. You can set viewport dimensions and other screenshot options before capturing. For JavaScript-heavy pages, wait for a selector or network idle condition before taking the screenshot. The same lifecycle rules apply: close the browser in a finally block and avoid leaving temporary user data directories behind.
- Is chrome-php/chrome safe for rendering user-supplied URLs?
- Rendering arbitrary user URLs exposes you to SSRF against internal networks, file:// access, and untrusted content reaching the browser engine. Restrict navigation to an allowlist, block private IP ranges and metadata endpoints, and apply egress filtering at the network layer. Avoid noSandbox in production; the documented Docker workaround removes a primary Chrome security boundary and is only acceptable with a read-only, user-namespaced container and strict URL controls. Treat the browser as an untrusted component and run it with least privilege.
- How do I prevent zombie Chrome processes and memory leaks in production?
- Browser lifecycle is your responsibility: orphaned Chrome processes, leaked temporary userDataDir directories, and memory growth in long-lived browsers are common production failures. Use keepAlive or connectToBrowser to reuse instances where appropriate, but build health checks, reaping, and a restart policy around them. Run browsers inside queue jobs with clear timeouts, and ensure finally blocks close pages and browsers. Monitor process counts, temp directory usage, and worker memory so you can restart before failures cascade.
- Can chrome-php/chrome run multiple browsers concurrently in Laravel?
- The library's asynchronous API means non-blocking calls within a single PHP process; it does not provide worker-level concurrency or a built-in browser pool. Real concurrency in Laravel comes from queue workers and a controlled pool of browser instances, with limits on how many Chrome processes each host can support. Synchronous navigation and JavaScript evaluation block the PHP worker, so keep browser work out of web requests and run it on dedicated queues. Size the pool against CPU and memory, not against the number of queued jobs.
- Does chrome-php/chrome support authenticated proxies?
- The README explicitly states that proxy authentication with credentials does not work, so an authenticated corporate proxy is a blocker or requires an architectural workaround. If your egress depends on credentialed proxies, test this before committing to the package. Possible workarounds include unauthenticated egress through a controlled gateway, network-level proxy configuration, or a different browser automation stack. Do not assume Chromium proxy flags will solve it through the library's current API.
- Is chrome-php/chrome actively maintained, and how does it compare to Playwright?
- chrome-php/chrome has active releases and a changelog, but it is community-maintained with no vendor SLA, so confirm contributor concentration and security-patch expectations for your risk tolerance. Symfony Panther's Chrome support runs on top of it, which is a strong ecosystem signal even though the supplied metadata reports zero dependents. Compared with Playwright or Puppeteer, chrome-php/chrome is a lower-level Chrome DevTools Protocol client and lacks richer tracing, video, request interception, test runners, and browser download management. Choose it for focused Laravel PDF, screenshot, or JS-rendered scraping endpoints when you can own browser lifecycle, and choose Playwright or Puppeteer for deeper automation and network mocking.