Retina screenshots with Ruby and Playwright

Install Playwright and Playwright client for Ruby

npm install playwright@1.27.1
gem install playwright-ruby-client

Take a screenshot of the retina image save to file

require 'playwright'

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch(headless: false) do |browser|
    context = browser.new_context(deviceScaleFactor: 2)

    page = context.new_page
    page.viewport_size = { width: 480, height: 240 }
    page.goto('https://www.bbc.co.uk/news/business-63709754')
    page.screenshot(path: './retina.png')
  end
end

Find out how to take a full-page screenshot with Ruby and Playwright.

We created Urlbox to make converting HTML to images easy

Learn more about our website screenshot API.