DEV Community

Daniel Igel
Daniel Igel

Posted on

URL to screenshot in one GET — desktop, mobile, or custom viewport

Taking screenshots of web pages in automation usually means installing Chromium, managing a Playwright process pool, and keeping browser sessions from leaking memory in production. The setup works but is heavy — and it fails in odd ways when headless Chrome decides to hang.

One GET returns a base64-encoded screenshot, no Chromium setup required:

curl --request GET \
  --url 'https://website-screenshot-api8.p.rapidapi.com/api/v1/screenshot?url=https%3A%2F%2Fexample.com&viewport=mobile&format=webp' \
  --header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
  --header 'x-rapidapi-host: website-screenshot-api8.p.rapidapi.com'
Enter fullscreen mode Exit fullscreen mode

Response includes success, format, width, height, image (base64 string), and size. Flip &fullPage=true to capture content below the fold, &darkMode=true for dark-mode rendering, &blockAds=true to strip ad frames. Set &responseType=binary to stream raw bytes directly.

Use POST when you need a custom viewport or want to wait for a selector before the capture fires:

const res = await fetch('https://website-screenshot-api8.p.rapidapi.com/api/v1/screenshot', {
  method: 'POST',
  headers: {
    'x-rapidapi-key': process.env.RAPIDAPI_KEY,
    'x-rapidapi-host': 'website-screenshot-api8.p.rapidapi.com',
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://example.com',
    viewport: { width: 1280, height: 800 },
    format: 'png',
    fullPage: true,
    waitForSelector: '#main-content',
  }),
});
const { image, width, height } = await res.json();
Enter fullscreen mode Exit fullscreen mode

waitForSelector delays the capture until a CSS selector appears in the DOM — useful for React or Vue pages that render content after the initial load. Viewport accepts either a preset string (desktop, mobile, tablet) or a custom { width, height } object.

Free tier on RapidAPI: https://rapidapi.com/danieligel/api/website-screenshot-api8

What do you use automated screenshots for — visual regression testing, OG image generation, or something else?

Top comments (0)