-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadItem.js
45 lines (33 loc) · 921 Bytes
/
readItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Modules
const {BrowserWindow} = require('electron')
// Offscreen BrowserWindow
let offscreenWindow
// Exported readItem function
module.exports = (url, callback) => {
// Create offscreen window
offscreenWindow = new BrowserWindow({
width: 500,
height: 500,
show: false,
webPreferences: {
offscreen: true
}
})
// Load item url
offscreenWindow.loadURL(url)
// Wait for content to finish loading
offscreenWindow.webContents.on('did-finish-load', e => {
// Get page title
let title = offscreenWindow.getTitle()
// Get screenshot (thumbnail)
offscreenWindow.webContents.capturePage().then( image => {
// Get image as a dataURL
let screenshot = image.toDataURL()
// Execute callback with new item object
callback({ title, screenshot, url })
// Clean up
offscreenWindow.close()
offscreenWindow = null
})
})
}