Add comment scrolling in capture (#1079)

* feat: add comment scrolling in capture

* lint

* feat use .waitForSelectore method

* revert timeout
This commit is contained in:
Ben Allen 2024-04-16 20:25:56 -04:00 committed by GitHub
parent bc85a63091
commit 6a13c22ad2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions

View File

@ -59,6 +59,9 @@ app.get('/*', async (req, res) => {
const url = new URL(req.originalUrl, captureUrl)
const timeLabel = `${Date.now()}-${url.href}`
const urlParams = new URLSearchParams(url.search)
const commentId = urlParams.get('commentId')
let page, pages
try {
@ -87,6 +90,12 @@ app.get('/*', async (req, res) => {
await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: 'dark' }])
await page.goto(url.href, { waitUntil: 'load', timeout })
console.timeLog(timeLabel, 'page loaded')
if (commentId) {
console.timeLog(timeLabel, 'scrolling to comment')
await page.waitForSelector('.outline-it')
}
const file = await page.screenshot({ type: 'png', captureBeyondViewport: false })
console.timeLog(timeLabel, 'screenshot complete')
res.setHeader('Content-Type', 'image/png')