Last active
October 27, 2023 15:06
-
-
Save crevulus/28203ee6fb5fa85657dd4160ff2ea5a5 to your computer and use it in GitHub Desktop.
A small script using puppeteer to get screenshots of multiple browser pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require("puppeteer"); | |
const pages = require("./webPages.json"); | |
async function takeMultipleScreenshots() { | |
try { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
for (const { id, name, url } of pages) { | |
await page.goto(url); | |
await page.screenshot({ path: `screenshot${id}.jpeg`, fullPage: true }); | |
console.log(`${name} - (${url})`); | |
} | |
} catch (err) { | |
console.log(`Error: ${err.message}`); | |
} | |
} | |
takeMultipleScreenshots(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "c1472465-ede8-4376-853c-39274242aa69", | |
"url": "https://github.com/microsoft/vscode", | |
"name": "VSCode" | |
}, | |
{ | |
"id": "6b08743e-9454-4829-ab3a-91ad2ce9a6ac", | |
"url": "https://github.com/vuejs/vue", | |
"name": "vue" | |
}, | |
{ | |
"id": "08923d12-caf2-4d5e-ba41-3019a9afbf9b", | |
"url": "https://github.com/tailwindlabs/tailwindcss", | |
"name": "tailwindcss" | |
}, | |
{ | |
"id": "daeacf42-1ab9-4329-8f41-26e7951b69cc", | |
"url": "https://github.com/getify/You-Dont-Know-JS", | |
"name": "You Dont Know JS" | |
} | |
] |
@Villegas-06 just add it after you await
taking the other screenshots:
for (const { id, name, url, url2 } of pages) {
await page.goto(url);
await page.screenshot({ path: `screenshot${id}.jpeg`, fullPage: true });
await page.goto(url2);
await page.screenshot({ path: `screenshot${id}-2.jpeg`, fullPage: true });
console.log(`${name} - (${url} & ${url2})`);
}
Bear in mind it's best to include a full URL with protocol, subdomain, etc.
Ook, thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a question, if I want browse one url more in array
({
"id": "6b08743e-9454-4829-ab3a-91ad2ce9a6ac",
"url2": "example.com",
"url": "https://github.com/vuejs/vue",
"name": "vue"
},).
¿How?