Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins/community/screenshot): add plugin_screenshot_viewport and plugin_screenshot_wait #1288

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions source/plugins/community/screenshot/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}

Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions source/plugins/community/screenshot/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down