$ show YusukeIwaki/playwright-ruby-client
This repository is a Ruby gem that provides a client for Microsoft Playwright, enabling programmatic browser automation for testing, scraping, and UI interaction. It wraps the Playwright protocol by spawning a Node.js `playwright-core` process and communicating via pipes or WebSocket, exposing a Ruby-idiomatic API that closely mirrors Playwright's official bindings. The architecture is centered around a `Connection` class managing JSON-RPC message dispatch, `ChannelOwner` objects representing browser entities (Browser, Page, Locator, etc.), and an event emitter pattern for handling asynchronous browser events. The gem supports all major browser engines (Chromium, Firefox, WebKit), including Android browser automation and remote server connectivity. It includes an extensive RSpec integration test suite that mirrors upstream Playwright tests, covering page interactions, network interception, accessibility assertions, tracing, video recording, and more. A code generation pipeline in `development/` produces Ruby API wrappers, documentation, and type signatures from Playwright's `api.json`, ensuring alignment with each compatible Playwright version.
The LLM identified 4 files worth highlighting for reuse:
A standalone Ruby implementation of a Node.js-style EventEmitter, providing `on`, `once`, `off`, `emit`, and `listeners` methods. It is mixed into `ChannelOwner` and used throughout the gem for event-driven communication. Could be extracted as a lightweight pub-sub utility for any Ruby project.
A reusable class that manages waiting for one of several concurrent events (promises, timeouts, signals) with configurable timeout and logging. It supports rejection handling and is used for implementing Playwright's auto-waiting mechanisms. The pattern is applicable to any asynchronous Ruby code requiring raced futures with timeouts.
A lean, case-insensitive HTTP header storage class with `get`, `get_all`, `set`, `delete`, and `headers_array` methods. It handles multi-value headers correctly and is used internally for processing network request/response headers. Could be reused in any HTTP client or proxy implementation.
Handles serialization of Ruby objects (including nested hashes, arrays, symbols, BigDecimals, Date, Regexp, etc.) into a JSON-compatible format suitable for Playwright's JavaScript evaluation protocol. The reverse parser is in `javascript/value_parser.rb`. This pair solves the recurring problem of safe cross-language value marshalling and can be adapted for any Ruby-to-JS bridge.