How to Take Browser Screenshots in Laravel


Laravel take/make browser screenshots; Through this tutorial, you will learn how to take/make browser screenshots in laravel using browsershot package.

How to Take Browser Screenshots in Laravel

Use the following steps to make/take browser screenshots in laravel:

  • Step 1 – Install Laravel
  • Step 2 – Install Browsershot Package
  • Step 3 – Create Route
  • Step 4 – Create Controller using Artisan
  • Step 5 – Run Laravel App

Step 1 – Install Laravel

First of all, execute the following command on terminal to install laravel app latest version:

composer create-project laravel/laravel blog-example

Step 2 – Install Browsershot Package

Then execute the following command on terminal to install browsershot package in laravel apps:

composer require spatie/browsershot
npm install puppeteer --global

Step 3 – Create Route

Now, visit routes directory and open web.php file. And create one route for capture browser screenshot:

<?php
  
use Illuminate\Support\Facades\Route;
  
use App\Http\Controllers\TestController;
  
/*
|--------------------------------------------------------------------------
| 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('test', [TestController::class,'index']);

Step 4 – Create Controller using Artisan

Execute the following command on terminal to create controller class in laravel apps:

php artisan make:controller TestController

After that, open controller folder/directory and open testcontroller.php. And add the folowing code into it:

<?php
 
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Spatie\Browsershot\Browsershot;
  
class TestController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index(Request $request)
    {
        Browsershot::url('https://www.tutsmake.com')
            ->setOption('landscape', true)
            ->windowSize(3840, 2160)
            ->waitUntilNetworkIdle()
            ->save('tutsmake.jpg');
  
        dd("Done");
    }
}

Step 5 – Run Laravel App

Execute the following command on temrinal to start laravel apps:

php artisan serve

Now, Go to your web browser, hit the following URL into it:

http://localhost:8000/demo

Conclusion

That’s all; Through this tutorial, you have learned how to take/make browser screenshots in laravel using browsershot package.

Recommended Laravel Tutorials


Discover more from Jassweb

Subscribe to get the latest posts sent to your email.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00