Screenshot Monitor Pro
A Node.js package for automated screenshot monitoring with SQLite database storage and configurable capture intervals. Perfect for activity tracking, surveillance, and automated screen recording.
Features
- 📸 Multi-Monitor Screenshot Capture: Takes screenshots from all attached monitors
- 🖼️ Thumbnail Generation: Automatically creates thumbnails for easy browsing
- 💾 SQLite Database: Stores all screenshot metadata and file paths
- ⚙️ Configurable: Customizable capture frequency, quality, and storage paths
- 🔍 Query Interface: Easy API to retrieve and manage screenshots
- 📊 Statistics: Get insights about your screenshot collection
- 🗂️ Organized Storage: Separate folders for screenshots and thumbnails
- 🆔 Unique Filenames: Format:
<Monitor ID>-<Timestamp>-<UUID>.<ext>
Installation
npm install screenshot-monitor-pro
Global Installation (CLI Tool)
npm install -g screenshot-monitor-pro
After global installation, you can use the CLI tool directly:
screenshot-monitor start --frequency 60000
screenshot-monitor capture
screenshot-monitor list --limit 5
Quick Start
Using the CLI Tool
npm start
npm run cli start --frequency 60000
npm run capture
npm run cli capture --monitor 0
npm run list
npm run cli list --monitor 0
npm run stats
npm run cli stats --monitor 0
npm run monitors
Using the JavaScript API
const ScreenshotMonitor = require('screenshot-monitor-pro');
const monitor = new ScreenshotMonitor({
frequency: 60000,
screenshotQuality: 90,
thumbnailWidth: 300,
thumbnailHeight: 200
});
async function startMonitoring() {
await monitor.init();
await monitor.start();
console.log('Screenshot monitoring started!');
}
startMonitoring();
Configuration Options
frequency | number | 30000 | Interval between screenshots (milliseconds) |
screenshotQuality | number | 90 | PNG quality (1-100) |
thumbnailWidth | number | 300 | Thumbnail width in pixels |
thumbnailHeight | number | 200 | Thumbnail height in pixels |
userDataPath | string | ~/.screenshot-monitor-pro | Base directory for storage |
API Reference
Constructor
const monitor = new ScreenshotMonitor(config);
Methods
async init()
Initialize the monitor, create directories, and set up the database.
await monitor.init();
async start()
Start the screenshot monitoring process.
await monitor.start();
stop()
Stop the screenshot monitoring process.
monitor.stop();
async captureScreenshot(monitor)
Manually capture a screenshot from a specific monitor.
const results = await monitor.captureAllScreenshots();
const monitors = monitor.getMonitors();
const result = await monitor.captureScreenshot(monitors[0]);
console.log(result);
async getScreenshots(limit, offset, monitorId)
Retrieve screenshot entries from the database.
const screenshots = await monitor.getScreenshots(10);
const screenshots = await monitor.getScreenshots(20, 40);
const screenshots = await monitor.getScreenshots(10, 0, 0);
const screenshots = await monitor.getScreenshotsByMonitor(0, 10);
async getScreenshotById(id)
Get a specific screenshot by its database ID.
const screenshot = await monitor.getScreenshotById(1);
async deleteScreenshot(id)
Delete a screenshot and its thumbnail from storage and database.
await monitor.deleteScreenshot(1);
async getStats(monitorId)
Get statistics about the screenshot collection.
const stats = await monitor.getStats();
console.log(stats);
const stats = await monitor.getStats(0);
const monitorStats = await monitor.getMonitorStats();
updateConfig(newConfig)
Update the monitor configuration.
monitor.updateConfig({
frequency: 45000,
thumbnailWidth: 400
});
getMonitors()
Get information about available monitors.
const monitors = monitor.getMonitors();
getConfig()
Get the current configuration.
const config = monitor.getConfig();
async close()
Close the database connection.
await monitor.close();
Complete Example
const ScreenshotMonitor = require('screenshot-monitor-pro');
async function example() {
const monitor = new ScreenshotMonitor({
frequency: 30000,
screenshotQuality: 95,
thumbnailWidth: 400,
thumbnailHeight: 300,
userDataPath: './my-screenshots'
});
try {
await monitor.init();
console.log('Monitor initialized');
await monitor.start();
console.log('Monitoring started');
setTimeout(async () => {
const stats = await monitor.getStats();
console.log('Statistics:', stats);
const screenshots = await monitor.getScreenshots(5);
console.log('Recent screenshots:', screenshots);
monitor.stop();
console.log('Monitoring stopped');
await monitor.close();
console.log('Database closed');
}, 120000);
} catch (error) {
console.error('Error:', error);
}
}
example();
File Structure
The package creates the following directory structure:
~/.screenshot-monitor-pro/
├── screenshots/
│ ├── 0-2024-01-15T10-30-00-000Z-550e8400-e29b-41d4-a716-446655440000.png
│ ├── 1-2024-01-15T10-30-00-000Z-550e8400-e29b-41d4-a716-446655440001.png
│ └── ...
├── thumbnails/
│ ├── thumb-0-2024-01-15T10-30-00-000Z-550e8400-e29b-41d4-a716-446655440000.png
│ ├── thumb-1-2024-01-15T10-30-00-000Z-550e8400-e29b-41d4-a716-446655440001.png
│ └── ...
└── screenshots.db
Filename Format
Screenshots are saved with the format: <Monitor ID>-<Timestamp>-<UUID>.<ext>
- Monitor ID: The ID of the monitor (0, 1, 2, etc.)
- Timestamp: ISO timestamp when the screenshot was taken
- UUID: Unique identifier to prevent filename collisions
- Extension: PNG format for screenshots, PNG for thumbnails
Database Schema
The SQLite database contains a screenshots
table with the following columns:
id
: Primary key
filename
: Original screenshot filename
thumbnail_filename
: Thumbnail filename
timestamp
: Capture timestamp
monitor_id
: ID of the monitor that was captured
monitor_name
: Name of the monitor
screen_width
: Original image width
screen_height
: Original image height
file_size
: File size in bytes
file_path
: Full path to screenshot file
thumbnail_path
: Full path to thumbnail file
uuid
: Unique identifier for the screenshot
Error Handling
The package includes comprehensive error handling:
try {
await monitor.init();
await monitor.start();
} catch (error) {
console.error('Monitor error:', error.message);
if (error.code === 'ENOENT') {
console.error('Directory creation failed');
}
}
Performance Considerations
- Memory Usage: Screenshots are processed in memory and immediately written to disk
- Storage: Monitor disk space usage, especially with high-frequency captures
- Database: SQLite database grows with each screenshot entry
- CPU: Image processing for thumbnails uses CPU resources
CLI Commands
start | Start screenshot monitoring | screenshot-monitor start --frequency 60000 |
capture | Capture screenshots from all monitors | screenshot-monitor capture |
capture | Capture from specific monitor | screenshot-monitor capture --monitor 0 |
list | List recent screenshots | screenshot-monitor list --limit 10 |
list | List from specific monitor | screenshot-monitor list --monitor 0 |
stats | Show overall statistics | screenshot-monitor stats |
stats | Show monitor-specific stats | screenshot-monitor stats --monitor 0 |
monitors | Show available monitors | screenshot-monitor monitors |
config | Show current configuration | screenshot-monitor config |
CLI Options
--frequency <ms>
: Screenshot interval in milliseconds
--quality <1-100>
: Screenshot quality percentage
--thumb-width <px>
: Thumbnail width in pixels
--thumb-height <px>
: Thumbnail height in pixels
--path <directory>
: Custom storage directory
--limit <number>
: Number of screenshots to list
--monitor <id>
: Specific monitor ID to target
Platform Support
- ✅ Windows
- ✅ macOS
- ✅ Linux
Dependencies
screenshot-desktop
: Cross-platform screenshot capture
sqlite3
: Database operations
sharp
: Image processing and thumbnail generation
fs-extra
: Enhanced file system operations
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Support
For issues and questions, please open an issue on GitHub.