Skip to content

Commit 9b22e99

Browse files
committed
Print screenshot on terminal when is possible
1 parent 09a82b5 commit 9b22e99

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

examples/screenshot.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const { URL } = require('url')
4+
const termImg = require('term-img')
45

56
const createBrowserless = require('..')
67
const browserless = createBrowserless()
@@ -9,12 +10,16 @@ const url = new URL(process.argv[2])
910
;(async () => {
1011
const tmpStream = await browserless.screenshot(url.toString(), {
1112
tmpOpts: {
12-
path: './',
1313
name: `${url.hostname}.${Date.now()}`
1414
}
1515
})
1616

17-
const filepath = tmpStream.path
18-
console.log(filepath)
19-
process.exit()
17+
try {
18+
termImg(tmpStream.path)
19+
await tmpStream.cleanup()
20+
process.exit()
21+
} catch (err) {
22+
console.log(`Screenshot saved at '${tmpStream.path}'`)
23+
process.exit()
24+
}
2025
})()

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"standard": "latest",
6060
"standard-markdown": "latest",
6161
"string-to-stream": "latest",
62+
"term-img": "latest",
6263
"time-span": "latest"
6364
},
6465
"engines": {

0 commit comments

Comments
 (0)