{"id":15631492,"url":"https://github.com/stefanzweifel/sidecar-browsershot","last_synced_at":"2025-05-16T15:06:41.047Z","repository":{"id":39653134,"uuid":"453678276","full_name":"stefanzweifel/sidecar-browsershot","owner":"stefanzweifel","description":"A Sidecar function to run Browsershot on Lambda.","archived":false,"fork":false,"pushed_at":"2025-05-08T05:37:12.000Z","size":9642,"stargazers_count":209,"open_issues_count":8,"forks_count":32,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-08T06:28:18.488Z","etag":null,"topics":["aws","lambda","laravel","laravel-package","puppeteer"],"latest_commit_sha":null,"homepage":"https://stefanzweifel.dev/posts/2022/06/21/introducing-sidecar-browsershot","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefanzweifel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"stefanzweifel","custom":["https://buymeacoff.ee/3oQ64YW"]}},"created_at":"2022-01-30T12:47:53.000Z","updated_at":"2025-04-26T00:30:36.000Z","dependencies_parsed_at":"2024-03-26T08:32:52.952Z","dependency_job_id":"c6a2b1eb-4e92-4956-bb2e-da44d2439e3a","html_url":"https://github.com/stefanzweifel/sidecar-browsershot","commit_stats":{"total_commits":145,"total_committers":18,"mean_commits":8.055555555555555,"dds":0.4896551724137931,"last_synced_commit":"d7442a342b63961f80082564f0e9fa1eee85538c"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanzweifel%2Fsidecar-browsershot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanzweifel%2Fsidecar-browsershot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanzweifel%2Fsidecar-browsershot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanzweifel%2Fsidecar-browsershot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefanzweifel","download_url":"https://codeload.github.com/stefanzweifel/sidecar-browsershot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254553959,"owners_count":22090417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","lambda","laravel","laravel-package","puppeteer"],"created_at":"2024-10-03T10:40:38.509Z","updated_at":"2025-05-16T15:06:41.027Z","avatar_url":"https://github.com/stefanzweifel.png","language":"PHP","funding_links":["https://github.com/sponsors/stefanzweifel","https://buymeacoff.ee/3oQ64YW"],"categories":[],"sub_categories":[],"readme":"# Run Browsershot on AWS Lambda with Sidecar for Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/wnx/sidecar-browsershot.svg?style=flat-square)](https://packagist.org/packages/wnx/sidecar-browsershot)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/stefanzweifel/sidecar-browsershot/run-tests.yml?label=tests\u0026style=flat-square)](https://github.com/stefanzweifel/sidecar-browsershot/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/stefanzweifel/sidecar-browsershot/laravel-pint-fixer.yml?label=code%20style\u0026style=flat-square)](https://github.com/stefanzweifel/sidecar-browsershot/actions?query=workflow%3A%22Laravel+Pint%22+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/wnx/sidecar-browsershot.svg?style=flat-square)](https://packagist.org/packages/wnx/sidecar-browsershot)\n\nThis package allows you to run [Browsershot](https://github.com/spatie/browsershot) on [AWS Lambda](https://aws.amazon.com/lambda/) through [Sidecar](https://github.com/hammerstonedev/sidecar).\n\nYou won't need to install Node, Puppeteer or Google Chrome on your server. The heavy lifting of booting a headless Google Chrome instance is happening on AWS Lambda.\n\n## Requirements\n\nThis package requires that [`spatie/browsershot`](https://github.com/spatie/browsershot) and [`hammerstone/sidecar`](https://github.com/hammerstonedev/sidecar) have been installed in your Laravel application.\n\nFollow their installation and configuration instructions. (You can skip the installation of puppeteer and Google Chrome for Browsershot though.)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require wnx/sidecar-browsershot\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"sidecar-browsershot-config\"\n```\n\nRegister the `BrowsershotFunction::class` in your `sidecar.php` config file.\n\n```php\n/*\n * All of your function classes that you'd like to deploy go here.\n */\n'functions' =\u003e [\n    \\Wnx\\SidecarBrowsershot\\Functions\\BrowsershotFunction::class,\n],\n```\n\nDeploy the Lambda function by running:\n\n```shell\nphp artisan sidecar:deploy --activate\n```\n\nSee [Sidecar documentation](https://hammerstone.dev/sidecar/docs/main/functions/deploying) for details.\n\n\u003e [!Note]\n\u003e You should redeploy the Lambda function, whenever you upgrade `spatie/browsershot`.\n\n## Usage\n\nYou can use `BrowsershotLambda` like the default `Browsershot`-class coming from the Spatie package.\nAll you need to do is replace `Browsershot` with `BrowsershotLambda`.\n\n```php\nuse Wnx\\SidecarBrowsershot\\BrowsershotLambda;\n\n// an image will be saved\nBrowsershotLambda::url('https://example.com')-\u003esave($pathToImage);\n\n// a pdf will be saved\nBrowsershotLambda::url('https://example.com')-\u003esave('example.pdf');\n\n// save your own HTML to a PDF\nBrowsershotLambda::html('\u003ch1\u003eHello world!!\u003c/h1\u003e')-\u003esave('example.pdf');\n\n// Get HTML of a URL and store it on a given disk\n$html = BrowsershotLambda::url('https://example.com')-\u003ebodyHtml();\nStorage::disk('s3')-\u003eput('example.html', $html);\n```\n\n## Warming\n\nsidecar-browsershot supports [warming](https://hammerstone.dev/sidecar/docs/main/functions/warming) for faster execution.\n\nTo enable this feature set the `SIDECAR_BROWSERSHOT_WARMING_INSTANCES` variable in your `.env` to the desired number of instances Sidecar should warm for you.\n\n```shell\nSIDECAR_BROWSERSHOT_WARMING_INSTANCES=5\n```\n\nAlternatively you can publish the `sidecar-browsershot.php` config file and change the `warming` setting yourself.\n\n## Reading source from S3\n\nYou can store an HTML file on AWS S3 and pass the path to Lambda for it to create the PDF or image from. \nThis is necessary for large source files in order to avoid restrictions on the size of Lambda requests.\n\n```php\nuse Wnx\\SidecarBrowsershot\\BrowsershotLambda;\n\n// Use an HTML file from S3 to generate a PDF\nBrowsershotLambda::readHtmlFromS3('html/example.html')-\u003esave('example.pdf');\n\n// You can also pass a disk name if required (default: 's3')\nBrowsershotLambda::readHtmlFromS3('html/example.html', 's3files')-\u003esave('example.pdf');\n```\n\n## Saving directly to S3\n\nYou can store your file directly on AWS S3 if you want to keep it there, or to avoid the size limit on Lambda responses.\n\nYou just need to pass a path and optional disk name (default: 's3') to the `saveToS3` method.\n- You must have an S3 disk defined in config/filesystems.php\n- You must give S3 write permissions to your sidecar-execution-role\n\n```php\nuse Wnx\\SidecarBrowsershot\\BrowsershotLambda;\n\n// an image will be saved on S3\nBrowsershotLambda::url('https://example.com')-\u003esaveToS3('example.jpg');\n\n// a pdf will be saved on S3\nBrowsershotLambda::url('https://example.com')-\u003esaveToS3('example.pdf');\n\n// save your own html to a PDF on S3\nBrowsershotLambda::html('\u003ch1\u003eHello world!!\u003c/h1\u003e')-\u003esaveToS3('example.pdf', 'example-store');\n```\n\n## Image Manipulation\nLike the original Browsershot package, you can [manipulate the image](https://spatie.be/docs/browsershot/v4/usage/creating-images#content-sizing-the-image) size and format.\n\nTo perform image manipulations on the screenshot, you need to install the optional dependency `spatie/image`. v3 or higher is required.\n\n\u003e **Note**   \n\u003e If you're using `fit()` in combination with `saveToS3`, the image will be downloaded from S3 to your local disc, manipulated and then uploaded back to S3.\n\n```php\n// Take screenshot at 1920x1080 and scale it down to fit 200x200 \nBrowsershotLambda::url('https://example.com')\n    -\u003ewindowSize(1920, 1080)\n    -\u003efit(\\Spatie\\Image\\Enums\\Fit::Contain, 200, 200)\n    -\u003esave('example.jpg');\n    \n// Take screenshot at 1920x1080 and scale it down to fit 200x200 and save it on S3\n// Note: To do the image manipulation, BrowsershotLambda will download the image\n// from S3 to the local disc of your app, manipulate it and then upload it back to S3. \nBrowsershotLambda::url('https://example.com')\n    -\u003ewindowSize(1920, 1080)\n    -\u003efit(\\Spatie\\Image\\Enums\\Fit::Contain, 200, 200)\n    -\u003esaveToS3('example.jpg');\n```\n\n## Register Custom Fonts\n\nBy default, sidecar-browsershot includes the \"Noto Color Emoji\"-font, to ensure that emojis are rendered correctly.\nIf you want to use custom fonts, you can put them all into a `resources/sidecar-browsershot/fonts`-folder. (You can customize the location of that folder in the `sidecar-browsershot.fonts` config)\n\nsidecar-browsershot will include all files in that folder when deploying the Lambda function and will register them automatically in Chromium for you.\n\n## Testing\n\nThe testsuite makes connections to AWS and runs the deployed Lambda function. In order to run the testsuite, you will need an active [AWS account](https://aws.amazon.com/).\n\nWe can use the native `sidecar:configure` artisan command to create the necessary AWS credentials for Sidecar. First copy the `testbench.example.yaml` file to `testbench.yaml`.\nThen run `./vendor/bin/testbench sidecar:configure` to start the Sidecar setup process. (You only have to do the setup once)\n\n```bash\ncp testbench.example.yaml testbench.yaml\ncp .env.example .env\n./vendor/bin/testbench sidecar:configure\n```\n\nAfter finishing the Sidecar setup process, you will have received a couple of `SIDECAR_*` environment variables. Add these credentials to `.env`.\n\nNow we can deploy our local `BrowsershotFunction` to AWS Lambda. Run the following command in your terminal, before executing the testsuite.\n\n```bash\n./vendor/bin/testbench sidecar-browsershot:setup\n```\n\nAfter the successful deployment, you can run the testsuite.\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Stefan Zweifel](https://github.com/stefanzweifel)\n- [Aaron Francis](https://github.com/aarondfrancis)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanzweifel%2Fsidecar-browsershot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanzweifel%2Fsidecar-browsershot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanzweifel%2Fsidecar-browsershot/lists"}