Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lance2k's avatar

How to use Browsershot to generate the pdf screenshot of a certain page instead of the login page?

My task is to generate a pdf screenshot of a certain page. We're using Laravel for the BE (running on http://127.0.0.1:8000) and Angular on the FE (running on http://localhost:4200).

While trying to run the code below

public function generatePdf(Request $request, $id)
{
    $path = public_path("/uploads/");
    if (!File::exists($path)) {
        File::makeDirectory($path, 0755, true);
    }

    Browsershot::url('http://localhost:4200/#/dashboard')
    ->authenticate('[email protected]', 'Monday@123')
	 ->setExtraHttpHeaders(['Authorization' => 'Bearer sample_token'])
    ->select('.ng-star-inserted')
    ->setDelay(3000)
    ->save($path . 'example.pdf');
    echo 'Pdf generated at <i>public/uploads/example.pdf</i>';
}

Browsershot generates the pdf screenshot of http://localhost:4200/#/login instead of http://localhost:4200/#/dashboard. I'm pretty sure I used the correct credentials and access_token in authenticate() and Authorization.

0 likes
0 replies

Please or to participate in this conversation.