{"_id":"2fa-adb-tools","name":"2fa-adb-tools","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"2fa-adb-tools","version":"1.0.0","description":"Capture 2FA verification codes from Android notifications for automated testing with Playwright","main":"index.js","keywords":["2fa","playwright","adb","testing","automation","otp","android","e2e","test-automation","verification-code"],"author":{"name":"pifpafi4","url":"https://github.com/pifpafi4"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/pifpafi4/2fa-adb-tools.git"},"bugs":{"url":"https://github.com/pifpafi4/2fa-adb-tools/issues"},"homepage":"https://github.com/pifpafi4/2fa-adb-tools#readme","engines":{"node":">=14.0.0"},"_id":"2fa-adb-tools@1.0.0","gitHead":"6399f0e916f99e9dd021bc860e327184456434cf","_nodeVersion":"22.17.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-Fhq8cjlNRqJhfaj1AM8+ZBIGLoBSqHo6su37y9Zzs2DydR+CuDmD4kHwSu3Z0pXrDKxG6bVwnz3GTt7TnvsnQQ==","shasum":"24825677b9de3f50f9a3e0c55a7de88448b8c1eb","tarball":"https://registry.npmjs.org/2fa-adb-tools/-/2fa-adb-tools-1.0.0.tgz","fileCount":9,"unpackedSize":32335,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDMfQ/J5CXtzHeK+V0gAEshiEk3BHTu8My9lykSqsLxDwIgOhbSOjj7Dv4sdV/UimqW4d0sVj99rv7wdz5miFLYq6k="}]},"_npmUser":{"name":"pifpafi4","email":"zimin.maksym@yandex.ru"},"directories":{},"maintainers":[{"name":"pifpafi4","email":"zimin.maksym@yandex.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/2fa-adb-tools_1.0.0_1773408381334_0.7594565181476076"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-13T13:26:21.333Z","1.0.0":"2026-03-13T13:26:21.465Z","modified":"2026-03-13T13:26:21.692Z"},"maintainers":[{"name":"pifpafi4","email":"zimin.maksym@yandex.ru"}],"description":"Capture 2FA verification codes from Android notifications for automated testing with Playwright","homepage":"https://github.com/pifpafi4/2fa-adb-tools#readme","keywords":["2fa","playwright","adb","testing","automation","otp","android","e2e","test-automation","verification-code"],"repository":{"type":"git","url":"git+https://github.com/pifpafi4/2fa-adb-tools.git"},"author":{"name":"pifpafi4","url":"https://github.com/pifpafi4"},"bugs":{"url":"https://github.com/pifpafi4/2fa-adb-tools/issues"},"license":"MIT","readme":"# 2FA ADB Tools\r\n\r\nA Node.js library for automatically capturing 2FA verification codes from Android notifications using ADB and OCR, with seamless Playwright integration for end-to-end testing.\r\n\r\n[![npm version](https://img.shields.io/npm/v/2fa-adb-tools.svg)](https://www.npmjs.com/package/2fa-adb-tools)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\n## 📋 Table of Contents\r\n\r\n- [Features](#-features)\r\n- [Installation](#-installation)\r\n- [Prerequisites](#-prerequisites)\r\n- [Quick Start](#-quick-start)\r\n- [API Reference](#-api-reference)\r\n- [Configuration](#-configuration)\r\n- [Troubleshooting](#-troubleshooting)\r\n\r\n## ✨ Features\r\n\r\n- **Automatic 2FA Capture**: Monitors Android notifications and extracts verification codes using OCR\r\n- **Playwright Integration**: Built-in helpers for seamless end-to-end testing\r\n- **Customizable Gestures**: Configure swipe coordinates and intervals for notification dismissal\r\n- **Smart Management**: Automatic screenshot cropping, cleanup, and storage with deduplication\r\n\r\n## 📦 Installation\r\n\r\n```bash\r\nnpm install 2fa-adb-tools\r\n```\r\n\r\n### Peer Dependency (for Playwright)\r\n\r\n```bash\r\nnpm install --save-dev @playwright/test\r\n```\r\n\r\n## 🔧 Prerequisites\r\n\r\n### Android Setup\r\n1. Enable **USB Debugging** on your Android device\r\n2. Install **ADB** (Android Debug Bridge)\r\n\r\n#### Install ADB\r\n- **Windows**: Download [Android Platform Tools](https://developer.android.com/studio/releases/platform-tools)\r\n- **macOS**: `brew install android-platform-tools`\r\n- **Linux**: `sudo apt-get install adb` (Debian/Ubuntu)\r\n\r\n#### Verify Connection\r\n```bash\r\nadb devices\r\n# Should show your device as \"device\"\r\n```\r\n\r\n## 🚀 Quick Start\r\n\r\n### Standalone Usage\r\n\r\n```javascript\r\nconst { TwoFAHelper } = require('2fa-adb-tools');\r\n\r\nconst helper = new TwoFAHelper({ screenshotInterval: 3000 });\r\nawait helper.startMonitoring();\r\n\r\ntry {\r\n    const code = await helper.waitForCode(60000);\r\n    console.log(`2FA code: ${code}`);\r\n} finally {\r\n    await helper.stopMonitoring();\r\n}\r\n```\r\n\r\n### With Playwright\r\n\r\n```javascript\r\nconst { test, expect } = require('@playwright/test');\r\nconst { TwoFAHelper, waitFor2FACode } = require('2fa-adb-tools');\r\n\r\ntest.describe('2FA Test', () => {\r\n    let twoFAHelper;\r\n\r\n    test.beforeAll(async () => {\r\n        twoFAHelper = new TwoFAHelper({ screenshotInterval: 3000 });\r\n        await twoFAHelper.startMonitoring();\r\n    });\r\n\r\n    test.afterAll(async () => {\r\n        await twoFAHelper.stopMonitoring();\r\n    });\r\n\r\n    test('login with 2FA', async ({ page }) => {\r\n        await page.goto('https://example.com/login');\r\n        await page.fill('#username', process.env.USERNAME);\r\n        await page.fill('#password', process.env.PASSWORD);\r\n        await page.click('#submit');\r\n\r\n        const code = await waitFor2FACode(page, twoFAHelper, {\r\n            codeInputSelector: '#code-input',\r\n            autoFill: true\r\n        });\r\n\r\n        await expect(page.locator('.success-message')).toBeVisible();\r\n    });\r\n});\r\n```\r\n\r\n## 📚 API Reference\r\n\r\n### TwoFAHelper\r\n\r\nMain class for Playwright integration and simplified 2FA code management.\r\n\r\n| Method | Description |\r\n|--------|-------------|\r\n| `startMonitoring()` | Begin monitoring for 2FA codes |\r\n| `stopMonitoring()` | Stop monitoring and cleanup |\r\n| `waitForCode(timeout)` | Wait for next code (returns Promise<string>) |\r\n\r\n### ADBMonitor\r\n\r\nLow-level class for direct ADB interaction.\r\n\r\n| Event | Description |\r\n|-------|-------------|\r\n| `code` | Emitted when a verification code is found |\r\n| `error` | Emitted on errors |\r\n\r\n### OCRProcessor\r\n\r\nHandles text recognition from images.\r\n\r\n```javascript\r\nconst ocr = new OCRProcessor({ languages: 'rus+eng' });\r\nawait ocr.init();\r\nconst text = await ocr.recognize('./screenshot.png');\r\nconst code = ocr.processText(text);\r\nawait ocr.terminate();\r\n```\r\n\r\n### ScreenshotManager\r\n\r\nManages screenshot capture and storage.\r\n\r\n```javascript\r\nconst sm = new ScreenshotManager({\r\n    adbPath: 'adb',\r\n    deviceId: 'device-id',\r\n    maxScreenshots: 50\r\n});\r\n\r\nconst screenshot = await sm.takeScreenshot();\r\nconst cropped = await sm.cropScreenshot(screenshot);\r\nsm.saveCodeScreenshot(screenshot, cropped, '123456');\r\n```\r\n\r\n## ⚙️ Configuration\r\n\r\n### TwoFAHelper Options\r\n\r\n```javascript\r\n{\r\n    // Monitoring\r\n    screenshotInterval: 3000,      // How often to take screenshots (ms)\r\n        autoSwipe: true,               // Enable/disable all swipes\r\n\r\n        // Swipe behavior\r\n        swipeAfterCode: true,          // Swipe after finding a code\r\n        swipeInterval: 10000,          // Auto-swipe every 10 seconds (0 = disable)\r\n\r\n        // Swipe coordinates\r\n        swipeConfig: {\r\n        startX: 150, startY: 1200,   // Start position\r\n            endX: 950, endY: 1200,       // End position\r\n            duration: 400                 // Swipe duration (ms)\r\n    },\r\n\r\n    // OCR crop region (where codes appear)\r\n    cropConfig: {\r\n        top: 930, bottom: 100,        // Vertical crop\r\n            left: 100, right: 100         // Horizontal crop\r\n    },\r\n\r\n    // Advanced\r\n    ocrLanguages: 'rus+eng',        // Tesseract languages\r\n        deviceId: null,                  // Specific device ID\r\n        maxScreenshots: 50               // Screenshots to keep\r\n}\r\n```\r\n\r\n### Finding Coordinates\r\n\r\n1. Enable **Pointer Location** in Developer Options on Android\r\n2. Note the coordinates for your swipe gesture\r\n3. Adjust `swipeConfig` accordingly\r\n\r\n### Optimizing Crop Region\r\n\r\nAdjust `cropConfig` to focus only on the area where 2FA codes appear in notifications.\r\n\r\n## 🔍 Troubleshooting\r\n\r\n| Issue | Solution |\r\n|-------|----------|\r\n| ADB not found | Install Android platform-tools and add to PATH |\r\n| No devices | Run `adb devices`, enable USB debugging, re-authorize device |\r\n| OCR fails | Adjust `cropConfig`, improve screenshot quality, check contrast |\r\n| Swipe not working | Verify coordinates, increase duration, ensure screen is unlocked |\r\n\r\n### Debug Mode\r\n\r\n```javascript\r\n// Enable verbose logging\r\nprocess.env.DEBUG = '2fa-adb-tools:*';\r\n\r\n// Log events\r\nhelper.on('code', console.log);\r\nhelper.on('error', console.error);\r\n```\r\n\r\n## 🤖 AI Disclosure\r\n\r\nThis project was developed with assistance from AI language models (DeepSeek) for code generation, documentation, and refactoring. The core logic, architecture decisions, and final code quality were reviewed, tested and approved by a human developer.\r\n\r\n## 📄 License\r\n\r\nMIT © [pifpafi4](https://github.com/pifpafi4) - делайте что хотите, я за код не отвечаю.","readmeFilename":"README.md","_rev":"1-08cba7d0d84b6dbb420432d44c3b126d"}