Skip to content

Commit

Permalink
create capture-screenshot.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dinxsh authored Aug 1, 2024
1 parent c700cd2 commit 9b93b37
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions capture-screenshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');

async function takeScreenshot(username) {
const url = `https://github.com/${username}`;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);

await page.setViewport({ width: 1280, height: 800 });
const screenshotPath = path.join('screenshots', `${username}.png`);
await page.screenshot({ path: screenshotPath, fullPage: true });

await browser.close();
return screenshotPath;
}

async function main() {
const username = process.argv[2];
if (!username) {
console.error('No username provided');
process.exit(1);
}

if (!fs.existsSync('screenshots')) {
fs.mkdirSync('screenshots');
}

const screenshotPath = await takeScreenshot(username);
console.log(`Screenshot taken for ${username}: ${screenshotPath}`);
}

main();

0 comments on commit 9b93b37

Please sign in to comment.