1

using Laravel-Sail, which is basically a convenient way to generate a docker-compose.yml to have a Webserver, MariaDB etc. locally, is causing trouble when it comes to the use of Browsershots, a Laravel-Package that provides Puppeteer.

Before I start

First of all: Puppeteer itself is working, as I extended the docker file and rebuilt the image.

What is the problem?

This part of my pdf-generation method is running forever and fails with timeout.

$view      = view('pdf.user', compact('user'));
$body_html = $view->render();

return response()->streamDownload(function () use (
    $body_html
) {
    echo Browsershot::html($body_html)->format('A4')
        ->margins(0, 0, 0, 0)->showBackground()
        ->addChromiumArguments([
            'font-render-hinting' => 'none',
        ])->noSandbox()->waitUntilNetworkIdle()->pdf();
});

As it turns out, this line within the blade-template is causing the issue:

<img src="{{asset('images/logo.png')}}" class="h-24 w-24">

Using tinker in the container, I found out that the assets() helper returns

asset('images/logo.png')
> http://myapp.test/images/logo.png

which is fine.

If I use a random image coming from another URL (not-dockerized), e.g. https://www.google.de/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png the view is being loaded and rendered fine.

So my question is: What could possibly be the problem here and how can I solve it?

SPQRInc
  • 162
  • 4
  • 23
  • 64

1 Answers1

2

I don't yet have an answer to this, but I think I've got a very similar problem in Laravel Sail when trying to use wkhtmltopdf to generate PDF files.

From the stock sail configuration, it does return a PDF except that; unfortunately, any externally linked images are empty due to being unresolvable using the site's local name (tts.test) from within the sail container.

If I add a reference to tts.test pointing to 127.0.0.1 into the container's /etc/hosts file, then the assets are now technically resolvable, but the process hangs until it times out.

What is very curious is that from a ps -ef | grep wkhtmltopdf command, I can see the hanging command including the location of the temporary HTML file it is working on, and if I run the same command interactively from sail shell then it produces the PDF output perfectly!! If I discover why it is hanging, I'll post an update here.

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
JonathanH-UK
  • 41
  • 1
  • 4