You can load local files in Playwright by passing in the absolute path of the file to the goto
method of the Page
object. Just make sure that you prepend file://
to the path as well.
Here is some sample code for opening a local file:
from playwright import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
# open a local file
page.goto("file://path/to/file.html")
Note: The path would look like this for windows: file://C:/path/to/file.html