Skip to content

Usage

Patchright's API is identical to Playwright. Swap the import and everything else stays the same.


Python (synchronous)

python
from patchright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("http://playwright.dev")
    page.screenshot(path="example.png")
    browser.close()

Python (asynchronous)

python
import asyncio
from patchright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        await page.goto("http://playwright.dev")
        await page.screenshot(path="example.png")
        await browser.close()

asyncio.run(main())

Node.js

javascript
const { chromium } = require('patchright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('http://example.com');
  await browser.close();
})();

Migration from Playwright

Replace the import line only:

Before (Playwright)After (Patchright)
from playwright.sync_api import sync_playwrightfrom patchright.sync_api import sync_playwright
from playwright.async_api import async_playwrightfrom patchright.async_api import async_playwright
const { chromium } = require('playwright')const { chromium } = require('patchright')

No other code changes are needed for a drop-in migration.


python
browser = p.chromium.launch(channel="chrome")

Using channel="chrome" launches the system-installed Google Chrome (must be installed separately) rather than the downloaded Chromium build. This is the highest-stealth configuration because Chrome's binary fingerprint matches real user traffic more closely than Chromium.

Do not pass custom user_agent or extra HTTP headers when targeting protected sites; these are common detection signals.