How mohit-s96/youtube_ocr_extension works
1. What this repo is
- A Chrome extension for OCR on YouTube videos.
- It is fully client-side: no backend, no API server, no cloud OCR service.
- The main purpose is to let a user select a region of a video frame and extract readable text from it.
2. Extension surface
- The user interacts with a popup UI (src/popup.html, src/popup.js) and likely a keyboard shortcut.
- The popup is the entry point for starting the crop/OCR flow, as described in the README.
- src/styles.css and src/img/ support the UI presentation and branding.
3. Background orchestration
- src/background.js acts as the extension’s central coordinator.
- In a Chrome extension architecture, this is typically where shortcut handling, message routing, and privileged extension actions are managed.
- It likely bridges the popup/content script/offscreen components rather than doing OCR directly in the UI.
4. Content script boundary
- src/contentScript.js is injected into YouTube pages.
- Its role is to operate in the context of the web page: detect the video page, overlay/select the crop region, and send page-specific information back to the extension runtime.
- This file forms the boundary between the extension and the YouTube DOM/video content.
5. Offscreen processing layer
- src/offscreen.html and src/offscreen.js indicate a separate hidden processing context.
- In Manifest V3, offscreen documents are commonly used for tasks that need DOM-like capabilities without a visible tab.
- Here, that layer likely handles screenshot/canvas processing and OCR execution while staying invisible to the user.
6. OCR engine
- The README explicitly says OCR is done with TesseractJS.
- That means text recognition happens in-browser using WebAssembly/service-worker-style processing provided by the library.
- This is the core compute-heavy subsystem and is isolated from the UI to keep the extension responsive.
7. End-to-end data flow
- User starts the action from popup or shortcut.
- Background script coordinates the request.
- Content script works on the YouTube page to identify the selected video area.
- Offscreen context receives image data/screenshot region, runs OCR via TesseractJS, and returns extracted text.
- The result is then surfaced back to the user through the extension UI.
8. Browser/runtime model
- This is a Chrome extension built around Manifest V3-style pieces.
- The presence of an offscreen document suggests it relies on extension APIs rather than a traditional page-only implementation.
- The README’s note about Manifest V2 on a separate branch confirms the current tree is the newer MV3 architecture.
9. Build/tooling layer
- webpack.common.js, webpack.dev.js, and webpack.prod.js show that the extension is bundled with Webpack.
- package.json defines the app’s dependencies and build scripts.
- This bundling step is important because the extension is split across several runtime contexts that need to be packaged together.
10. Static assets and packaging
- assets/ and src/img/ hold branding and UI assets such as the logo/favicon.
- src/manifest.json is the extension contract that wires together popup, background, content script, offscreen page, permissions, and shortcuts.
- The final build output is what gets loaded as an unpacked extension in Chrome.
11. Architectural boundary summary
- The repo cleanly separates UI, page injection, background coordination, and OCR processing.
- The most important architectural split is between the visible extension surfaces and the hidden processing context used to perform screenshot-based OCR without a backend.
Main entry points: background.js Background · manifest.json Manifest · contentScript.js Content script · popup.html Popup UI
Components 16
Extension runtime
Visible Chrome extension surfaces and coordination logic.
- Popup UI · User-facing popup that starts the OCR flow.
src/popup.html - Popup logic · Handles popup interactions and triggers extension actions.
src/popup.js - Background · Central extension coordinator for messages, shortcuts, and orchestration.
src/background.js - Content script · Injected into YouTube pages to work with the video DOM and selection boundary.
src/contentScript.js - Styles · Shared styling for the popup and extension UI.
src/styles.css
OCR processing
Hidden processing context and OCR engine.
- Offscreen page · Invisible document used for background processing tasks.
src/offscreen.html - Offscreen logic · Runs screenshot/canvas handling and coordinates OCR execution.
src/offscreen.js - TesseractJS · In-browser OCR engine used to extract text from image data.
Build and packaging
Bundling, manifest, and static assets.
- Manifest · Wires together permissions, entry points, and extension runtime pieces.
src/manifest.json - Webpack common · Shared bundling configuration for all extension builds.
webpack.common.js - Webpack dev · Development build configuration.
webpack.dev.js - Webpack prod · Production build configuration.
webpack.prod.js - Package config · Defines dependencies and build scripts for the extension.
package.json - UI assets · Icons and images used by the extension UI.
src/img - Static assets · Packaged static assets such as logo and favicon resources.
assets - README · Describes the extension behavior, usage, and architecture.
README.md
Connections 22
- Popup UI → Popup logic: uses · Popup UI is driven by its JavaScript controller.
- Popup logic → Background: starts flow · Popup actions request the OCR workflow through the background coordinator.
- Background → Content script: injects/routs · Background coordinates page-side work through the content script.
- Content script → Background: messages · Content script sends page and selection state back to the extension runtime.
- Content script → Offscreen page: captures region · Selected video-frame imagery is forwarded for hidden processing.
- Offscreen page → Offscreen logic: hosts · The offscreen document loads the processing logic.
- Offscreen logic → TesseractJS: runs OCR · Offscreen logic delegates text recognition to TesseractJS.
- Offscreen logic → Background: returns text · Extracted OCR text is sent back for orchestration and display.
- Manifest → Popup UI: declares · Manifest defines the popup entry point.
- Manifest → Background: declares · Manifest registers the background coordinator.
- Manifest → Content script: injects · Manifest configures content script injection on YouTube pages.
- Manifest → Offscreen page: enables · Manifest includes the offscreen document used for processing.
- Manifest → Styles: bundles · Manifest participates in packaging the extension UI assets.
- Webpack common → Webpack dev: shared by · Development build extends shared bundling rules.
- Webpack common → Webpack prod: shared by · Production build extends shared bundling rules.
- Package config → Webpack common: scripts · Package scripts drive the Webpack build pipeline.
- Package config → Webpack dev: scripts · Development script uses the dev build configuration.
- Package config → Webpack prod: scripts · Production script uses the production build configuration.
- Static assets → Popup UI: brands · Static assets support the visible extension surface.
- UI assets → Popup UI: decorates · Images and icons support the popup UI presentation.
- README → Background: describes · Documentation explains the extension architecture and flow.
- README → TesseractJS: mentions · README identifies TesseractJS as the OCR engine.