website/versioned_docs/version-3.10/examples/puppeteer_capture_screenshot.mdx
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import RunnableCodeBlock from '@site/src/components/RunnableCodeBlock'; import ApiLink from '@site/src/components/ApiLink';
import PuppeteerPageScreenshotSource from '!!raw-loader!roa-loader!./puppeteer_page_screenshot.ts'; import PuppeteerCrawlerUtilsSnapshotSource from '!!raw-loader!roa-loader!./puppeteer_crawler_utils_snapshot.ts'; import PuppeteerCrawlerPageScreenshotSource from '!!raw-loader!roa-loader!./puppeteer_crawler_page_screenshot.ts'; import PuppeteerCrawlerCrawlerUtilsSnapshotSource from '!!raw-loader!roa-loader!./puppeteer_crawler_crawler_utils_snapshot.ts';
:::tip
To run this example on the Apify Platform, select the apify/actor-node-puppeteer-chrome image for your Dockerfile.
:::
This example captures a screenshot of a web page using Puppeteer. It would look almost exactly the same with Playwright.
Using page.screenshot():
Using utils.puppeteer.saveSnapshot():
PuppeteerCrawlerThis example captures a screenshot of multiple web pages when using PuppeteerCrawler:
Using page.screenshot():
Using the context-aware <ApiLink to="puppeteer-crawler/namespace/puppeteerUtils#saveSnapshot">saveSnapshot()</ApiLink> utility:
In both examples using page.screenshot(), a key variable is created based on the URL of the web page. This variable is used as the key when saving
each screenshot into a key-value store.