Playwright (Python) performance on WSL2 is much slower than on Win11 — any fix?

40 views Asked by At

I use Playwright (with Python 3.11) for scraping workflow (on a Windows 11 machine) and recently started moving towards all development work inside WSL2. I've noticed Playwright headless and head-ed browser performance (across all the browsers) seems to be abysmal on WSL2 compared to on Windows.

Typical workflow:

from playwright.sync_api import sync_playwright

... # other code

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    page.goto('https://benjamintseng.com/') # just picking my Wordpress blog as an example
    ... # other code

Leads to a timeout on the page.goto command at 30 seconds (as per default). When I load this with headless=False, I can see that DOM elements have loaded but the browser just doesn't ever finish loading (the "loading loop") just keeps going. The network tab in the inspector appears empty. I didn't see anything obvious in the console tab.

When I run identical code on Python on Windows 11, there is no delay or timeout.

Is this just "overhead" from "Linux emulation" that comes with WSL that I need to live with (but shouldn't be there if I run this on a full Linux server) or is there a fix / change I can make? I'd really like to keep everything in WSL for local work (allows me to combine the Windows apps I'm familiar with, not to mention some I need for work) with Linux command-line/development tools.

0

There are 0 answers