A cross-platform API for preventing screen capture and recording in Electron applications. This library allows developers to protect sensitive content from being captured during screen sharing, recording, or other screen capture scenarios.
- Cross-Platform Support: Windows (β ), macOS (π§), Linux (π§)
- Easy Integration: Simple TypeScript/JavaScript API
- Native Performance: Direct OS-level API integration
- Privacy Protection: Prevents content from appearing in screen captures
- Reversible: Can enable/disable protection dynamically
- Installation
- Quick Start
- API Reference
- Platform Support
- Examples
- Building from Source
- Contributing
- License
npm install secure-visibility-api- Node.js 14.0.0 or higher
- Electron 10.0.0 or higher
- Platform-specific build tools (see Building from Source)
import { preventCapture, allowCapture, isCapturePrevented } from 'secure-visibility-api';
import { BrowserWindow } from 'electron';
// Create your Electron window
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
// Get the native window handle
const hwnd = mainWindow.getNativeWindowHandle();
// Prevent screen capture
try {
const success = preventCapture(hwnd);
if (success) {
console.log('Screen capture prevention enabled');
}
} catch (error) {
console.error('Failed to prevent capture:', error);
}
// Check if capture is prevented
const isProtected = isCapturePrevented(hwnd);
console.log('Window is protected:', isProtected);
// Allow capture again (if needed)
allowCapture(hwnd);Prevents screen capture and recording of the specified window.
Parameters:
hwnd- The window handle fromBrowserWindow.getNativeWindowHandle()
Returns:
boolean-trueif successful,falseotherwise
Throws:
Error- If the operation fails or invalid parameters are provided
Allows screen capture and recording of the specified window (reverses preventCapture).
Parameters:
hwnd- The window handle fromBrowserWindow.getNativeWindowHandle()
Returns:
boolean-trueif successful,falseotherwise
Throws:
Error- If the operation fails or invalid parameters are provided
Checks if capture prevention is currently active for the specified window.
Parameters:
hwnd- The window handle fromBrowserWindow.getNativeWindowHandle()
Returns:
boolean-trueif capture is prevented,falseif capture is allowed
Throws:
Error- If the operation fails or invalid parameters are provided
Gets the current platform.
Returns:
string- The platform string ('win32','darwin','linux')
Checks if the current platform is supported.
Returns:
boolean-trueif the platform is supported,falseotherwise
| Platform | Status | API Used | Notes |
|---|---|---|---|
| Windows | β Supported | SetWindowDisplayAffinity |
Full support with WDA_MONITOR |
| macOS | π§ In Development | Core Graphics APIs | Planned implementation |
| Linux | π§ In Development | X11/Wayland APIs | Limited support due to platform restrictions |
Uses the Windows API SetWindowDisplayAffinity with WDA_MONITOR flag to prevent:
- Screen capture tools (Snipping Tool, etc.)
- Screen recording software
- Remote desktop applications
- Screen sharing in video conferencing apps
import { preventCapture, allowCapture } from 'secure-visibility-api';
import { BrowserWindow, ipcMain } from 'electron';
const mainWindow = new BrowserWindow({
width: 1200,
height: 800
});
// Enable protection when window is ready
mainWindow.once('ready-to-show', () => {
const hwnd = mainWindow.getNativeWindowHandle();
preventCapture(hwnd);
});
// IPC handlers for dynamic control
ipcMain.handle('enable-protection', () => {
const hwnd = mainWindow.getNativeWindowHandle();
return preventCapture(hwnd);
});
ipcMain.handle('disable-protection', () => {
const hwnd = mainWindow.getNativeWindowHandle();
return allowCapture(hwnd);
});import {
preventCapture,
allowCapture,
isCapturePrevented,
isPlatformSupported
} from 'secure-visibility-api';
class WindowProtection {
private hwnd: number;
private isProtected: boolean = false;
constructor(hwnd: number) {
this.hwnd = hwnd;
}
async enableProtection(): Promise<boolean> {
if (!isPlatformSupported()) {
throw new Error('Platform not supported');
}
try {
this.isProtected = preventCapture(this.hwnd);
return this.isProtected;
} catch (error) {
console.error('Failed to enable protection:', error);
return false;
}
}
async disableProtection(): Promise<boolean> {
try {
const result = allowCapture(this.hwnd);
if (result) {
this.isProtected = false;
}
return result;
} catch (error) {
console.error('Failed to disable protection:', error);
return false;
}
}
getProtectionStatus(): boolean {
try {
return isCapturePrevented(this.hwnd);
} catch (error) {
console.error('Failed to get protection status:', error);
return false;
}
}
}- Visual Studio 2019 or later with C++ build tools
- Windows SDK
- Xcode Command Line Tools
- macOS SDK
- GCC/G++ compiler
- Python 3.x
- make
# Install dependencies
npm install
# Build TypeScript and native modules
npm run build
# Build only TypeScript
npm run build:ts
# Build only native modules
npm run build:native
# Clean build artifacts
npm run clean
# Run tests
npm test# Windows
npm run build:native:win32
# macOS (when implemented)
npm run build:native:darwin
# Linux (when implemented)
npm run build:native:linux# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run example app
npm run example- Window Handle: Always use
BrowserWindow.getNativeWindowHandle()to get the correct window handle - Timing: Apply protection after the window is fully loaded and visible
- Platform Limitations: Some platforms may have limited or no support for capture prevention
- Performance: Native modules provide optimal performance with minimal overhead
- Security: This library prevents visual capture but doesn't protect against other forms of data extraction
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Clone your fork
- Install dependencies:
npm install - Create a feature branch
- Make your changes
- Add tests for new functionality
- Run tests:
npm test - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Windows implementation based on Microsoft's
SetWindowDisplayAffinityAPI - Inspired by the need for privacy protection in Electron applications
- Built with Node.js Native Addons API
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information
- Include your platform, Node.js version, and Electron version
Made with β€οΈ for the Electron community