Entrypoints (WXT Framework)
Relevant source files
The following files were used as context for generating this wiki page:The Read Frog browser extension is built using the WXT framework, which utilizes a directory-based entrypoint system to structure the different components of the extension. Each directory within src/entrypoints/ defines a distinct part of the extension, such as the background script, content scripts, popup, or options page. This modular approach aligns with the project's design principles of Single Responsibility and clear boundaries.
This system simplifies the development and management of a complex browser extension by isolating functionalities. The build process, managed by WXT and configured in wxt.config.ts, automatically bundles these entrypoints and generates the required manifest.json file for the extension.
Sources: CLAUDE.md, wxt.config.ts
Core Configuration
The primary configuration for the extension's entrypoints and manifest is located in wxt.config.ts. This file uses WXT's defineConfig function to set up the project.
Sources: wxt.config.ts
Manifest Generation
The manifest property in the configuration is a function that dynamically generates the manifest.json file based on the build mode (development or production) and target browser.
Key properties defined in the manifest include:
name:__MSG_extName__(for i18n)description:__MSG_extDescription__(for i18n)default_locale: 'en'permissions: A list of required browser APIs.host_permissions: URLs the extension needs to access.oauth2: Configuration for Google Drive API access.
Sources: wxt.config.ts:15-56
The following diagram illustrates how the configuration file feeds into the final extension manifest.
This diagram shows that wxt.config.ts is the source for generating the manifest.json file, including permissions and other settings.
Sources: wxt.config.ts:15-56
Permissions
The extension requests several permissions to enable its features.
| Permission | Purpose |
|---|---|
storage | To store user settings and configuration. |
tabs | To interact with browser tabs. |
alarms | For scheduling tasks like config backup. |
cookies | Required for certain API interactions. |
contextMenus | To add "Read with Read Frog" to context menus. |
identity | For OAuth2 authentication with Google. |
Sources: wxt.config.ts:24
Host Permissions
Host permissions vary between development and production modes to allow access to local servers during development.
- Development:
http://localhost:*/*,https://*.readfrog.app/*,https://www.googleapis.com/* - Production:
https://*.readfrog.app/*,https://www.googleapis.com/*
Sources: wxt.config.ts:28-44
Entrypoint Architecture
The extension's functionality is divided into several entrypoints located in the src/entrypoints/ directory. This structure is a core concept of the WXT framework.
| Entrypoint Directory | Description |
|---|---|
background/ | The background service worker. It handles the extension lifecycle, message routing, and coordinates between different parts of the extension. |
*.content/ | Content scripts injected into web pages. There are multiple content scripts for different features like the main reading UI, selection popups, and the side panel. |
popup/ | The UI for the extension's action button popup. |
options/ | The extension's settings page, which is configured to open in a new tab. |
Sources: CLAUDE.md
The following diagram shows the high-level architecture of the entrypoints.
This diagram illustrates the different entrypoints and how the background script coordinates them. Content scripts are injected into web pages, while the options and popup UIs run in their own contexts.
Sources: CLAUDE.md
Content Scripts (*.content/)
Content scripts are the primary way the extension interacts with web page content. Read Frog uses several specialized content scripts.
side.content
This entrypoint manages the main side panel UI for article reading and analysis. It is a React application that gets mounted into the host page.
- UI Structure: The main component is
SideContent, which includes aTopBar,Metadatadisplay, and the mainContentarea. - Functionality: It handles displaying the extracted article, analysis, and explanations. It also features a resizable panel. The width of the panel is stored in the user's configuration.
- Activation: The side panel can be opened via a message, such as one sent from the context menu. The
readArticlemessage triggers the side panel to open and begin the reading process.
Sources: src/entrypoints/side.content/components/side-content/index.tsx, src/entrypoints/side.content/components/side-content/metadata.tsx:28-44
The sequence diagram below shows the flow when a user initiates the "Read Article" feature.
This diagram details the "Read Article" process, from user click to displaying AI-generated explanations, involving content extraction, analysis, and batched explanation steps.
Sources: src/hooks/read/read.tsx, src/entrypoints/side.content/components/side-content/metadata.tsx
selection.content
This entrypoint is responsible for the toolbar that appears when a user selects text on a page.
- Activation: The toolbar appears on
mouseupevents if there is a text selection. - Logic: It checks if the selection is not empty and if the event target is within the selection, or if the active element is an
inputortextarea. This ensures the toolbar appears in appropriate contexts, including form fields. - Features: The toolbar contains buttons for AI actions, translation, and text-to-speech.
Sources: src/entrypoints/selection.content/selection-toolbar/tests/selection-toolbar.test.tsx
Options Page (options/)
The src/entrypoints/options/ directory defines the extension's settings page.
- Implementation: It's a standard HTML page (
index.html) that loads a React application (main.tsx). - Manifest Configuration: The
index.htmlfile contains a meta tag<meta name="manifest.open_in_tab" content="true" />which instructs WXT to configure the options page to always open in a new tab rather than being embedded in the browser's extension management UI.
Sources: src/entrypoints/options/index.html:6
Background Script (background/)
The background service worker, defined in src/entrypoints/background/, is the central nervous system of the extension.
Its responsibilities include:
- Handling the extension's lifecycle events.
- Routing messages between different entrypoints (e.g., from a content script to the popup).
- Managing asynchronous tasks like translation queues and database cleanup.
- Coordinating actions between content scripts and the popup UI.
Sources: CLAUDE.md
Build Scripts
The package.json file contains scripts for building and developing the extension using WXT's command-line interface.
| Script | Command | Description |
|---|---|---|
build | wxt build | Creates a production build of the extension. |
build:firefox | wxt build -b firefox | Creates a production build specifically for Firefox. |
dev | wxt | Starts the development server with hot-reloading for Chrome. |
zip | wxt zip | Packages the production build into a zip file for store submission. |
postinstall | wxt prepare | Generates TypeScript types and other files needed for development. |
Sources: package.json:7-19
Summary
The WXT entrypoint system provides a robust and organized architecture for the Read Frog extension. By dividing the application into logical, file-based modules (background, content, options, popup), it promotes separation of concerns and simplifies development. The configuration in wxt.config.ts and the scripts in package.json work together to automate the complex build process, allowing developers to focus on building features within this structured framework.