Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
Puppeteer Question: I'm Screenshotting A Series of Pages. Can I Use Each Page URL as the Image Name?

I have a problem with a Puppeteer script I'm writing. I've gotten it to do 90% of what it needs to do, which is use the sitemap page for any given site and go to each page before taking a full-page screenshot. It also spits out a console.log of a massive array with all of the site URLs. What I need to do and can't get right is to pull the page URL for each page it opens during its for loop and use that as the name for the screenshot. So like if it goes to google.com, picture 1 is called "google.com/.png", then "google.com/dogpictures.png" etc.

I'm including it below, I'd love to hear any feedback:

const puppeteer = require("puppeteer");

(async () => {
    'use strict'
 
    const smta = require('sitemap-to-array')
    const options = { returnOnComplete: true}
    const sitemapUrl = 'https:____.org/page-sitemap.xml'
     
    smta(sitemapUrl, options, (error, list) => {
      if (error) {
        console.error(error)
      } else {     

        console.log(list)
        useSitemapWithPuppeteer(list);
      }
    })

  const useSitemapWithPuppeteer = async (array) => {  

  const urls = array.map(obj => obj.loc);
  
  const browser = await puppeteer.launch({
    headless: false,
    defaultViewport: null,
  });
  
  for (let i = 0; i < urls.length; i++) {  
    const url = urls[i];
    const page = await browser.newPage();
    page.setDefaultNavigationTimeout(0);
    await page.goto(`${url}`, { waitUntil: "networkidle2" });
    const currentURL = page.url;
    await page.screenshot({ path: "test" + i + ".png", fullPage: true });
    
  }
  await browser.close();
  
}})();
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!