Examples
Screenshot of a particular size with Ruby and Playwright
Install Playwright and the Playwright client for Ruby
npm install playwright
gem install playwright-ruby-client Take a screenshot of the resized viewport and save to file
require 'playwright'
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
playwright.chromium.launch do |browser|
page = browser.new_page
page.viewport_size = { width: 480, height: 240 }
page.goto('https://www.htmltoimage.com/demo')
page.screenshot(path: './size.png')
end
end Find out how to take a full-page screenshot with Ruby and Playwright.
That was 10 lines of code — plus a browser to run in production
Keeping headless browsers fed, patched and scaled is a job in itself. We built Urlbox so the same screenshot is one API call:
curl "https://api.urlbox.com/v1/YOUR_API_KEY/png?url=https://example.com" Try the Urlbox screenshot API — free trial, no browser babysitting.