Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
windows-ss
Advanced tools
Readme
Take screenshots quickly on Windows by communicating directly with native API's.
Did I mention that it's DPI aware too?
Using this repo. The numbers below were taken over 1000 runs, each at 2560x1440*, outputing bmp
.
Library | Save to buffer | Save to file |
---|---|---|
windows-ss | 52ms | 51ms |
screenshot-desktop | 152ms | 141ms |
desktop-screenshot | n/a | 63ms** |
* Except for desktop-screenshot
, it ran at 1706x960 as it's DPI unaware.
** Times are relative to lower resolution of 1706x960. If interpolated back to 1440p according to a DPI of 1.5, 63 * (1.5 ^ 2) = 141ms
npm i windows-ss
IMPORTANT: You'll need .NET 4.5 or .NET Core installed, as this library depends on
edge-js
. Refer here for more info regarding installation.
import { capturePrimaryMonitor } from 'windows-ss';
await capturePrimaryMonitor({
// The format of the returned Buffer & saved file.
format: 'png',
// How much to carve off the edges. (Left, Top, Right, Bottom)
crop: {
left: 0,
top: 0,
right: 0,
bottom: 0,
},
// The bounds where the screen will be captured. (Left, Top, Right, Bottom)
bounds: {
left: 0,
top: 0,
right: 0,
bottom: 0,
},
// The file the screenshot will be saved to.
save: './ss.png',
});
getMonitorInfos
getMonitorInfosSync
Returns information about the the currently connected monitors.
Promise<MonitorInfo[]>
—— MonitorInfo[]
MonitorInfo
s gotten from the current system.import { getMonitorInfos, getMonitorInfosSync } from 'windows-ss';
await getMonitorInfos();
getMonitorInfosSync();
/*
// Example output
[
{
monitor: { left: 0, top: 0, right: 2560, bottom: 1440 },
workArea: { left: 0, top: 0, right: 2560, bottom: 1380 },
deviceName: '\\\\.\\DISPLAY1'
},
{
monitor: { left: 304, top: -1080, right: 2224, bottom: 0 },
workArea: { left: 304, top: -1080, right: 2224, bottom: -40 },
deviceName: '\\\\.\\DISPLAY2'
}
]
*/
captureMonitorByIndex
captureMonitorByIndexSync
Captures a screenshot of the monitor matching the device index.
deviceIndex: number
config: Configuration
Promise<Buffer | null>
—— Buffer | null
options.format
. null
is returned instead if save
was passed into the config
parameter.import { captureMonitorByIndex, captureMonitorByIndexSync, getMonitorInfos } from 'windows-ss';
const monitorInfos = await getMonitorInfos();
await captureMonitorByIndex(monitorInfos.length - 1);
captureMonitorByIndexSync(0);
captureMonitorByName
captureMonitorByNameSync
Captures a screenshot of the monitor matching the device name.
deviceName: string
config: Configuration
Promise<Buffer | null>
—— Buffer | null
options.format
. null
is returned instead if save
was passed into the config
parameter.import { captureMonitorByName, captureMonitorByNameSync, getMonitorInfos } from 'windows-ss';
const monitorInfos = await getMonitorInfos();
await captureMonitorByName(monitorInfos[0].deviceName);
captureMonitorByNameSync(String.raw`\\.\DISPLAY1`);
capturePrimaryMonitor
capturePrimaryMonitorSync
Captures a screenshot of the primary monitor.
config: Configuration
Promise<Buffer | null>
—— Buffer | null
options.format
. null
is returned instead if save
was passed into the config
parameter.import { capturePrimaryMonitor, capturePrimaryMonitorSync } from 'windows-ss';
await capturePrimaryMonitor();
capturePrimaryMonitorSync();
captureWindowByTitle
captureWindowByTitleSync
Captures a screenshot of the window matching the title.
title: string
config: Configuration
Promise<Buffer | null>
—— Buffer | null
options.format
. null
is returned instead if save
was passed into the config
parameter.import { captureWindowByTitle, captureWindowByTitleSync } from 'windows-ss';
await captureWindowByTitle('Task Manager');
captureWindowByTitleSync('Notepad');
captureActiveWindow
captureActiveWindowSync
Captures a screenshot of the currently active/focused window.
config: Configuration
Promise<Buffer | null>
—— Buffer | null
options.format
. null
is returned instead if save
was passed into the config
parameter.import { captureActiveWindow, captureActiveWindowSync } from 'windows-ss';
await captureActiveWindow();
captureActiveWindowSync();
Configuration
Contains options that can be provided by the user when taking a screenshot.
(Optional) format: string
— The format of the returned buffer & saved file.
'png'
'png'
'jpg'
'jpeg'
'bmp'
'emf'
'exif'
'gif'
'icon'
'tiff'
'wmf'
(Optional) crop: PlainRectangle
— How much to carve off the edges.
(Optional) bounds: PlainRectangle
— The bounds where the screen will be captured.
(Optional) save: string
— The path to where the screenshot will be saved to.
Note: If this property is not provided, the screenshot is simply returned as a Buffer.
MonitorInfo
Contains a description of a monitor.
monitor: PlainRectangle
— The resolution of the entire monitor.workArea: PlainRectangle
— The resolution of the entire monitor excluding the taskbar.deviceName: string
— The device name of the monitor.PlainRectangle
Contains properties to form a plain rectangle.
left: number
— The left edge of the rectangle.
IMPORTANT: This must be of
int
type, meaning no decimals. Else, it will fail applying configuration.
top: number
— The top edge of the rectangle.
IMPORTANT: This must be of
int
type, meaning no decimals. Else, it will fail applying configuration.
right: number
— The right edge of the rectangle.
IMPORTANT: This must be of
int
type, meaning no decimals. Else, it will fail applying configuration.
bottom: number
— The bottom edge of the rectangle.
IMPORTANT: This must be of
int
type, meaning no decimals. Else, it will fail applying configuration.
NoMatchError
Thrown when no match can be found with the provided arguments.
paramName: string
name: string
stack: string
raw: CSException
InvalidArgumentCountError
Thrown when an invalid amount of arguments were provided.
paramName: string
name: string
stack: string
raw: CSException
InvalidConfigurationError
Thrown when an invalid Configuration
object was provided.
paramName: string
name: string
stack: string
raw: CSException
CSArgumentError
Based on C#'s ArgumentException
.
CSError
Based on C#'s SystemException
.
ClientError
Error
raw: CSException
InnerException
property of the raw Error
object thrown by edge-js
name: string
stack: string
All contributions are welcome. File an issue if you find something wrong, & a pull request if you can fix it.
MIT.
FAQs
[![npm version](https://badge.fury.io/js/windows-ss.svg)](https://badge.fury.io/js/windows-ss)
The npm package windows-ss receives a total of 4 weekly downloads. As such, windows-ss popularity was classified as not popular.
We found that windows-ss demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.