Taking screenshots | laravel-screenshot | Spatie

 SPATIE

  Laravel Screenshot
=====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-screenshot](https://spatie.be/docs/laravel-screenshot/v1)  Basic-usage  Taking screenshots

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-screenshot/v1)

- [ Introduction ](https://spatie.be/docs/laravel-screenshot/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-screenshot/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-screenshot/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-screenshot/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-screenshot/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-screenshot/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-screenshot/v1/about-us)

Basic usage
-----------

- [ Taking screenshots ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/taking-screenshots)
- [ Customizing screenshots ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/customizing-screenshots)
- [ Saving screenshots to disks ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/saving-screenshots-to-disks)
- [ Queued screenshot generation ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/queued-screenshot-generation)
- [ Testing screenshots ](https://spatie.be/docs/laravel-screenshot/v1/basic-usage/testing-screenshots)

Drivers
-------

- [ Configuration ](https://spatie.be/docs/laravel-screenshot/v1/drivers/configuration)
- [ Customizing Browsershot ](https://spatie.be/docs/laravel-screenshot/v1/drivers/customizing-browsershot)
- [ Using the Cloudflare driver ](https://spatie.be/docs/laravel-screenshot/v1/drivers/using-the-cloudflare-driver)
- [ Custom drivers ](https://spatie.be/docs/laravel-screenshot/v1/drivers/custom-drivers)

Advanced usage
--------------

- [ Extending with macros ](https://spatie.be/docs/laravel-screenshot/v1/advanced-usage/extending-with-macros)

 Taking screenshots
==================

###  On this page

1. [ Screenshotting a URL ](#content-screenshotting-a-url)
2. [ Screenshotting HTML ](#content-screenshotting-html)
3. [ Using JavaScript ](#content-using-javascript)

This package can take screenshots of any URL or raw HTML.

Screenshotting a URL
--------------------------------------------------------------------------------------------------------------------

The most common use case is taking a screenshot of a URL:

```
use Spatie\LaravelScreenshot\Facades\Screenshot;

Screenshot::url('https://example.com')->save('screenshot.png');
```

Screenshotting HTML
-----------------------------------------------------------------------------------------------------------------

You can also take a screenshot from a string of HTML:

```
use Spatie\LaravelScreenshot\Facades\Screenshot;

Screenshot::html('Hello world!')->save('hello.png');
```

Using JavaScript
--------------------------------------------------------------------------------------------------------

The JavaScript in your HTML will be executed when the screenshot is taken. You could use this to have a JavaScript charting library render a chart.

Here's a simple example. If you screenshot this HTML...

```

    document.getElementById('target').innerHTML = 'hello';

```

... using this code...

```
use Spatie\LaravelScreenshot\Facades\Screenshot;

Screenshot::html($html)->save('screenshot.png');
```

... the text `hello` will be visible in the screenshot.
