From 10f50b46011e2d4b32e32b4fff2e820c9ad7ba23 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Sun, 20 Nov 2022 06:47:48 -0500 Subject: [PATCH] feat(plugins/community/screenshot): add `plugin_screenshot_viewport` and `plugin_screenshot_wait` --- source/plugins/community/screenshot/index.mjs | 6 ++++-- .../plugins/community/screenshot/metadata.yml | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/source/plugins/community/screenshot/index.mjs b/source/plugins/community/screenshot/index.mjs index 82f91dfc702..366bb6bf552 100644 --- a/source/plugins/community/screenshot/index.mjs +++ b/source/plugins/community/screenshot/index.mjs @@ -7,7 +7,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal return null //Load inputs - let {url, selector, title, background} = imports.metadata.plugins.screenshot.inputs({data, account, q}) + let {url, selector, title, background, viewport, wait} = imports.metadata.plugins.screenshot.inputs({data, account, q}) if (!url) throw {error: {message: "URL is not set"}} @@ -16,9 +16,11 @@ export default async function({login, q, imports, data, account}, {enabled = fal const browser = await imports.puppeteer.launch() console.debug(`metrics/compute/${login}/plugins > screenshot > started ${await browser.version()}`) const page = await browser.newPage() - await page.setViewport({width: 1280, height: 1280}) + await page.setViewport(viewport) console.debug(`metrics/compute/${login}/plugins > screenshot > loading ${url}`) await page.goto(url, {waitUntil:["domcontentloaded", "networkidle2"]}) + if (wait) + await new Promise(solve => setTimeout(solve, wait)) //Screenshot await page.waitForSelector(selector) diff --git a/source/plugins/community/screenshot/metadata.yml b/source/plugins/community/screenshot/metadata.yml index bc6eccc7f1a..b478502e578 100644 --- a/source/plugins/community/screenshot/metadata.yml +++ b/source/plugins/community/screenshot/metadata.yml @@ -42,6 +42,23 @@ inputs: type: string default: body + plugin_screenshot_viewport: + description: | + Viewport options + type: json + default: | + { + "width": 1280, + "height": 1280 + } + + plugin_screenshot_wait: + description: | + Wait time before taking screenshot (ms) + type: number + min: 0 + default: 0 + plugin_screenshot_background: description: | Background