aboutsummaryrefslogtreecommitdiffstats
path: root/src/background/run-ocr.ts
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2025-06-13 18:55:27 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2025-06-13 18:55:27 +0530
commit64e38ab240a1ca3427592eb80f2cef57fddbdafe (patch)
treee9fcb0e797a1106e48b6ee716426970cf48b8251 /src/background/run-ocr.ts
parent00e5ea80b1b0ba37ac4b5dc7b10ae6eac26aa1af (diff)
downloadbanglar-bhumi-utils-64e38ab240a1ca3427592eb80f2cef57fddbdafe.tar.gz
banglar-bhumi-utils-64e38ab240a1ca3427592eb80f2cef57fddbdafe.zip
Sending OCR request along with captcha image data to the background script.
Diffstat (limited to 'src/background/run-ocr.ts')
-rw-r--r--src/background/run-ocr.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/background/run-ocr.ts b/src/background/run-ocr.ts
index d61e71a..f6d1339 100644
--- a/src/background/run-ocr.ts
+++ b/src/background/run-ocr.ts
@@ -1,7 +1,15 @@
-chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
- if (message.type === "ping") {
- console.log("Received ping from content script");
- console.log(message.data);
- sendResponse({ text: "pong" });
+import Tesseract from "tesseract.js";
+
+chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
+ if (message.type === "OCR") {
+ (async () => {
+ const { data: { text, confidence } } = await Tesseract.recognize(message.dataURL, "eng+osd", {
+ logger: m => console.log(m),
+ });
+ sendResponse({ text, confidence });
+ })();
+ return true;
}
+
+ return false;
});