How to Run Browser Automation in WSL2 Without Losing Your Weekend
A developer spent a weekend troubleshooting browser automation on Windows Subsystem for Linux 2 (WSL2) after encountering a common but underacknowledged networking problem. By default, WSL2 uses NAT networking, meaning Linux processes cannot treat Windows services as local, which causes Playwright's CDP connections to port 9222 to silently fail. The fastest workaround is retrieving the Windows host IP from within WSL2 and using it explicitly in the Playwright connectOverCDP() call, or switching to mirrored networking where localhost works directly. For reusing an already authenticated Windows Chrome session, launching Chrome with remote debugging enabled and attaching via CDP is the shortest path, though Playwright itself warns that CDP offers lower fidelity than a native connection. The author cautions that while this setup works for quick prototypes and local experiments, attaching an autonomous agent to a personal Chrome profile loaded with live credentials is both brittle and a security risk.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in