Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Browsershot’s Puppeteer addStyleTag option to inject CSS before taking a screenshot. Pass the option through setOption(), then call save() to write an image or screenshot() to get its bytes.

Inject CSS before the screenshot

For a live webpage, start with Browsershot::url(), set the CSS content, and then capture the page:

<?php

use SpatieBrowsershotBrowsershot;

$url = 'https://example.com';
$outputPath = storage_path('app/page.png');
$css = 'body { font-size: 14px; }';

Browsershot::url($url)
    ->setOption('addStyleTag', json_encode([
        'content' => $css,
    ]))
    ->save($outputPath);

This follows the image-capture method documented for Browsershot v4. The addStyleTag option is Puppeteer’s option for inserting a style element; it can take CSS content or a stylesheet URL. This example uses CSS content. See Spatie’s Browsershot v4 image guide and the Puppeteer addStyleTag API.

Choose how to receive the image

Write the screenshot to a file

Use save($path) when the application needs a file at a known location. Ensure the destination directory exists and that the PHP process can write to it. The sample uses a path under Laravel’s storage directory; change the output path and file extension to suit your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall

Return image bytes

Use screenshot() when the calling code needs the captured image data rather than a file written by Browsershot:

$imageBytes = Browsershot::url($url)
    ->setOption('addStyleTag', json_encode([
        'content' => $css,
    ]))
    ->screenshot();

The image guide documents both approaches. Choose one based on how the rest of your application handles the output; do not call save() when you specifically need the return value.

Rank #2
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
  • 1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core
  • 4GB DDR4 System Memory; 128GB Solid State Drive
  • 11.6" HD (1366 x 768) Multi-Touch Display
  • Combo headphone/microphone jack - Noble Wedge Lock slot - HDMI; 2 USB 3.1 Gen 1
  • Windows 11 Pro

Make the injected CSS reliable

  • Target the intended page elements. The injected rules run against the page’s DOM and styles. Use selectors that match the page you are capturing, and account for the page’s own CSS when choosing specificity.
  • Wait for the state you want to capture. Pages that build content with JavaScript or load it later may need a wait condition. Browsershot’s image guide covers delayed screenshots, waiting for a JavaScript function, and waiting for a selector. Choose the condition that corresponds to the content rather than assuming one fixed delay: image guide.
  • Check the actual output. Confirm that the saved file exists, opens as the expected image format, and has the dimensions your application requires. The appropriate output depends on the project’s installed Browsershot, Puppeteer, and Chrome versions and its environment.

Use the right capture path for the job

Browsershot is Spatie’s PHP package for rendering a URL or supplied HTML through Puppeteer and headless Chrome into an image or PDF. Use Browsershot::url($url) for a live webpage; Browsershot can also accept HTML input. See Browsershot’s overview.

Laravel Dusk is a different fit: it provides screenshots in the context of browser tests, including a method to capture a particular element. Use Dusk when the screenshot is test evidence; use the documented Browsershot path when the goal is generating an image with injected CSS. See Laravel Dusk screenshot documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.

Deployment, security, and troubleshooting

Chrome or Puppeteer does not run

Browsershot depends on a compatible installed setup of Browsershot, Puppeteer, and Chrome. The title does not specify their versions or the operating system, so there is no single installation command that applies to every Laravel project. Follow the requirements for the versions already installed and verify that the PHP process can launch the browser in the deployment environment.

Chrome fails in a restricted container

Some restricted environments, including some Docker configurations, may require Chrome’s no-sandbox mode. Spatie’s Laravel Screenshot guide documents configuring it globally or for an individual screenshot. Enable it only when the environment requires it, and consult that package’s documentation for the applicable configuration: Laravel Screenshot installation and setup.

Rank #4
15.6 Inch Laptop Computer, N4020, 4GB DDR4 RAM, 128GB eMMC,with Windows 11
  • EFFORTLESS EVERYDAY PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 Home system, delivering reliable, low-power efficiency for daily tasks like document editing, email, online classes, and web browsing
  • 15.6-INCH FULL HD DISPLAY: Enjoy immersive visuals on the 15.6" FHD (1920x1080) anti-glare screen with micro-edge bezels. Delivers clear details and comfortable viewing for long study sessions, working on spreadsheets, and video playback
  • RESPONSIVE MULTITASKING & STORAGE: Built with 4GB LPDDR4 RAM and 128GB eMMC storage for smooth daily essential use. Expand your storage by up to 1TB via the integrated TF card slot to easily store movies, photos, and working files
  • ADVANCED CONNECTIVITY: Outfitted with 2x Full-Featured Type-C ports for data transfer, fast charging, and dual-monitor output, alongside 2x USB 3.2 Gen1 ports and a 3.5mm audio jack for complete peripheral compatibility
  • LIGHTWEIGHT & SILENT OPERATION: Slim and portable for effortless travel or commuting. Features a 1MP HD webcam for remote meetings, 38Wh battery with 45W Type-C fast charging, and a fanless silent design for peaceful work environments.

The CSS or page content is missing

  • Check that the addStyleTag option is passed before save() or screenshot().
  • Confirm the CSS string is valid and its selectors match the rendered page.
  • If the page adds or reveals content asynchronously, use an appropriate wait condition such as a selector or JavaScript function, as described in the image guide.
  • Inspect the captured output in the same environment where the application runs; local browser behavior does not establish that the deployed browser setup is identical.

The destination file is missing

When using save($path), check that the parent directory exists, the path is the one your application expects, and the PHP process has permission to write there. If the caller needs the output in memory instead, use screenshot().

Untrusted URLs or HTML are involved

Validate input before passing it to Browsershot. Spatie warns: “It is the responsibility of the user to validate the URLs and HTML passed to browsershot. Only pass URLs and HTML that you trust.” See Spatie’s Browsershot requirements and security note.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Using the Laravel Screenshot wrapper

If your project uses Spatie’s Laravel Screenshot wrapper instead of calling Browsershot directly, withBrowsershot() exposes the underlying instance for one-off customization. Its documentation says closure-based customization is not compatible with saveQueued(), so do not assume the same customization works in queued saves. Check the wrapper’s current guidance for the exact version in your project: Using Browsershot with Laravel Screenshot.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. Its API can return a screenshot or PDF from one GET request, without setting up Puppeteer and Chrome in your Laravel application. The CSS injection example above is for direct Browsershot capture; use ScreenshotNeo when a managed screenshot request better suits the job.

See the ScreenshotNeo documentation. Example cURL request:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
  • It accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Responses include X-Page-Verdict and X-Billed headers.
  • Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$249.99
Bestseller No. 2
Dell Latitude 3190 11.6' HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core; 4GB DDR4 System Memory; 128GB Solid State Drive
$179.99
Bestseller No. 3
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$289.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.