🚀 We are hiring! See open positions

How to load local files in Playwright?

by Bernardas Alisauskas May 29, 2023 1 min read

To test our Puppeteer web scrapers we might want o use local files instead of public websites. Just like real web browsers Puppeteer can load local files using the file:// URL protocol. Here's an example in Python:

python
from playwright import sync_playwright

with sync_playwright() as pw:
    browser = pw.chromium.launch(headless=False)
    context = browser.new_context(viewport={"width": 1920, "height": 1080})
    page = context.new_page()

    # open a local file (note: absolute path needs to be used)
    page.goto("file://home/user/projects/test.html");  # linux
    page.goto("file://C:/Users/projects/test.html");  # windows
    print(page.content())
Scale Your Web Scraping
Anti-bot bypass, browser rendering, and rotating proxies — all in one API. Start with 1,000 free credits.
No credit card required 1,000 free API credits Anti-bot bypass included
Not ready? Get our newsletter instead.