From 7fa3b34b08547bcb40677356573e1f443042b7cb Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 29 Nov 2023 17:48:28 +0100 Subject: [PATCH] screenshot with pupeteer --- helpers/screenshot.mjs | 37 ++++++++++++++++++++++++++++++++++++ helpers/screenshots/.gitkeep | 0 2 files changed, 37 insertions(+) create mode 100644 helpers/screenshot.mjs create mode 100644 helpers/screenshots/.gitkeep diff --git a/helpers/screenshot.mjs b/helpers/screenshot.mjs new file mode 100644 index 0000000..0d654f7 --- /dev/null +++ b/helpers/screenshot.mjs @@ -0,0 +1,37 @@ +/** + * prendre un screenshot avec puppeteer + */ + +import fs from "fs"; + +import puppeteer from "puppeteer"; + +let url = "https://www.cipherbliss.com" + +async function captureScreenshot() { + const targetUrl = url; + const screenshotPath = "screenshots/github-profile.jpeg"; + + try { + // Launch headless Chromium browser + const browser = await puppeteer.launch({ headless: true }); + + // Create a new page + const page = await browser.newPage(); + + // Set viewport width and height + await page.setViewport({ width: 1440, height: 1080 }); + + // Navigate to the target URL + await page.goto(targetUrl); + + // Capture screenshot and save it + await page.screenshot({ path: screenshotPath }); + await browser.close(); + console.log("\nšŸŽ‰ GitHub profile screenshot captured successfully."); + } catch (err) { + console.log("āŒ Error: ", err.message); + } +} + +captureScreenshot(); diff --git a/helpers/screenshots/.gitkeep b/helpers/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29