pwaldhauer/browsershot-aio

All in one Docker Container to run Browsershot

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

v0.1 2023-06-08 13:13 UTC

This package is auto-updated.

Last update: 2024-05-08 15:24:18 UTC


README

This is a combinaton of two things:

  • A Docker image based on alpine-chrome including a simple Express server that executes the command generated by the Browsershot library by Spatie
  • A simple PHP wrapper that extends the original Browsershot library with the code to call the Express server instead of using node to call Puppeteer

Why?

  • I do not want to include Node and Puppeteer in my main PHP application image
  • I do not want to mess with all the hassle of using remoteInstance
  • I do not want to use Lambda functions using the wonderful sidecar-browsershot library (Instead I was heavily influenced by it.)

Caution

It may very well be that half of the functions of Browsershot do not work. I just tested simple pdf generation. Also the Express server has no authentication. I won't recommend using this in a production environment.

Running

For more information please see the README of alpine-chrome

docker container run -p 3000:3000 -it --rm --cap-add=SYS_ADMIN ghcr.io/pwaldhauer/browsershot-aio

Or use something like that in a docker-compose.yml:

  chrome:
    image: ghcr.io/pwaldhauer/browsershot-aio
    restart: unless-stopped
    cap_add:
      - SYS_ADMIN

Using in PHP

Use it like you would use Browsershot but replace it with BrowsershotAio. Be sure to set the url to the express server:

use pwaio\BrowsershotAio\BrowsershotAio;

BrowsershotAio::setEndpoint('http://chrome:3000');

// if you do not want to create a shared volume for your containers
$data = BrowsershotAio::url('https://example.com')->base64Screenshot();

// an image will be saved (needs a shared volume)
BrowsershotAio::url('https://example.com')->save($pathToImage);

// a pdf will be saved (needs a shared volume)
BrowsershotAio::url('https://example.com')->save('example.pdf');

License

MIT