sindresorhus / pageres

Capture website screenshots
MIT License
9.68k stars 744 forks source link

Support beforeScreenshot option #424

Closed jopemachine closed 2 years ago

jopemachine commented 2 years ago

It seems like capture-website's some options including beforeScreenshot is missing from the finalOptions.

I think supporting beforeScreenshot option could be useful when the website stores access token in the localstorage. (or other situations) like below way.

Do you have any plans to add capture-website's other options including beforeScreenshot?


// Ref : https://stackoverflow.com/questions/51789038/set-localstorage-items-before-page-loads-in-puppeteer
const setLocalStorageToken = (page) => {
  await page.evaluate(() => {
    localStorage.setItem('token', 'example-token');
  });

  // user token set successfully.
  await page.goto('http://localhost:8080/');
};

(async () => {
  await new Pageres({
    delay: 2,
    beforeScreenShot: (page) => {
      setLocalStorageToken(page);
    }
  })
    .src('http://localhost:8080/')
    .dest(__dirname)
    .run();

  console.log('Finished generating screenshots!');
})();

I appreciate all your efforts in creating and maintaining these awesome libraries.

sindresorhus commented 2 years ago

It's not something I plan to work on, but a good pull request would be welcomed. Should be easy enough to copy-paste the docs from capture-website.