-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhandler.js
43 lines (35 loc) · 1.11 KB
/
handler.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
'use strict';
const { Chromeless } = require('chromeless')
var moment = require("moment")
module.exports.invokeRemoteChromeless = (event, context, callback) => {
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
},
body: JSON.stringify({
message: 'Finished taking screenshot with serverlesss chrome! Your function executed successfully!',
input: event,
}),
};
var now = moment();
console.log(now.format("dddd, MMMM Do YYYY, h:mm:ss a"))
run()
async function run() {
const chromeless = new Chromeless({
remote: {
endpointUrl: 'https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com/dev',
apiKey: 'your-api-key-here'
},
})
const screenshot = await chromeless
.goto('https://www.google.com')
.type('chromeless', 'input[name="q"]')
.press(13)
.wait('#resultStats')
.screenshot()
console.log(screenshot) // prints local file path or S3 url
await chromeless.end()
}
callback(null, response);
};