forked from DreamLab-AI/origin-logseq-AR
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtake-screenshot.js
More file actions
88 lines (71 loc) · 2.52 KB
/
take-screenshot.js
File metadata and controls
88 lines (71 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
/**
* Playwright Screenshot Script
* Takes screenshots of the VisionFlow website via HTTPS bridge
* Uses system Chromium instead of Playwright's bundled browser
*/
const { chromium } = require('playwright');
const path = require('path');
const SCREENSHOT_DIR = process.env.SCREENSHOT_DIR || '/home/devuser/workspace/project/screenshots';
const URL = process.env.TARGET_URL || 'https://localhost:3001';
async function takeScreenshots() {
console.log('Launching system Chromium browser...');
const browser = await chromium.launch({
executablePath: '/usr/bin/chromium', // Use system chromium
headless: false, // Use headed mode for VNC display
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--ignore-certificate-errors', // Accept self-signed cert
'--disable-web-security',
'--disable-gpu' // For Xvfb compatibility
]
});
const context = await browser.newContext({
ignoreHTTPSErrors: true,
viewport: { width: 1920, height: 1080 }
});
const page = await context.newPage();
console.log(`Navigating to ${URL}...`);
try {
await page.goto(URL, {
waitUntil: 'networkidle',
timeout: 30000
});
console.log('Page loaded successfully');
// Take full page screenshot
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const fullPagePath = path.join(SCREENSHOT_DIR, `visionflow-fullpage-${timestamp}.png`);
await page.screenshot({
path: fullPagePath,
fullPage: true
});
console.log(`Full page screenshot saved: ${fullPagePath}`);
// Take viewport screenshot
const viewportPath = path.join(SCREENSHOT_DIR, `visionflow-viewport-${timestamp}.png`);
await page.screenshot({
path: viewportPath,
fullPage: false
});
console.log(`Viewport screenshot saved: ${viewportPath}`);
// Get page title
const title = await page.title();
console.log(`Page title: ${title}`);
// Wait a bit to see it on VNC
await page.waitForTimeout(3000);
} catch (error) {
console.error('Error:', error.message);
// Take error screenshot anyway
const errorPath = path.join(SCREENSHOT_DIR, `error-screenshot-${Date.now()}.png`);
try {
await page.screenshot({ path: errorPath });
console.log(`Error screenshot saved: ${errorPath}`);
} catch (e) {
console.error('Could not take error screenshot');
}
}
await browser.close();
console.log('Browser closed');
}
takeScreenshots().catch(console.error);