ahoi's avatar
Level 5

Browsershots::html does not work in Docker/Sail properly

Hello there,

I got a strange issue:

I got Browsershots working with laravel-sail, following the advice to publish the docker file and rebuild the image.

Well - but now I got this issue:

$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();
});

is running foreeeever using Laravel sail and does not complete once yet, while

return response()->streamDownload(function () {
    echo Browsershot::url('https://laracasts.com')->format('A4')
        ->margins(0, 0, 0, 0)->showBackground()
        ->addChromiumArguments([
            'font-render-hinting' => 'none',
        ])->noSandbox()->waitUntilNetworkIdle()->pdf();
});

completes within a second.

If I make $body_html incredible small like $body_html = "<strong>test</strong> it works fine but as soon as it grows a little - it's not that complex - the task does not finish.

Any ideas? The same stuff is working fine on homestead/vagrant on VirtualBox provider.

0 likes
2 replies
ahoi's avatar
Level 5

Inside the HTML there are assets being loaded like this:

<link href="{{ asset(('/css/app.css')) }}" rel="stylesheet">

Inside Sail the asset points to an URL like this:

asset(('/css/app.css'))

> "http://myapp.test/css/app.css"

But indeed the host can be resolved. So this is not the problem. But Browsershots is stuck when I load an asset like a small image or css.

E.g. if I don't load

<div class="margined-bottom-default unbreak-element">
	<img src="{{asset('images/logo.png')}}" class="h-24 w-24">
</div>

or the css asset(('/css/app.css')) the pdf can be displayed. But the image is only a few kb. And if I include the same logo using an image-hoster, it works fine...

So maybe there's a problem using concurrent connections in sail...?

daniel_san's avatar

I solved this by directly inserting css via file_get_contents and including images base64_encoded.

Please or to participate in this conversation.