aboutsummaryrefslogtreecommitdiffstats
path: root/src/offscreen/ocr/index.js
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 11:35:08 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 11:35:08 +0530
commit600c337b1cdc884aebf59083eb57b178b43441ce (patch)
treed1f3cb7eb1020bcdcd66d9dbf0279f79d5856332 /src/offscreen/ocr/index.js
parent98e7019c61ea0ffe344ef7ce809d38d62254a9fc (diff)
downloadbanglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.tar.gz
banglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.zip
docs: added some documentation comments to all functions
Diffstat (limited to 'src/offscreen/ocr/index.js')
-rw-r--r--src/offscreen/ocr/index.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/offscreen/ocr/index.js b/src/offscreen/ocr/index.js
index 432811e..aab9da8 100644
--- a/src/offscreen/ocr/index.js
+++ b/src/offscreen/ocr/index.js
@@ -4,6 +4,15 @@ let ocrWorker = null;
const WORKER_PATH = chrome.runtime.getURL("offscreen/ocr/static/worker.min.js");
const CORE_PATH = chrome.runtime.getURL("offscreen/ocr/static");
+/**
+ * Creates (or reuses) a Tesseract.js worker and recognises text from
+ * the given image data URL. The worker is configured to only recognise
+ * uppercase alphanumerics (excluding `0`, `O`, `1`, `I`) suitable for
+ * CAPTCHA text.
+ *
+ * @param {string} dataURL - A `data:image/png;base64,…` string.
+ * @returns {{ text: string, confidence: number }}
+ */
async function performOcrInOffscreen(dataURL) {
if (!ocrWorker) {
ocrWorker = await Tesseract.createWorker("eng", 1, {
@@ -23,6 +32,11 @@ async function performOcrInOffscreen(dataURL) {
}
// Listen for messages from the Service Worker
+/**
+ * Handles two message types from the background service worker:
+ * - `"OFFSCREEN_OCR_REQUEST"`: runs OCR on the supplied data URL.
+ * - `"OFFSCREEN_TERMINATE_OCR_WORKER"`: terminates the worker to free memory.
+ */
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "OFFSCREEN_OCR_REQUEST" && message.dataURL) {
performOcrInOffscreen(message.dataURL)