-
Notifications
You must be signed in to change notification settings - Fork 0
/
puppeteer.js
54 lines (46 loc) · 1.49 KB
/
puppeteer.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
46
47
48
49
50
51
52
53
54
const puppeteer = require('puppeteer');
let config = require('./config');
const fs = require('fs');
(async () => {
let text = "";
let json = {};
const browser = await puppeteer.launch();
//const browser = puppeteer.launch({product: 'firefox'});
const page = await browser.newPage();
page.on('console', msg => {
text = msg.text().replace(/\:/g, ": ").replace(/,/g, ", ");
try {
json = JSON.parse(msg.text());
if (json.failed) {
console.log(json);
page.goto(json.fetch);
browser.close();
}
}
catch {
console.log(`${msg.text()} (not parsed)`);
}
});
await page.goto('http://localhost:8989/2020-06-20-colour-match-api/#3', {
waitUntil: 'domcontentloaded'
});
await page.waitForSelector('canvas', {
visible: true
});
const canvasElement = await page.$('canvas');
let filename = `${json.cc_id}.png`;
await canvasElement.screenshot({
path:filename,
omitBackground: true,
});
console.log(config);
console.log("replacing config.image_filename, was:");
console.log(config.image_filename);
config.image_filename = filename;
console.log("replacing config.status_text, was:");
console.log(config.status_text);
config.status_text = text;
config.in_reply_to_id = null;
fs.writeFileSync('config.json', JSON.stringify(config, null, 2));
await browser.close();
})();