Dev.to
7/14/2026
I wasted a weekend on WSL2 browser automation so you don’t have to
Short summary
A practical guide to browser automation on WSL2, focusing on connecting Playwright to Windows Chrome via CDP on port 9222. The key challenge is WSL2's NAT networking, which requires using the Windows host IP instead of localhost. For production use, the author recommends running both agent and browser in the same Linux environment via WSLg rather than relying on cross-boundary CDP connections.
- •WSL2 NAT networking means localhost:9222 won't reach Windows Chrome — use the Windows host IP instead
- •CDP connection to an existing Chrome profile is convenient for prototypes but brittle for production automation
- •For reliable setups, run agent and browser in the same Linux environment using WSLg
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



