How andresz74/youtube-transcript-extension works
1. What this repository is
- This is a Chrome extension whose UI lives in the browser popup.
- It is a thin client: the extension itself does not scrape YouTube directly. Instead, it depends on an external transcript API service to fetch transcript data.
2. Primary runtime boundary
- The extension runs inside Chrome’s extension runtime, centered on manifest.json, src/popup.html, and src/popup.js.
- There is no separate backend in this repo; the only server-side dependency is the external transcript generator service described in the README.
3. Popup UI subsystem
- src/popup.html defines the popup shell.
- src/ui.js contains rendering helpers for the popup states: loading, transcript display, copy actions, and error/empty states.
- styles/styles.css provides the popup’s presentation.
- This is the only user-facing interface in the repo.
4. Popup orchestration flow
- src/popup.js is the main controller for the popup lifecycle.
- On open, it inspects the current tab, determines whether the page is a YouTube video page, and either:
- shows a “no video found” state, or
- triggers transcript retrieval and updates the UI as results arrive.
- It is the central coordinator between URL detection, API calls, and rendering.
5. YouTube page detection
- src/url-detection.js isolates the logic for deciding whether the active tab contains a YouTube video.
- The README indicates support for standard watch pages and Shorts, and the code structure suggests this module encapsulates those URL rules so the popup controller stays small.
6. Transcript data access boundary
- src/transcript-api.js is the network client that calls the external REST API.
- It handles the important operational concerns for that boundary: request timing, error handling, and converting the remote response into something the UI can use.
- This is the key integration point between the extension and the external transcript service.
7. Response contract / normalization
- src/transcript-contract.js defines the expected shape of transcript data returned by the backend.
- This module likely validates or normalizes the API response so the UI receives a stable contract, even if the backend response format changes slightly.
- The presence of separate contract tests indicates this is treated as an important architectural boundary.
8. Configuration and environment override
- src/config.js centralizes configuration such as the default API base URL and request timeout.
- The README documents a runtime override via localStorage.setItem('ytTranscriptApiBaseUrl', ...), which means the popup can be pointed at a local backend without changing source code.
- That makes the external API endpoint a configurable dependency rather than a hard-coded one.
9. End-to-end data flow
- User clicks the extension icon.
- Popup opens and popup.js reads the active tab URL.
- url-detection.js verifies the tab is a YouTube video page.
- transcript-api.js calls the configured transcript service.
- transcript-contract.js shapes the returned payload.
- ui.js renders the title and transcript.
- The user can then copy the transcript to the clipboard from the popup.
10. Error and empty-state handling
- The architecture explicitly includes failure paths: non-YouTube pages, missing video IDs, API failures, timeouts, and potentially empty transcript responses.
- These are surfaced in the popup rather than failing silently, which is important because the extension’s main dependency is an external service.
11. Testing boundary
- The tests/ directory focuses on the API client and contract logic:
- tests/transcript-api.spec.js
- tests/transcript-contract.spec.js
- This indicates the most critical logic is considered to be the service integration and response-shaping layers, not the static UI markup.
12. Repository/tooling shape
- The project is a small, framework-free JavaScript codebase with linting and formatting configured via ESLint and Prettier.
- A GitHub Actions workflow (.github/workflows/release-on-tag.yml) handles release automation on tags, which is the main delivery pipeline in the repo.
- The architecture is therefore: browser extension UI + configurable REST dependency + lightweight validation/rendering layers.
Main entry points: popup.js Popup controller · transcript-api.js API client · ui.js UI helpers · transcript-contract.js Contract
Components 14
Chrome extension
Popup-driven extension runtime in Chrome.
- Manifest · Declares the Chrome extension entrypoints and permissions.
manifest.json - Popup shell · Defines the popup window structure.
src/popup.html - Popup controller · Coordinates tab inspection, transcript lookup, and UI updates.
src/popup.js - UI helpers · Renders loading, transcript, copy, empty, and error states.
src/ui.js - URL rules · Detects whether the active tab is a YouTube video page or Shorts page.
src/url-detection.js - Config · Holds API base URL and timeout defaults plus local override support.
src/config.js - API client · Calls the external transcript service and handles request timing and failures.
src/transcript-api.js - Contract · Normalizes and validates transcript payloads from the service.
src/transcript-contract.js - Styles · Provides the popup presentation and layout.
styles/styles.css
Transcript service
External REST dependency used to fetch transcript data.
- Transcript API · Remote dependency that generates or serves transcript data.
Tooling
Release, lint, and test support around the extension.
- API tests · Covers transcript client behavior and failure handling.
tests/transcript-api.spec.js - Contract tests · Covers transcript response shaping and validation.
tests/transcript-contract.spec.js - Release flow · Automates publishing on tagged releases.
.github/workflows/release-on-tag.yml - Package config · Defines scripts and project metadata for linting, formatting, and tests.
package.json
Connections 14
- Manifest → Popup shell: popup entry · Manifest points Chrome to the popup UI.
- Manifest → Popup controller: load controller · Popup runtime bootstraps the controller logic.
- Popup controller → URL rules: detect page · Checks whether the active tab is a supported YouTube video page.
- Popup controller → Config: read config · Uses configured API endpoint and timeout settings.
- Popup controller → API client: fetch transcript · Requests transcript data once a valid video page is found.
- API client → Transcript API: REST call · Sends network requests to the external transcript service.
- API client → Contract: shape response · Normalizes or validates remote payloads before use.
- Popup controller → UI helpers: render states · Updates loading, transcript, empty, and error views.
- Popup shell → UI helpers: mount UI · Provides the DOM scaffold for rendering helpers.
- UI helpers → Styles: style UI · Presentation layer for the popup interface.
- Popup controller → Contract: consume contract · Relies on the stable transcript shape for rendering and copy actions.
- API tests → API client: verify client · Exercises request behavior and error handling.
- Contract tests → Contract: verify shape · Exercises transcript normalization and validation.
- Release flow → Package config: release steps · Uses project scripts and metadata during automation.