/*! For license information please see 2d0713c0.13a1b489.js.LICENSE.txt */ "use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[81952],{78609:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>c,default:()=>d,frontMatter:()=>o,metadata:()=>a,toc:()=>p});var s=t(85893),r=t(11151);const o={},c="Screenshots",a={id:"guides/screenshots",title:"Screenshots",description:"For capturing screenshots use Page.screenshot().",source:"@site/../docs/guides/screenshots.md",sourceDirName:"guides",slug:"/guides/screenshots",permalink:"/next/guides/screenshots",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{},sidebar:"docs",previous:{title:"Headless mode",permalink:"/next/guides/headless-modes"},next:{title:"PDF generation",permalink:"/next/guides/pdf-generation"}},i={},p=[];function l(e){const n={a:"a",code:"code",h1:"h1",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{id:"screenshots",children:"Screenshots"}),"\n",(0,s.jsxs)(n.p,{children:["For capturing screenshots use ",(0,s.jsx)(n.a,{href:"https://pptr.dev/api/puppeteer.screenshot.pdf",children:(0,s.jsx)(n.code,{children:"Page.screenshot()"})}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"const browser = await puppeteer.launch();\nconst page = await browser.newPage();\nawait page.goto('https://news.ycombinator.com', {\n waitUntil: 'networkidle2',\n});\nawait page.screenshot({\n path: 'hn.pdf',\n});\n\nawait browser.close();\n"})}),"\n",(0,s.jsxs)(n.p,{children:["You can also capture a screenshot of a specific element using ",(0,s.jsx)(n.a,{href:"https://pptr.dev/api/puppeteer.elementhandle.screenshot",children:(0,s.jsx)(n.code,{children:"ElementHandle.screenshot()"})}),":"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"const fileElement = await page.waitForSelector('div');\nawait fileElement.screenshot({\n path: 'div.png',\n});\n"})}),"\n",(0,s.jsxs)(n.p,{children:["By default, ",(0,s.jsx)(n.a,{href:"https://pptr.dev/api/puppeteer.elementhandle.screenshot",children:(0,s.jsx)(n.code,{children:"ElementHandle.screenshot()"})})," tries to scroll the element into view\nif it is hidden."]})]})}function d(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},75251:(e,n,t)=>{var s=t(67294),r=Symbol.for("react.element"),o=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,a=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function p(e,n,t){var s,o={},p=null,l=null;for(s in void 0!==t&&(p=""+t),void 0!==n.key&&(p=""+n.key),void 0!==n.ref&&(l=n.ref),n)c.call(n,s)&&!i.hasOwnProperty(s)&&(o[s]=n[s]);if(e&&e.defaultProps)for(s in n=e.defaultProps)void 0===o[s]&&(o[s]=n[s]);return{$$typeof:r,type:e,key:p,ref:l,props:o,_owner:a.current}}n.Fragment=o,n.jsx=p,n.jsxs=p},85893:(e,n,t)=>{e.exports=t(75251)},11151:(e,n,t)=>{t.d(n,{Z:()=>a,a:()=>c});var s=t(67294);const r={},o=s.createContext(r);function c(e){const n=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]);