Test OpenGraph image generation on Netlify locally

02 Jun 2021 in Tech

I previously wrote a post on how to generate OpenGraph images with Netlify on-demand builders.

Kevin tried it out but was frustrated that it was tough to test locally.

Here's how to develop on your local machine:

  1. Install chromium with brew
bash
brew install --cask chromium
  1. Install netlify-cli
bash
npm install netlify-cli -g
  1. Update executablePath in the call to puppeteer.launch
javascript
executablePath: process.env.CHROMIUM_PATH || (await chromium.executablePath),
  1. Run CHROMIUM_PATH=/usr/local/bin/chromium netlify dev in your terminal

  2. Visit http://localhost:8888/.netlify/functions/og to see a generated image

  3. Enjoy your generated image