capture.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { chromium } = require('playwright');
  2. const fs = require('fs');
  3. const URLS = [
  4. "http://localhost:5287",
  5. "http://localhost:5287/cli",
  6. "http://localhost:5287/yaml",
  7. "http://localhost:5287/hardware/tree",
  8. "http://localhost:5287/servers/list",
  9. "http://localhost:5287/resources/hardware/proxmox-node01",
  10. "http://localhost:5287/systems/list",
  11. "http://localhost:5287/services/list"
  12. ];
  13. (async () => {
  14. const browser = await chromium.launch();
  15. const page = await browser.newPage({
  16. viewport: { width: 1366, height: 768 }
  17. });
  18. if (!fs.existsSync("./webui_screenshots"))
  19. fs.mkdirSync("./webui_screenshots");
  20. for (const url of URLS) {
  21. const filename = url.replace(/^https?:\/\//, '').replace(/\//g, '_') + ".png";
  22. console.log("Capturing", url);
  23. await page.goto(url, {
  24. waitUntil: "networkidle",
  25. timeout: 30000
  26. });
  27. // extra settle time for SPA hydration
  28. await page.waitForTimeout(2000);
  29. await page.screenshot({
  30. path: `webui_screenshots/${filename}`,
  31. fullPage: false
  32. });
  33. }
  34. await browser.close();
  35. })();