
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
electron2screenshot
Advanced tools
electron 截图插件
npm i electron2screenshot
import { app, globalShortcut } from 'electron'
import Screenshots from './screenshots'
app.whenReady().then(() => {
const screenshots = new Screenshots()
globalShortcut.register('ctrl+shift+a', () => {
screenshots.startCapture()
screenshots.$view.webContents.openDevTools()
})
// 点击确定按钮回调事件
screenshots.on('ok', (e, buffer, bounds) => {
console.log('capture', buffer, bounds)
})
// 点击取消按钮回调事件
screenshots.on('cancel', () => {
console.log('capture', 'cancel1')
})
screenshots.on('cancel', e => {
// 执行了preventDefault
// 点击取消不会关闭截图窗口
e.preventDefault()
console.log('capture', 'cancel2')
})
// 点击保存按钮回调事件
screenshots.on('save', (e, buffer, bounds) => {
console.log('capture', buffer, bounds)
})
debug({ showDevTools: true, devToolsMode: 'undocked' })
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
globalShortcut.register('esc', () => {
if (screenshots.$win?.isFocused()) {
screenshots.endCapture()
}
})
BrowserWindow,减少创建窗口的开销,可用以下代码实现。需注意,启用该功能,会导致window-all-closed事件不触发,因此需要手动关闭截图窗口// 是否复用截图窗口,加快截图窗口显示,默认值为 false
// 如果设置为 true 则会在第一次调用截图窗口时创建,后续调用时直接使用
// 且由于窗口不会 close,所以不会触发 app 的 `window-all-closed` 事件
const screenshots = new Screenshots({
singleWindow: true
})
| 名称 | 说明 | 返回值 |
|---|---|---|
constructor(opts: ScreenshotsOpts): Screenshots | 调用截图方法截图 | - |
startCapture(): Promise<void> | 调用截图方法截图 | - |
endCapture(): Promise<void> | 手动结束截图 | - |
setLang(lang: Lang): Promise<void> | 修改语言 | - |
interface Bounds {
x: number
y: number
width: number
height: number
}
export interface Display {
id: number
x: number
y: number
width: number
height: number
}
export interface ScreenshotsData {
bounds: Bounds
display: Display
}
class Event {
public defaultPrevented = false
public preventDefault(): void {
this.defaultPrevented = true
}
}
| 名称 | 说明 | 回调参数 |
|---|---|---|
| ok | 截图确认事件 | (event: Event, buffer: Buffer, data: ScreenshotsData) => void |
| cancel | 截图取消事件 | (event: Event) => void |
| save | 截图保存事件 | (event: Event, buffer: Buffer, data: ScreenshotsData) => void |
event对象可调用preventDefault方法来阻止默认事件,例如阻止默认保存事件const screenshots = new Screenshots({
lang: {
magnifier_position_label: 'Position',
operation_ok_title: 'Ok',
operation_cancel_title: 'Cancel',
operation_save_title: 'Save',
operation_redo_title: 'Redo',
operation_undo_title: 'Undo',
operation_mosaic_title: 'Mosaic',
operation_text_title: 'Text',
operation_brush_title: 'Brush',
operation_arrow_title: 'Arrow',
operation_ellipse_title: 'Ellipse',
operation_rectangle_title: 'Rectangle'
}
})
screenshots.on('save', (e, buffer, data) => {
// 阻止插件自带的保存功能
// 用户自己控制保存功能
e.preventDefault()
// 用户可在这里自己定义保存功能
console.log('capture', buffer, data)
})
screenshots.startCapture()
FAQs
electron 截图插件
We found that electron2screenshot 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.