fix: improve app reports puppeteer interactions

This commit is contained in:
Ruben Fiszel
2024-09-05 10:07:21 +02:00
parent db00641281
commit fa2f5e1b3f
2 changed files with 20 additions and 6 deletions
+3 -1
View File
@@ -88,7 +88,7 @@ services:
condition: service_healthy
volumes:
- worker_logs:/tmp/windmill/logs
## This worker is specialized for reports or scraping jobs. It is assigned the "reports" worker group which has an init script that installs chromium and can be targeted by using the "chromium" worker tag.
# This worker is specialized for reports or scraping jobs. It is assigned the "reports" worker group which has an init script that installs chromium and can be targeted by using the "chromium" worker tag.
# windmill_worker_reports:
# image: ${WM_IMAGE}
# pull_policy: always
@@ -111,6 +111,7 @@ services:
# # mount the docker socket to allow to run docker containers from within the workers
# - /var/run/docker.sock:/var/run/docker.sock
# - worker_dependency_cache:/tmp/windmill/cache
# - worker_logs:/tmp/windmill/logs
# The indexer powers full-text job and log search, an EE feature.
windmill_indexer:
@@ -136,6 +137,7 @@ services:
condition: service_healthy
volumes:
- windmill_index:/tmp/windmill/search
- worker_logs:/tmp/windmill/logs
lsp:
image: ghcr.io/windmill-labs/windmill-lsp:latest
@@ -146,19 +146,25 @@
const appPreviewScript = `import puppeteer from 'puppeteer-core';
import dayjs from 'dayjs';
export async function main(app_path: string, startup_duration = 5, kind: 'pdf' | 'png' = 'pdf') {
const browser = await puppeteer.launch({ headless: 'new', executablePath: '/usr/bin/chromium', args: ['--no-sandbox'] });
let browser = null
try {
browser = await puppeteer.launch({ headless: true, executablePath: '/usr/bin/chromium', args: ['--no-sandbox',
'--no-zygote',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu'] });
const page = await browser.newPage();
await page.setCookie({
"name": "token",
"value": Bun.env["WM_TOKEN"],
"domain": Bun.env["WM_BASE_URL"]?.replace(/https?:\\/\\//, '')
"domain": Bun.env["BASE_URL"]?.replace(/https?:\\/\\//, '')
})
page
.on('console', msg =>
console.log(dayjs().format("HH:mm:ss") + " " + msg.type().substr(0, 3).toUpperCase() + " " + msg.text()))
.on('pageerror', ({ msg }) => console.log(dayjs().format("HH:mm:ss") + " " + msg));
await page.setViewport({ width: 1200, height: 2000 });
await page.goto(Bun.env["WM_BASE_URL"] + '/apps/get/' + app_path + '?workspace=' + Bun.env["WM_WORKSPACE"] + "&hideRefreshBar=true&hideEditBtn=true");
await page.goto(Bun.env["BASE_URL"] + '/apps/get/' + app_path + '?workspace=' + Bun.env["WM_WORKSPACE"] + "&hideRefreshBar=true&hideEditBtn=true");
await page.waitForSelector("#app-content", { timeout: 20000 })
await new Promise((resolve, _) => {
setTimeout(resolve, startup_duration * 1000)
@@ -182,8 +188,14 @@ export async function main(app_path: string, startup_duration = 5, kind: 'pdf' |
type: "png",
captureBeyondViewport: false
});
await browser.close();
return Buffer.from(screenshot).toString('base64');
await browser.close();
return Buffer.from(screenshot).toString('base64');
} catch (err) {
if (browser) {
await browser.close();
}
throw err;
}
}`
const notificationScripts = {