|
|
|
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[42639],{26959:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>a,default:()=>d,frontMatter:()=>o,metadata:()=>c,toc:()=>p});var s=t(85893),r=t(11151);const o={},a="Screenshots",c={id:"guides/screenshots",title:"Screenshots",description:"For capturing screenshots use Page.screenshot().",source:"@site/versioned_docs/version-22.8.2/guides/screenshots.md",sourceDirName:"guides",slug:"/guides/screenshots",permalink:"/guides/screenshots",draft:!1,unlisted:!1,tags:[],version:"22.8.2",frontMatter:{},sidebar:"docs",previous:{title:"Headless mode",permalink:"/guides/headless-modes"},next:{title:"PDF generation",permalink:"/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"),a=Object.prototype.hasOwnProperty,c=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)a.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:c.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:()=>c,a:()=>a});var s=t(67294);const r={},o=s.createContext(r);function a(e){const n=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]);
|