You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

ocr-click-plugin

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ocr-click-plugin - npm Package Compare versions

Comparing version

to
2.1.4

install.js

29

dist/index.js

@@ -18,3 +18,11 @@ "use strict";

const tesseract_js_1 = __importDefault(require("tesseract.js"));
const sharp_1 = __importDefault(require("sharp"));
// Try to import Sharp, but handle gracefully if not available
let sharp = null;
try {
sharp = require('sharp');
console.log('✅ Sharp image processing library loaded successfully');
}
catch (error) {
console.warn('⚠️ Sharp not available. Image enhancement will be disabled. Install with: SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --include=optional sharp');
}
const SOURCE_URL_REGEX = new RegExp('/session/[^/]+/plugin/textclick');

@@ -47,3 +55,3 @@ const CHECK_TEXT_URL_REGEX = new RegExp('/session/[^/]+/plugin/checktext');

console.log('Enhancing screenshot for better OCR results...');
// Step 2: Enhance the screenshot
// Step 2: Enhance the screenshot (if Sharp is available)
const enhancedBase64Image = yield this.enhanceScreenshot(screenshotBase64);

@@ -99,2 +107,3 @@ // Step 3: Process the enhanced screenshot with OCR

confidence: targetWord.confidence,
imageEnhanced: sharp !== null,
};

@@ -116,3 +125,3 @@ }

console.log('Enhancing screenshot for OCR text detection...');
// Step 2: Enhance the screenshot
// Step 2: Enhance the screenshot (if Sharp is available)
const enhancedBase64Image = yield this.enhanceScreenshot(screenshotBase64);

@@ -153,2 +162,3 @@ // Step 3: Process the enhanced screenshot with OCR

matches: matches,
imageEnhanced: sharp !== null,
message: isPresent

@@ -168,2 +178,3 @@ ? `Text "${text}" found with ${matchingWords.length} match(es)`

matches: [],
imageEnhanced: sharp !== null,
message: `Error checking text presence: ${errorMessage}`,

@@ -175,8 +186,12 @@ error: errorMessage

}
// Helper method to enhance the screenshot
// Helper method to enhance the screenshot (with fallback if Sharp not available)
enhanceScreenshot(base64Image) {
return __awaiter(this, void 0, void 0, function* () {
if (!sharp) {
console.log('Sharp not available - using original image without enhancement');
return base64Image;
}
try {
const imageBuffer = Buffer.from(base64Image, 'base64');
const enhancedBuffer = yield (0, sharp_1.default)(imageBuffer)
const enhancedBuffer = yield sharp(imageBuffer)
.grayscale() // Convert to grayscale

@@ -199,4 +214,4 @@ .normalize() // Normalize contrast

catch (err) {
console.error('Error enhancing screenshot:', err);
throw err;
console.error('Error enhancing screenshot with Sharp, using original:', err);
return base64Image; // Fallback to original image
}

@@ -203,0 +218,0 @@ });

{
"name": "ocr-click-plugin",
"version": "2.1.3",
"version": "2.1.4",
"description": "An Appium plugin that uses OCR (Optical Character Recognition) to find and click text elements on mobile device screens",

@@ -15,3 +15,4 @@ "main": "dist/index.js",

"prepublish": "npx tsc",
"postinstall": "echo 'If Sharp installation fails, try: SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --include=optional sharp'",
"postinstall": "node install.js",
"install-sharp": "SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --include=optional sharp",
"lint": "eslint '**/*.js' --fix",

@@ -50,3 +51,4 @@ "prettier": "prettier '**/*.js' --write --single-quote",

"README.md",
"package.json"
"package.json",
"install.js"
],

@@ -57,5 +59,7 @@ "dependencies": {

"jimp": "^1.6.0",
"sharp": "^0.34.2",
"tesseract.js": "^5.1.1"
},
"optionalDependencies": {
"sharp": "^0.34.2"
},
"peerDependencies": {

@@ -62,0 +66,0 @@ "appium": "^2.12.1"