1const Apify = require('apify');
2
3Apify.main(async () => {
4
5 const input = await Apify.getInput();
6
7 const options = {};
8
9 if (input.viewport) {
10 options.defaultViewport = input.viewport
11 }
12 const browser = await Apify.launchPuppeteer(options);
13
14 const page = await browser.newPage();
15 await page.setContent(input.html);
16 const image = await page.screenshot({type: input.format, fullPage: true});
17
18 await Apify.setValue('screenshot', image, { contentType: `image/${input.format}` });
19 if (input.outputType == "link") {
20 const keyValueStore = await Apify.openKeyValueStore();
21 const link = keyValueStore.getPublicUrl('screenshot');
22 await Apify.setValue('OUTPUT', {link});
23 } else {
24 await Apify.setValue('OUTPUT', image, { contentType: `image/${input.format}` });
25 }
26});