sindresorhus/pageres

Support beforeScreenshot option

jopemachine opened this issue · 1 comments

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.

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.