How to Get Browser screenshots Using Laravel?




How to Get Browser screenshots Using Laravel?

Hello Friends,

This tutorial will teach you how to take a screenshot in Laravel. Here, you will discover how to screenshot a website's url using Laravel. You may comprehend the idea behind how to screenshot a website in Laravel using the url. We'll demonstrate how to snap a screenshot in Laravel with your assistance. Okay, let's get into the specifics.

We will use spatie/browsershot composer package for take a screenshot of website in laravel. we will use url(), setOption(), windowSize(), waitUntilNetworkIdle() and save() method to capture browser screenshot in

Now let's start.

Step 1:Install Laravel Application

This is optional; however, if you have not created the laravel app, then you may go ahead and execute the below command:

composer create-project laravel/laravel example-app

Step 2: Install spatie/browsershot Package

Installing the spatie/browsershot package will enable us to take a snapshot of a URL in Laravel. Let's execute the following commands:

composer require spatie/browsershot

Next, we need to install puppeteer npm package, that used to capture screenshot. let's installed using the below command:

npm install puppeteer --global

Step 3: Create Route

In this is step we need to create one route for capture browser screenshot. let's add the below route on web.php file.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\DemoController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!



Route::get('demo', [DemoController::class,'index']);

Step 4: Create Controller

We need to create a DemoController with the index() method in this stage.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Spatie\Browsershot\Browsershot;

class DemoController extends Controller



* Write code on Method


* @return response()


public function index(Request $request)



->setOption('landscape', true)

->windowSize(3840, 2160)






Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

php artisan serve


I hope it can help you...