Skip to content
← Back to Community
Taking screenshots with Puppeteer
Profile icon
Seven7Four4

It is actually very easy to take screenshots with Puppeteer!

To do this, instead of making a NodeJS repl, make a Bash repl.

Then click on the Shell tab (on top of console), and type this in:

npm init -y

This will set your package.json file, which is recommended.

Then put this into the main.sh file:

npm install puppeteer --save && node index.js

Then, make a new file called index.js. In there, you will put a script that takes a screenshot.

Example:

const puppeteer = require('puppeteer'); // Your URL here var url='https://replit.com/@Seven7Four4'; (async () => { const browser = await puppeteer.launch({ headless: false, args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const page = await browser.newPage(); await page.goto(url); console.log(await page.content()); await page.screenshot({path: 'screenshot.png'}); })();

And finally, make a file called screenshot.png, and after the site loads, you have a screenshot of your site! Check screenshot.png to see it.

Voters
Profile icon
MiserableCuckoo
Profile icon
Seven7Four4