Увійти Реєстрація
Вакансії
Вакансії Laravel Компанії Статистика
Підготовка
Як підготуватися Співбесіди Тестування Документація
Блог
Всі статті Серії
Екосистема
Пакети Ресурси Проєкти Інструменти Події Відео
Інше
Про нас Реклама

Browsershot

spatie/browsershot
5.5.2 5,252 49.3M 30 листопада 2026
На GitHub

Конвертуй веб-сторінку в зображення або PDF, використовуючи headless Chrome.

8

Поділитись

README

Logo for Browsershot

Render web pages to an image or PDF with Puppeteer

Latest Version MIT Licensed run-tests Total Downloads

The package can convert a web page to an image or PDF. The conversion is done behind the scenes by Puppeteer which runs a headless version of Google Chrome.

Here's a quick example:

use Spatie\Browsershot\Browsershot;

// an image will be saved
Browsershot::url('https://example.com')->save($pathToImage);

It will save a PDF if the path passed to the save method has a pdf extension.

// a pdf will be saved
Browsershot::url('https://example.com')->save('example.pdf');

You can also use an arbitrary html input, simply replace the url method with html:

Browsershot::html('<h1>Hello world!!</h1>')->save('example.pdf');

Local file requests from html() are blocked by default, including absolute filesystem paths and JavaScript-generated file URLs. If your trusted HTML needs local assets, opt in with Browsershot::html($html)->allowLocalFileAccess()->save('example.pdf'). This permits access to any local file readable by Chrome; only enable it for trusted HTML. Browsershot is not a sandbox for untrusted content.

If your HTML input is already in a file locally use the :

Browsershot::htmlFromFilePath('/local/path/to/file.html')->save('example.pdf');

Browsershot also can get the body of an html page after JavaScript has been executed:

Browsershot::url('https://example.com')->bodyHtml(); // returns the html of the body

If you wish to retrieve an array list with all of the requests that the page triggered you can do so:

$requests = Browsershot::url('https://example.com')
    ->triggeredRequests();

foreach ($requests as $request) {
    $url = $request['url']; //https://example.com/
}

To use Chrome's new headless mode pass the newHeadless method:

Browsershot::url('https://example.com')->newHeadless()->save($pathToImage);

Support us

Learn how to create a package like this one, by watching our premium video course:

Laravel Package training

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Documentation

All documentation is available on our documentation site.

Testing

For running the testsuite, you'll need to have Puppeteer installed. Pleaser refer to the Browsershot requirements here. Usually npm -g i puppeteer will do the trick.

Additionally, you'll need the pdftotext CLI which is part of the poppler-utils package. More info can be found in in the spatie/pdf-to-text readme. Usually brew install poppler-utils will suffice.

Finally run the tests with:

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker.

Alternatives

If you're not able to install Node and Puppeteer, take a look at v2 of browsershot, which uses Chrome headless CLI to take a screenshot. v2 is not maintained anymore, but should work pretty well.

If using headless Chrome does not work for you take a look at at v1 of this package which uses the abandoned PhantomJS binary.

Credits

License

The MIT License (MIT). Please see License File for more information.

Коментарі

Увійдіть, щоб залишити коментар

Будьте першим, хто залишить коментар!

Схожі пакети

Image

intervention/image

Бібліотека для обробки зображень на PHP.

14,395 4.4.2 12

Laravel Excel

maatwebsite/excel

Імпорт та експорт Excel і CSV поверх PhpSpreadsheet: експорт з колекції чи запиту одним рядком, імпорт із валідацією і чергами для великих файлів. Найпоширеніше рішення для звітів і вивантажень.

12,704 4.0.1 13 4

Laravel Medialibrary

spatie/laravel-medialibrary

Пакет для асоціювання файлів з Eloquent-моделями. Надає зручний інтерфейс для управління медіа-файлами, пов'язаними з вашими моделями бази даних.

6,172 11.23.15 13 8

Image Optimizer

spatie/image-optimizer

Простий пакет для оптимізації зображень за допомогою PHP.

2,884 1.10.1 7

Fast Excel

rap2hpoutre/fast-excel

Швидкий імпорт та експорт Excel для Laravel.

2,395 v5.18.0 13 7

Pdf To Image

spatie/pdf-to-image

Конвертує PDF-файли в зображення.

1,459 3.5.0 10