ocr-click-plugin
Advanced tools
Comparing version
@@ -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" |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
23602
12.99%4
33.33%278
26.94%7
Infinity%1
Infinity%- Removed