How saeed3e/puppeteer works
Main components
• Core API (puppeteer-core): This package contains the base API and abstraction for interacting with browsers. It encapsulates the communication logic with the browsers, including modules for CDP (Chrome DevTools Protocol), WebDriver BiDi, and related low‑level functionality.
• Puppeteer “wrapper” (packages/puppeteer): This package builds upon puppeteer‑core with additional tooling, configuration, and ease‑of‑use for end users (for example, automatically downloading a compatible Chrome binary).
• Browser Management (packages/browsers): This module is responsible for detecting, installing, and launching browsers, along with handling metadata and platform‑specific logic.
• Schematics and Extensions (packages/ng‑schematics): Targeting integration with frameworks like Angular, these schematics provide configuration and setup for projects that wish to use Puppeteer.
• Test Infrastructure: There are multiple test folders (e.g., test, test‑d, packages/testserver) and tools (in tools/*) that help with integration, smoke tests, and automated coverage. These represent the internal quality assurance and continuous integration layers.
• Documentation and Website: The docs/* and website directories provide API documentation, guides, and information for users and contributors.
Relationships and interactions
• User Code: Developers write scripts that import Puppeteer. Their application code uses the high‑level API provided by “puppeteer” (which internally relies on “puppeteer‑core”) to control the browser.
• API Layer: The public API receives calls from client code and forwards these calls to sub‑modules that handle the actual communication (via CDP and WebDriver BiDi).
• Browser Management & Launching: When the API calls a ‘launch’ method, the puppeteer wrapper (or the browsers package) manages the process of locating the executable (or downloading one if needed), creating a browser process, and setting up communication channels.
• Protocol Communication Modules: Within puppeteer‑core, there are separate modules for handling CDP interactions, browser contexts, frames, elements, events, and more. They often use event emitters and asynchronous paradigms to manage browser feedback.
• Testing and Build Tools: Test directories and the “tools” folder provide scripts, CI configurations (e.g., GitHub Actions workflows), and utilities for release management and documentation generation.
Architectural patterns and design principles
• Modularity: The project is highly modular with its multiple packages that separate concerns (core API, browser management, schematics GUI integration, etc.).
• Layered Abstraction: There is a layered approach—from the low‑level protocol wrappers (e.g., for CDP, WebDriver BiDi) in puppeteer‑core up to the high‑level API for end users provided by puppeteer.
• Separation of Concerns: Dedicated folders exist for configuration, documentation, tests, and tooling, making it easy to isolate responsibilities.
• Extensible: The existence of custom query handlers, builders, and schematics shows an intent for extensibility and integration with external systems.
• Essential components and their responsibilities:
– Make the API and protocol layers central, as these are the heart of Puppeteer.
– Represent test and CI as peripheral but important, demonstrating the mature development and verification process.
• Important files/folders from the file tree are captured in abstract form (e.g., packages, docs, tests, tools, website) so that one can see the separation of concerns.