Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' not found

Published 3 years ago by lucasvrm

Hello there!

I´ve installed a package called spatie/browsershot and I followed the steps showed here

But it's not working at all...

I am new to laravel, so probably this is a silly mistake... What I am doing wrong?

function inside a controller

public function create_preview()
        $findhash = Link::where('hash', '=', $hash)->firstOrFail();
    $browsershot = new Spatie\Browsershot\Browsershot();

        return view('pages.teste2');



    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "guzzlehttp/guzzle": "~6.0",
        "greggilbert/recaptcha": "^2.0",
        "symfony/dom-crawler": "^2.7",
        "fabpot/goutte": "^3.1",
        "pragmarx/tracker": "^1.0",
        "geoip/geoip": "~1.14",
        "spatie/laravel-analytics": "^1.2",
        "roumen/sitemap": "^2.5",
        "ramsey/uuid": "^2.8",
        "intervention/image": "^2.3",
        "spatie/browsershot": "^1.2"

@lucasvrm Try this:

$browsershot = new \Spatie\Browsershot\Browsershot();

Or, import it at the top and then use it:

use Spatie\Browsershot\Browsershot;


public function create_preview()
    $browsershot = new Browsershot();
3 years ago (64,200 XP)

@lucasvrm Are you receiving errors? Could you elaborate a bit more?


Did you register the service provider?


@thomaskim I did what you told:

$browsershot = new \Spatie\Browsershot\Browsershot();

But now I get another error:

Whoops, looks like something went wrong.
1/1 Exception in Browsershot.php line 172: could not create screenshot

    in Browsershot.php line 172
    at Browsershot->save('previews/arstechnica-browsershot.jpg') in LinksController.php line 121
    at LinksController->show_all()
    at call_user_func_array(array(object(LinksController), 'show_all'), array()) in Controller.php line 256
    at Controller->callAction('show_all', array()) in ControllerDispatcher.php line 164
    at ControllerDispatcher->call(object(LinksController), object(Route), 'show_all') in ControllerDispatcher.php line 112
    at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))

@zachleigh yes I registered the service provider...


@lucasvrm At least we know that you installed it correctly now. :)

I took a quick peak at the code. This new error seems like it's one of two things:

  1. Your image file doesn't exist.
  2. If it does exist, it's too big. It cannot be bigger than 1024 bytes.

@thomaskim What do you mean by "your image file doesn't exist"? I am trying to create an image file... This spatie/browsershot package intent is to create screenshots from a specified url address.

Where did you take a quick peack at the code? I´m asking just to learn with you hahaha


@lucasvrm Open your Browsershot's file. This is what I see when I go to line 172.

if (! file_exists($targetFile) OR filesize($targetFile) < 1024)
    throw new Exception('could not create screenshot');

file_exists checks whether a file or directory exists. filesize gets the file's size in bytes. If the file does not exist or if the file is too big, it'll throw that error.

The creator of the package also said on that page that it'll have trouble with javascript-heavy sites. I'm not sure if that's related to your site.


@thomaskim I tested with a very light site ( and it did not work... I think this is not the problem...

I tested after decreasing the width and height to see if the problem was related to the size of the image but it did not work either...

It was as simple as that to take a quick peack at the code, wasn´t it? hahaha

I am very new to this laravel, php, javascript world...


@lucasvrm After reading the comments on github, I think I found the solution. I'm not sure what OS you're on, but the phantomjs file that comes packaged with this is intended for Linux.

Edit: If you're not using linux, follow @sitesense's advice below. :)


Actually, if you want to work with PhantomJS, I suggest you install Node.js ( ) and then run npm install phantomjs from the command line.


@thomaskim I am using linux.... @sitesense Thanks for the advice...

I think the error might be something about dir permissions... spatie/browsershot uses phantomjs and I saw here that phantomjs has to be writable in the screenshots folder...

I'll get back to this issue later... Thanks for your help and attention!

As soon as I manage this issue I´ll let you know...


Did you install all the dependencies of PhantomJS? I ran into a missing dependency for PhantomJS on a project at my work. It was missing a lib called something like libicu48.


@thomaskim I gave up trying to use the spatie/browsershot package... Searching the web, I found another package, created and maintained by a laracasts user, @_stefanzweifel . I installed it, I had some issues to run it (obviously!! I am learning php, laravel, composer, etc while coding hahaha). And Stefan was so attentive: he helped me with everything I needed! Every github issue was answered asap!

I am glad that I managed to achieve what I wanted! I just wanted to grab a website screenshot and save it on local disk. I use this screenshot to show a preview of a shortened url. I am building (just for learning purposes) a url shortener app...

But..... I have a problem now and I am quite sure I will learn a lot resolving it... Every time a user shortens a url, the success view takes too long to render, because the app is grabbing the screenshot of that website...

What I want to do is: to take the user to the success page, and to grab the screenshot and save it on local disk, after that... Like a background process...

I searched the web, laracasts and other laravel´s help sites, but I couldn´t find a solution or a way to do that.

Do you know how I can do that?


My code is inside a controller...

---some validation---
$hash = Str::random(5);
            $website_to_screenshot = $request->input('hewit');
            $screenshot_name = $hash.'.jpg';
            $preview_path = ''.$hash.'.jpg';

            $screenshot = new Screenshot('APIKey');
            $screenshot->store('/home/frgcplql/public_html/', $screenshot_name);

            $hewed = ''. $hash;

            $link = Link::create([

                'url'           => $request->input('hewit'),
                'hash'          => $hash,
                'preview_path'  => $preview_path,


            return Redirect::home()->with([
                'hewed'       => $hewed,
                'hash'        => $hash,
3 years ago (13,985 XP)

Search for queu in the laravel docs!

Please sign in or create an account to participate in this conversation.