- How do I install spatie/browsershot in a Laravel project?
- Run `composer require spatie/browsershot` in your project directory. The package requires Node.js (≥18.x) and Chrome/Chromium (≥113.0). For Docker deployments, include a Node.js layer or use `puppeteer-core` to avoid bundling Chrome.
- Does this package support Laravel queues for async PDF/image generation?
- Yes. Use `Browsershot::url()->delay(60)->save()` to dispatch jobs to Laravel queues. This is useful for batch processing or long-running renders. Ensure your queue worker has Node.js installed.
- Can I generate multi-page PDFs with spatie/browsershot?
- Yes, leverage Puppeteer’s `pdf()` options via `setNodeOptions()`. For example, pass `['format': 'A4', 'printBackground': true]` to control pagination. Combine with `htmlFromFilePath()` for complex layouts.
- What Laravel versions does spatie/browsershot support?
- The package works with Laravel 8+, tested up to PHP 8.5. For older versions, ensure compatibility with the underlying Puppeteer version (check `composer.json` for constraints).
- How do I block untrusted URLs or local file access in production?
- Use `setBlockedRequests(['file://*', 'http://untrusted.com'])` to restrict URLs. This is critical for security, especially when rendering external content. Enable it via `Browsershot::setBlockedRequests()` before rendering.
- Is there a way to optimize memory usage for batch PDF generation?
- Reuse Chrome instances by setting `setNodeOptions(['--no-sandbox'])` in Docker and limit concurrent jobs. For high-volume tasks, implement sleep delays between jobs to avoid OOM errors. Use `throwOnRemoteConnectionError()` to handle failures gracefully.
- Can I extract searchable text from generated PDFs?
- Yes, install `poppler-utils` on your system (e.g., `sudo apt-get install poppler-utils`). This enables OCR-like text extraction for searchable PDFs. The package doesn’t handle this directly but integrates with system tools.
- How do I debug failed renders or network request issues?
- Use `triggeredRequests()` to inspect network activity. For errors, enable verbose logging with `setNodeOptions(['--remote-debugging-port=9222'])` and connect via Chrome DevTools. Wrap calls in `try-catch` to log failures.
- What are the alternatives to spatie/browsershot for Laravel?
- For static HTML, consider `dompdf` (pure PHP but limited JS support) or `wkhtmltopdf` (lighter but no JS rendering). For Node.js-only solutions, `puppeteer-sharp` exists, but browsershot bridges this gap for PHP/Laravel.
- How do I deploy spatie/browsershot in a serverless environment like AWS Lambda?
- Use `puppeteer-core` (no bundled Chrome) and pre-install Node.js in your Lambda layer. Avoid `--no-sandbox` for security. Test with small payloads first, as Lambda has memory/time limits.