feat(plugins/community/screenshot): add plugin_screenshot_viewport and plugin_screenshot_wait (#1288)
This commit is contained in:
@@ -7,7 +7,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
|||||||
return null
|
return null
|
||||||
|
|
||||||
//Load inputs
|
//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)
|
if (!url)
|
||||||
throw {error: {message: "URL is not set"}}
|
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()
|
const browser = await imports.puppeteer.launch()
|
||||||
console.debug(`metrics/compute/${login}/plugins > screenshot > started ${await browser.version()}`)
|
console.debug(`metrics/compute/${login}/plugins > screenshot > started ${await browser.version()}`)
|
||||||
const page = await browser.newPage()
|
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}`)
|
console.debug(`metrics/compute/${login}/plugins > screenshot > loading ${url}`)
|
||||||
await page.goto(url, {waitUntil:["domcontentloaded", "networkidle2"]})
|
await page.goto(url, {waitUntil:["domcontentloaded", "networkidle2"]})
|
||||||
|
if (wait)
|
||||||
|
await new Promise(solve => setTimeout(solve, wait))
|
||||||
|
|
||||||
//Screenshot
|
//Screenshot
|
||||||
await page.waitForSelector(selector)
|
await page.waitForSelector(selector)
|
||||||
|
|||||||
@@ -42,6 +42,23 @@ inputs:
|
|||||||
type: string
|
type: string
|
||||||
default: body
|
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:
|
plugin_screenshot_background:
|
||||||
description: |
|
description: |
|
||||||
Background
|
Background
|
||||||
|
|||||||
Reference in New Issue
Block a user