Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Browsershot

Browsershot Laravel Package

spatie/browsershot

Convert web pages or HTML to images and PDFs using headless Chrome via Puppeteer. Capture screenshots, generate PDFs, render JS, extract body HTML, and inspect network requests. Simple fluent API for URLs, raw HTML, or local HTML files.

View on GitHub
Deep Wiki
Context7

Convert HTML to an image, PDF or string

Frequently asked questions about Browsershot
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony