"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[12199],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>k});var n=a(67294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function p(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var p=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=n.createContext({}),d=function(e){var t=n.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},u=function(e){var t=d(e.components);return n.createElement(o.Provider,{value:t},e.children)},m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},s=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,p=e.originalType,o=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),s=d(a),k=r,g=s["".concat(o,".").concat(k)]||s[k]||m[k]||p;return a?n.createElement(g,l(l({ref:t},u),{},{components:a})):n.createElement(g,l({ref:t},u))}));function k(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var p=a.length,l=new Array(p);l[0]=s;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i.mdxType="string"==typeof e?e:r,l[1]=i;for(var d=2;d{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>s,frontMatter:()=>l,metadata:()=>o,toc:()=>u});a(67294);var n=a(3905);function r(){return r=Object.assign||function(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var p=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}const l={sidebar_label:"Page"},i="Page class",o={unversionedId:"api/puppeteer.page",id:"version-19.4.1/api/puppeteer.page",title:"Page class",description:"Page provides methods to interact with a single tab or extension background page in Chromium.",source:"@site/versioned_docs/version-19.4.1/api/puppeteer.page.md",sourceDirName:"api",slug:"/api/puppeteer.page",permalink:"/api/puppeteer.page",draft:!1,tags:[],version:"19.4.1",frontMatter:{sidebar_label:"Page"},sidebar:"api",previous:{title:"BrowserContext.waitForTarget",permalink:"/api/puppeteer.browsercontext.waitfortarget"},next:{title:"Page.$",permalink:"/api/puppeteer.page._"}},d={},u=[{value:"Signature:",id:"signature",level:4},{value:"Remarks",id:"remarks",level:2},{value:"Example 1",id:"example-1",level:2},{value:"Example 2",id:"example-2",level:2},{value:"Properties",id:"properties",level:2},{value:"Methods",id:"methods",level:2}],m={toc:u};function s(e){var{components:t}=e,a=p(e,["components"]);return(0,n.kt)("wrapper",r({},m,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("h1",r({},{id:"page-class"}),"Page class"),(0,n.kt)("p",null,"Page provides methods to interact with a single tab or ",(0,n.kt)("a",r({parentName:"p"},{href:"https://developer.chrome.com/extensions/background_pages"}),"extension background page")," in Chromium."),(0,n.kt)("admonition",r({},{type:"note"}),(0,n.kt)("p",{parentName:"admonition"},"One Browser instance might have multiple Page instances.")),(0,n.kt)("h4",r({},{id:"signature"}),"Signature:"),(0,n.kt)("pre",null,(0,n.kt)("code",r({parentName:"pre"},{className:"language-typescript"}),"export declare class Page extends EventEmitter\n")),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Extends:")," ",(0,n.kt)("a",r({parentName:"p"},{href:"/api/puppeteer.eventemitter"}),"EventEmitter")),(0,n.kt)("h2",r({},{id:"remarks"}),"Remarks"),(0,n.kt)("p",null,"The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,n.kt)("inlineCode",{parentName:"p"},"Page")," class."),(0,n.kt)("h2",r({},{id:"example-1"}),"Example 1"),(0,n.kt)("p",null,"This example creates a page, navigates it to a URL, and then saves a screenshot:"),(0,n.kt)("pre",null,(0,n.kt)("code",r({parentName:"pre"},{className:"language-ts"}),"import puppeteer from 'puppeteer';\n\n(async () => {\n const browser = await puppeteer.launch();\n const page = await browser.newPage();\n await page.goto('https://example.com');\n await page.screenshot({path: 'screenshot.png'});\n await browser.close();\n})();\n")),(0,n.kt)("p",null,"The Page class extends from Puppeteer's ",(0,n.kt)("a",r({parentName:"p"},{href:"/api/puppeteer.eventemitter"}),"EventEmitter")," class and will emit various events which are documented in the ",(0,n.kt)("a",r({parentName:"p"},{href:"/api/puppeteer.pageemittedevents"}),"PageEmittedEvents")," enum."),(0,n.kt)("h2",r({},{id:"example-2"}),"Example 2"),(0,n.kt)("p",null,"This example logs a message for a single page ",(0,n.kt)("inlineCode",{parentName:"p"},"load")," event:"),(0,n.kt)("pre",null,(0,n.kt)("code",r({parentName:"pre"},{className:"language-ts"}),"page.once('load', () => console.log('Page loaded!'));\n")),(0,n.kt)("p",null,"To unsubscribe from events use the ",(0,n.kt)("a",r({parentName:"p"},{href:"/api/puppeteer.page.off"}),"Page.off()")," method:"),(0,n.kt)("pre",null,(0,n.kt)("code",r({parentName:"pre"},{className:"language-ts"}),"function logRequest(interceptedRequest) {\n console.log('A request was made:', interceptedRequest.url());\n}\npage.on('request', logRequest);\n// Sometime later...\npage.off('request', logRequest);\n")),(0,n.kt)("h2",r({},{id:"properties"}),"Properties"),(0,n.kt)("table",null,(0,n.kt)("thead",{parentName:"table"},(0,n.kt)("tr",{parentName:"thead"},(0,n.kt)("th",r({parentName:"tr"},{align:null}),"Property"),(0,n.kt)("th",r({parentName:"tr"},{align:null}),"Modifiers"),(0,n.kt)("th",r({parentName:"tr"},{align:null}),"Type"),(0,n.kt)("th",r({parentName:"tr"},{align:null}),"Description"))),(0,n.kt)("tbody",{parentName:"table"},(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.accessibility"}),"accessibility")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("code",null,"readonly")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.accessibility"}),"Accessibility")),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.coverage"}),"coverage")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("code",null,"readonly")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.coverage"}),"Coverage")),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.keyboard"}),"keyboard")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("code",null,"readonly")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.keyboard"}),"Keyboard")),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.mouse"}),"mouse")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("code",null,"readonly")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.mouse"}),"Mouse")),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.touchscreen"}),"touchscreen")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("code",null,"readonly")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.touchscreen"}),"Touchscreen")),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.tracing"}),"tracing")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("code",null,"readonly")),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.tracing"}),"Tracing")),(0,n.kt)("td",r({parentName:"tr"},{align:null}))))),(0,n.kt)("h2",r({},{id:"methods"}),"Methods"),(0,n.kt)("table",null,(0,n.kt)("thead",{parentName:"table"},(0,n.kt)("tr",{parentName:"thead"},(0,n.kt)("th",r({parentName:"tr"},{align:null}),"Method"),(0,n.kt)("th",r({parentName:"tr"},{align:null}),"Modifiers"),(0,n.kt)("th",r({parentName:"tr"},{align:null}),"Description"))),(0,n.kt)("tbody",{parentName:"table"},(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page._"}),"$(selector)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Runs ",(0,n.kt)("code",null,"document.querySelector")," within the page. If no element matches the selector, the return value resolves to ",(0,n.kt)("code",null,"null"),".")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.__"}),"$$(selector)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"The method runs ",(0,n.kt)("code",null,"document.querySelectorAll")," within the page. If no elements match the selector, the return value resolves to ",(0,n.kt)("code",null,"[]"),".")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.__eval"}),"$$eval(selector, pageFunction, args)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method runs ",(0,n.kt)("code",null,"Array.from(document.querySelectorAll(selector))")," within the page and passes the result as the first argument to the ",(0,n.kt)("code",null,"pageFunction"),".")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page._eval"}),"$eval(selector, pageFunction, args)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method runs ",(0,n.kt)("code",null,"document.querySelector")," within the page and passes the result as the first argument to the ",(0,n.kt)("code",null,"pageFunction"),".")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page._x"}),"$x(expression)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"The method evaluates the XPath expression relative to the page document as its context node. If there are no such elements, the method resolves to an empty array.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.addscripttag"}),"addScriptTag(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Adds a ",(0,n.kt)("code",null,"<","script",">")," tag into the page with the desired URL or content.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.addstyletag"}),"addStyleTag(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Adds a ",(0,n.kt)("code",null,"<","link rel=",'"',"stylesheet",'"',">")," tag into the page with the desired URL or a ",(0,n.kt)("code",null,"<","style type=",'"',"text/css",'"',">")," tag with the content."),(0,n.kt)("p",null,"Shortcut for ."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.addstyletag_1"}),"addStyleTag(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.addstyletag_2"}),"addStyleTag(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.authenticate"}),"authenticate(credentials)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Provide credentials for ",(0,n.kt)("code",null,"HTTP authentication"),".")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.bringtofront"}),"bringToFront()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Brings page to front (activates tab).")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.browser"}),"browser()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Get the browser the page belongs to.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.browsercontext"}),"browserContext()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Get the browser context that the page belongs to.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.click"}),"click(selector, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method fetches an element with ",(0,n.kt)("code",null,"selector"),", scrolls it into view if needed, and then uses ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.mouse"}),"Page.mouse")," to click in the center of the element. If there's no element matching ",(0,n.kt)("code",null,"selector"),", the method throws an error.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.close"}),"close(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.content"}),"content()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.cookies"}),"cookies(urls)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"If no URLs are specified, this method returns cookies for the current page URL. If URLs are specified, only cookies for those URLs are returned.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.createpdfstream"}),"createPDFStream(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Generates a PDF of the page with the ",(0,n.kt)("code",null,"print")," CSS media type.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.deletecookie"}),"deleteCookie(cookies)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulate"}),"emulate(device)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Emulates a given device's metrics and user agent."),(0,n.kt)("p",null,"To aid emulation, Puppeteer provides a list of known devices that can be via ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.knowndevices"}),"KnownDevices"),"."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulatecputhrottling"}),"emulateCPUThrottling(factor)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Enables CPU throttling to emulate slow CPUs.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulateidlestate"}),"emulateIdleState(overrides)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Emulates the idle state. If no arguments set, clears idle state emulation.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulatemediafeatures"}),"emulateMediaFeatures(features)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulatemediatype"}),"emulateMediaType(type)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulatenetworkconditions"}),"emulateNetworkConditions(networkConditions)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"This does not affect WebSockets and WebRTC PeerConnections (see ",(0,n.kt)("a",r({parentName:"td"},{href:"https://crbug.com/563644"}),"https://crbug.com/563644"),"). To set the page offline, you can use ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setofflinemode"}),"Page.setOfflineMode()"),"."),(0,n.kt)("p",null,"A list of predefined network conditions can be used by importing ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.predefinednetworkconditions"}),"PredefinedNetworkConditions"),"."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulatetimezone"}),"emulateTimezone(timezoneId)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulatevisiondeficiency"}),"emulateVisionDeficiency(type)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Simulates the given vision deficiency on the page.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.evaluate"}),"evaluate(pageFunction, args)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Evaluates a function in the page's context and returns the result."),(0,n.kt)("p",null,"If the function passed to ",(0,n.kt)("code",null,"page.evaluateHandle")," returns a Promise, the function will wait for the promise to resolve and return its value."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.evaluatehandle"}),"evaluateHandle(pageFunction, args)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.evaluateonnewdocument"}),"evaluateOnNewDocument(pageFunction, args)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Adds a function which would be invoked in one of the following scenarios:"),(0,n.kt)("p",null,"- whenever the page is navigated"),(0,n.kt)("p",null,"- whenever the child frame is attached or navigated. In this case, the function is invoked in the context of the newly attached frame."),(0,n.kt)("p",null,"The function is invoked after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed ",(0,n.kt)("code",null,"Math.random"),"."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.exposefunction"}),"exposeFunction(name, pptrFunction)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"The method adds a function called ",(0,n.kt)("code",null,"name")," on the page's ",(0,n.kt)("code",null,"window")," object. When called, the function executes ",(0,n.kt)("code",null,"puppeteerFunction")," in node.js and returns a ",(0,n.kt)("code",null,"Promise")," which resolves to the return value of ",(0,n.kt)("code",null,"puppeteerFunction"),"."),(0,n.kt)("p",null,"If the puppeteerFunction returns a ",(0,n.kt)("code",null,"Promise"),", it will be awaited."),(0,n.kt)("p",null,":::note"),(0,n.kt)("p",null,"Functions installed via ",(0,n.kt)("code",null,"page.exposeFunction")," survive navigations."),(0,n.kt)("p",null,":::note"))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.focus"}),"focus(selector)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method fetches an element with ",(0,n.kt)("code",null,"selector")," and focuses it. If there's no element matching ",(0,n.kt)("code",null,"selector"),", the method throws an error.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.frames"}),"frames()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.getdefaulttimeout"}),"getDefaultTimeout()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.goback"}),"goBack(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method navigate to the previous page in history.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.goforward"}),"goForward(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method navigate to the next page in history.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.goto"}),"goto(url, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.hover"}),"hover(selector)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method fetches an element with ",(0,n.kt)("code",null,"selector"),", scrolls it into view if needed, and then uses ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.mouse"}),"Page.mouse")," to hover over the center of the element. If there's no element matching ",(0,n.kt)("code",null,"selector"),", the method throws an error.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.isclosed"}),"isClosed()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Indicates that the page has been closed.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.isdraginterceptionenabled"}),"isDragInterceptionEnabled()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.isjavascriptenabled"}),"isJavaScriptEnabled()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.mainframe"}),"mainFrame()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.metrics"}),"metrics()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.off"}),"off(eventName, handler)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.on"}),"on(eventName, handler)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Listen to page events."),(0,n.kt)("p",null,":::note"),(0,n.kt)("p",null,"This method exists to define event typings and handle proper wireup of cooperative request interception. Actual event listening and dispatching is delegated to ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.eventemitter"}),"EventEmitter"),"."),(0,n.kt)("p",null,":::"))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.once"}),"once(eventName, handler)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.pdf"}),"pdf(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.queryobjects"}),"queryObjects(prototypeHandle)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method iterates the JavaScript heap and finds all objects with the given prototype.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.reload"}),"reload(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.screenshot"}),"screenshot(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.select"}),"select(selector, values)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Triggers a ",(0,n.kt)("code",null,"change")," and ",(0,n.kt)("code",null,"input")," event once all the provided options have been selected. If there's no ",(0,n.kt)("code",null,"<","select",">")," element matching ",(0,n.kt)("code",null,"selector"),", the method throws an error.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setbypasscsp"}),"setBypassCSP(enabled)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Toggles bypassing page's Content-Security-Policy.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setcacheenabled"}),"setCacheEnabled(enabled)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setcontent"}),"setContent(html, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setcookie"}),"setCookie(cookies)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setdefaultnavigationtimeout"}),"setDefaultNavigationTimeout(timeout)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"This setting will change the default maximum navigation time for the following methods and related shortcuts:"),(0,n.kt)("p",null,"- ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.goback"}),"page.goBack(options)")),(0,n.kt)("p",null,"- ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.goforward"}),"page.goForward(options)")),(0,n.kt)("p",null,"- ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.goto"}),"page.goto(url,options)")),(0,n.kt)("p",null,"- ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.reload"}),"page.reload(options)")),(0,n.kt)("p",null,"- ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setcontent"}),"page.setContent(html,options)")),(0,n.kt)("p",null,"- ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitfornavigation"}),"page.waitForNavigation(options)")))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setdefaulttimeout"}),"setDefaultTimeout(timeout)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setdraginterception"}),"setDragInterception(enabled)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setextrahttpheaders"}),"setExtraHTTPHeaders(headers)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"The extra HTTP headers will be sent with every request the page initiates."),(0,n.kt)("p",null,":::tip"),(0,n.kt)("p",null,"All HTTP header names are lowercased. (HTTP headers are case-insensitive, so this shouldn\u2019t impact your server code.)"),(0,n.kt)("p",null,":::"),(0,n.kt)("p",null,":::note"),(0,n.kt)("p",null,"page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests."),(0,n.kt)("p",null,":::"))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setgeolocation"}),"setGeolocation(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Sets the page's geolocation.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setjavascriptenabled"}),"setJavaScriptEnabled(enabled)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setofflinemode"}),"setOfflineMode(enabled)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Sets the network connection to offline."),(0,n.kt)("p",null,"It does not change the parameters used in ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.emulatenetworkconditions"}),"Page.emulateNetworkConditions()")))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setrequestinterception"}),"setRequestInterception(value)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Activating request interception enables ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.httprequest.abort"}),"HTTPRequest.abort()"),", ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.httprequest.continue"}),"HTTPRequest.continue()")," and ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.httprequest.respond"}),"HTTPRequest.respond()")," methods. This provides the capability to modify network requests that are made by a page."),(0,n.kt)("p",null,"Once request interception is enabled, every request will stall unless it's continued, responded or aborted; or completed using the browser cache."),(0,n.kt)("p",null,"See the ",(0,n.kt)("a",r({parentName:"td"},{href:"https://pptr.dev/next/guides/request-interception"}),"Request interception guide")," for more details."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setuseragent"}),"setUserAgent(userAgent, userAgentMetadata)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.setviewport"}),"setViewport(viewport)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,(0,n.kt)("code",null,"page.setViewport")," will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport before navigating to the page."),(0,n.kt)("p",null,"In the case of multiple pages in a single browser, each page can have its own viewport size."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.tap"}),"tap(selector)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"This method fetches an element with ",(0,n.kt)("code",null,"selector"),", scrolls it into view if needed, and then uses ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.touchscreen"}),"Page.touchscreen")," to tap in the center of the element. If there's no element matching ",(0,n.kt)("code",null,"selector"),", the method throws an error.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.target"}),"target()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.title"}),"title()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.type"}),"type(selector, text, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Sends a ",(0,n.kt)("code",null,"keydown"),", ",(0,n.kt)("code",null,"keypress/input"),", and ",(0,n.kt)("code",null,"keyup")," event for each character in the text."),(0,n.kt)("p",null,"To press a special key, like ",(0,n.kt)("code",null,"Control")," or ",(0,n.kt)("code",null,"ArrowDown"),", use ",(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.keyboard.press"}),"Keyboard.press()"),"."))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.url"}),"url()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.viewport"}),"viewport()")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitforfilechooser"}),"waitForFileChooser(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"This method is typically coupled with an action that triggers file choosing."),(0,n.kt)("p",null,":::caution"),(0,n.kt)("p",null,"This must be called before the file chooser is launched. It will not return a currently active file chooser."),(0,n.kt)("p",null,":::"))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitforframe"}),"waitForFrame(urlOrPredicate, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitforfunction"}),"waitForFunction(pageFunction, options, args)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Waits for a function to finish evaluating in the page's context.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitfornavigation"}),"waitForNavigation(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),"Waits for the page to navigate to a new URL or to reload. It is useful when you run code that will indirectly cause the page to navigate.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitfornetworkidle"}),"waitForNetworkIdle(options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitforrequest"}),"waitForRequest(urlOrPredicate, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitforresponse"}),"waitForResponse(urlOrPredicate, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("a",r({parentName:"td"},{href:"/api/puppeteer.page.waitforselector"}),"waitForSelector(selector, options)")),(0,n.kt)("td",r({parentName:"tr"},{align:null})),(0,n.kt)("td",r({parentName:"tr"},{align:null}),(0,n.kt)("p",null,"Wait for the ",(0,n.kt)("code",null,"selector")," to appear in page. If at the moment of calling the method the ",(0,n.kt)("code",null,"selector")," already exists, the method will return immediately. If the ",(0,n.kt)("code",null,"selector")," doesn't appear after the ",(0,n.kt)("code",null,"timeout")," milliseconds of waiting, the function will throw."),(0,n.kt)("p",null,"This method works across navigations:"))))),(0,n.kt)("pre",null,(0,n.kt)("code",r({parentName:"pre"},{className:"language-ts"}),"import puppeteer from 'puppeteer';\n(async () => {\n const browser = await puppeteer.launch();\n const page = await browser.newPage();\n let currentURL;\n page\n .waitForSelector('img')\n .then(() => console.log('First URL with image: ' + currentURL));\n for (currentURL of [\n 'https://example.com',\n 'https://google.com',\n 'https://bbc.com',\n ]) {\n await page.goto(currentURL);\n }\n await browser.close();\n})();\n")),(0,n.kt)("p",null,"|\n| ",(0,n.kt)("a",r({parentName:"p"},{href:"/api/puppeteer.page.waitfortimeout"}),"waitForTimeout(milliseconds)")," | | |\n| ",(0,n.kt)("a",r({parentName:"p"},{href:"/api/puppeteer.page.waitforxpath"}),"waitForXPath(xpath, options)")," | | ",(0,n.kt)("p",null,"Wait for the ",(0,n.kt)("code",null,"xpath")," to appear in page. If at the moment of calling the method the ",(0,n.kt)("code",null,"xpath")," already exists, the method will return immediately. If the ",(0,n.kt)("code",null,"xpath")," doesn't appear after the ",(0,n.kt)("code",null,"timeout")," milliseconds of waiting, the function will throw."),(0,n.kt)("p",null,"This method works across navigation")),(0,n.kt)("pre",null,(0,n.kt)("code",r({parentName:"pre"},{className:"language-ts"}),"import puppeteer from 'puppeteer';\n(async () => {\n const browser = await puppeteer.launch();\n const page = await browser.newPage();\n let currentURL;\n page\n .waitForXPath('//img')\n .then(() => console.log('First URL with image: ' + currentURL));\n for (currentURL of [\n 'https://example.com',\n 'https://google.com',\n 'https://bbc.com',\n ]) {\n await page.goto(currentURL);\n }\n await browser.close();\n})();\n")),(0,n.kt)("p",null,"|\n| ",(0,n.kt)("a",r({parentName:"p"},{href:"/api/puppeteer.page.workers"}),"workers()")," | | |"))}s.isMDXComponent=!0}}]);