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

Pinchanzee's avatar

Browsershot URL behind Auth Middleware in Laravel 11

I have been attempting to take a screenshot of a page behind the Auth Middleware but have failed so far trying the various solutions I've found online and my own experimentation - always capturing the login page. The code essentially boils down to:

Browsershot::url($url) ->withCookies($cookies)

Using various attempts of using data from request()->cookie(). I even tried temporarily hardcoding the cookies as they appear in the browser (to see if that was the right direction to head), but nothing I've passed to ->withCookies has worked.

I can't drop the Auth Middleware for this route because I do need to authenticate the user - they need to only be able to screenshot the resources they own. I can get it mostly working using Browsershot::html, but that's not fit for my purpose as the view has Alpine JS that needs to be executed to complete the display.

At this point though I'm considering I may have to:

  1. Drop the middleware for the route
  2. Validate user access to the $url and save a custom token in the database signifying authentication
  3. Call Browsershot
  4. In the controller for the $url, check for the custom token from 2 But that seems horrendously hacky in a framework that has so far given me everything I've needed very cleanly.

So I'm wondering if I have missed some obvious way of doing this, or whether those with more experience perhaps have cleaner workarounds to suggest?

0 likes
0 replies

Please or to participate in this conversation.