capture.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const { chromium } = require('playwright');
  2. const fs = require('fs');
  3. const URLS = [
  4. "http://localhost:5287",
  5. "http://localhost:5287/visualise/topology",
  6. "http://localhost:5287/visualise/logical",
  7. "http://localhost:5287/cli",
  8. "http://localhost:5287/yaml",
  9. "http://localhost:5287/hardware/tree",
  10. "http://localhost:5287/servers/list",
  11. "http://localhost:5287/resources/hardware/proxmox-node01",
  12. "http://localhost:5287/systems/list",
  13. "http://localhost:5287/services/list"
  14. ];
  15. (async () => {
  16. const browser = await chromium.launch();
  17. const page = await browser.newPage({
  18. viewport: { width: 1366, height: 768 }
  19. });
  20. if (!fs.existsSync("./webui_screenshots"))
  21. fs.mkdirSync("./webui_screenshots");
  22. for (const url of URLS) {
  23. const filename = url.replace(/^https?:\/\//, '').replace(/\//g, '_') + ".png";
  24. console.log("Capturing", url);
  25. // Diagram routes are taller than the standard viewport; stretch it so
  26. // the GraphView's `h-full` container shows the whole diagram in-frame.
  27. const isVisualise = url.includes("/visualise/");
  28. if (isVisualise) {
  29. await page.setViewportSize({ width: 2400, height: 5000 });
  30. } else {
  31. await page.setViewportSize({ width: 1366, height: 768 });
  32. }
  33. await page.goto(url, {
  34. waitUntil: "networkidle",
  35. timeout: 30000
  36. });
  37. // extra settle time for SPA hydration; Mermaid renders async so the
  38. // visualise routes need a longer window before screenshotting.
  39. await page.waitForTimeout(isVisualise ? 5000 : 2000);
  40. // The visualise route wraps the diagram in an overflow:auto container
  41. // bounded to 75vh — fine for the live UI, but it clips taller diagrams
  42. // in screenshots. For the capture only, expand any ancestor of the SVG
  43. // to its natural height and disable overflow clipping.
  44. if (isVisualise) {
  45. await page.evaluate(() => {
  46. const svg = document.querySelector("[id^='visualise-graph-host'] svg, #visualise-graph-host svg");
  47. if (!svg) return;
  48. let el = svg.parentElement;
  49. while (el && el !== document.body) {
  50. el.style.height = "auto";
  51. el.style.maxHeight = "none";
  52. el.style.overflow = "visible";
  53. el = el.parentElement;
  54. }
  55. });
  56. await page.waitForTimeout(500);
  57. }
  58. await page.screenshot({
  59. path: `webui_screenshots/${filename}`,
  60. fullPage: isVisualise
  61. });
  62. }
  63. await browser.close();
  64. })();