Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary fix for #4 #9

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions scripts/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,43 @@
During initial setup, run bun run puppeteer browsers install chrome, and copy the executable path to line 8
*/
const puppeteer = require('puppeteer');
const fs = require('fs');

(async () => {
const browser = await puppeteer.launch({executablePath: '/home/vishalds/.cache/puppeteer/chrome/linux-126.0.6478.182/chrome-linux64/chrome'});
const page = await browser.newPage();
await page.goto('file://' + process.argv[2]);
try {
const browser = await puppeteer.launch({
executablePath: '/home/vishalds/.cache/puppeteer/chrome/linux-126.0.6478.182/chrome-linux64/chrome',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});

// Mobile screenshot
await page.setViewport({ width: 412, height: 915 });
await page.screenshot({ path: process.argv[3] });
const page = await browser.newPage();
await page.setRequestInterception(true);

// Desktop screenshot
await page.setViewport({ width: 1280, height: 800 });
await page.screenshot({ path: process.argv[4] });
// Intercept requests to our own API & block them
// this is a temporary fix, has to be mitigated completely asap
page.on('request', (request) => {
if (request.url().includes('api.zitefy.com')) {
request.abort();
} else {
request.continue();
}
});

await browser.close();
await page.goto('file://' + process.argv[2], {
waitUntil: 'networkidle0',
timeout: 60000
});

await page.setViewport({ width: 412, height: 915 });
await page.screenshot({ path: process.argv[3] });

await page.setViewport({ width: 1280, height: 800 });
await page.screenshot({ path: process.argv[4] });

await browser.close();

} catch (error) {
fs.writeFileSync('screenshot_error.log', error.toString());
process.exit(1);
}
})();
Loading