Retina screenshots with Python and Playwright

Install Playwright and Playwright client for Python

pip install pytest-playwright
playwright install

Take a screenshot of the retina image save to file

import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        context = await browser.new_context(device_scale_factor=2)
        page = await context.new_page()
        await page.set_viewport_size({'width': 480, 'height': 240})
        await page.goto('')
        await page.screenshot(path='retina.png')
        await browser.close()

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

We created Urlbox to make converting HTML to images easy

Learn more about our website screenshot API.