-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 995 Bytes
/
Copy pathindex.js
File metadata and controls
40 lines (32 loc) · 995 Bytes
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
const launchChrome = require('@serverless-chrome/lambda')
const CDP = require('chrome-remote-interface')
function runChrome (event, callback) {
console.log('EVENT:', event)
launchChrome({
flags: ['--window-size=1280x1696', '--hide-scrollbars', '--headless'],
// chromePath: './node_modules/@serverless-chrome/lambda/dist/headless-chromium'
})
.then((chrome) => {
// Chrome is now running on localhost:9222
CDP.Version()
.then((versionInfo) => {
callback(null, {
versionInfo,
})
})
.catch((error) => {
callback(error)
})
})
// Chrome didn't launch correctly 😢
.catch(callback)
}
module.exports.handler = function handler (event, context, callback) {
runChrome(event, callback)
}
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
process.exit(1)
});
// Local test
// runChrome({}, console.log)