Closer to the Metal: Leaving Playwright for CDP
4 days ago
- #playwright
- #browser-automation
- #cdp
- The article discusses the transition from using Playwright to directly using the Chrome DevTools Protocol (CDP) for browser automation.
- Playwright and Puppeteer are praised for their ease in creating QA tests and automation scripts but criticized for obscuring important browser details.
- Switching to raw CDP has improved speed in element extraction, screenshots, and added new capabilities like async reactions and cross-origin iframe support.
- The article highlights the 'Curse of Abstraction' where adapter libraries like Playwright can become more of a hindrance than help as complexity grows.
- A historical overview of browser automation tools is provided, from PhantomJS to modern tools like Playwright and Puppeteer.
- The author explains the underlying APIs exposed by browsers, including Chrome Extension APIs, CDP APIs, and OS-Level Accessibility APIs.
- Playwright's client-server model and its limitations, such as state drift and edge cases, are discussed.
- The challenges of browser automation, including various ways a tab can crash in Chrome, are outlined.
- The article introduces new tools developed by the author's team, such as 'cdp-use' for Python bindings to CDP and an event-driven architecture for better responsiveness.
- The new architecture includes features like 'watchdog' services for monitoring downloads and crashes, and enhanced element handles for cross-origin iframes.
- The article concludes with a reflection on the evolution of browser automation and the promise of AI in simplifying these complexities.