puppeteer/assets/js/ccf9c475.c01e5092.js

1 line
40 KiB
JavaScript

"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[85574],{3905:(e,t,a)=>{a.d(t,{Zo:()=>d,kt:()=>g});var r=a(67294);function n(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 r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function l(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?p(Object(a),!0).forEach((function(t){n(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):p(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function i(e,t){if(null==e)return{};var a,r,n=function(e,t){if(null==e)return{};var a,r,n={},p=Object.keys(e);for(r=0;r<p.length;r++)a=p[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var p=Object.getOwnPropertySymbols(e);for(r=0;r<p.length;r++)a=p[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var o=r.createContext({}),u=function(e){var t=r.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},d=function(e){var t=u(e.components);return r.createElement(o.Provider,{value:t},e.children)},s={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,p=e.originalType,o=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),m=u(a),g=n,k=m["".concat(o,".").concat(g)]||m[g]||s[g]||p;return a?r.createElement(k,l(l({ref:t},d),{},{components:a})):r.createElement(k,l({ref:t},d))}));function g(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var p=a.length,l=new Array(p);l[0]=m;var i={};for(var o in t)hasOwnProperty.call(t,o)&&(i[o]=t[o]);i.originalType=e,i.mdxType="string"==typeof e?e:n,l[1]=i;for(var u=2;u<p;u++)l[u]=a[u];return r.createElement.apply(null,l)}return r.createElement.apply(null,a)}m.displayName="MDXCreateElement"},99142:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>o,contentTitle:()=>l,default:()=>s,frontMatter:()=>p,metadata:()=>i,toc:()=>u});var r=a(87462),n=(a(67294),a(3905));const p={},l="Page class",i={unversionedId:"api/puppeteer.page",id:"api/puppeteer.page",title:"Page class",description:"Page provides methods to interact with a single tab or extension background page in Chromium.",source:"@site/../docs/api/puppeteer.page.md",sourceDirName:"api",slug:"/api/puppeteer.page",permalink:"/puppeteer/api/puppeteer.page",draft:!1,tags:[],version:"current",frontMatter:{},sidebar:"sidebar",previous:{title:"Offset.y property",permalink:"/puppeteer/api/puppeteer.offset.y"},next:{title:"Page.$() method",permalink:"/puppeteer/api/puppeteer.page._"}},o={},u=[{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}],d={toc:u};function s(e){let{components:t,...a}=e;return(0,n.kt)("wrapper",(0,r.Z)({},d,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("h1",{id:"page-class"},"Page class"),(0,n.kt)("p",null,"Page provides methods to interact with a single tab or ",(0,n.kt)("a",{parentName:"p",href:"https://developer.chrome.com/extensions/background_pages"},"extension background page")," in Chromium."),(0,n.kt)("p",null,(0,n.kt)("strong",{parentName:"p"},"Signature:")),(0,n.kt)("pre",null,(0,n.kt)("code",{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",{parentName:"p",href:"/puppeteer/api/puppeteer.eventemitter"},"EventEmitter")),(0,n.kt)("h2",{id:"remarks"},"Remarks"),(0,n.kt)("p",null,"One Browser instance might have multiple Page instances."),(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",{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",{parentName:"pre",className:"language-js"},"const puppeteer = require('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",{parentName:"p",href:"/puppeteer/api/puppeteer.eventemitter"},"EventEmitter")," class and will emit various events which are documented in the ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.pageemittedevents"},"PageEmittedEvents")," enum."),(0,n.kt)("h2",{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",{parentName:"pre",className:"language-js"},"page.once('load', () => console.log('Page loaded!'));\n")),(0,n.kt)("p",null,"To unsubscribe from events use the ",(0,n.kt)("inlineCode",{parentName:"p"},"off")," method:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},"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",{id:"properties"},"Properties"),(0,n.kt)("table",null,(0,n.kt)("thead",{parentName:"table"},(0,n.kt)("tr",{parentName:"thead"},(0,n.kt)("th",{parentName:"tr",align:null},"Property"),(0,n.kt)("th",{parentName:"tr",align:null},"Modifiers"),(0,n.kt)("th",{parentName:"tr",align:null},"Type"),(0,n.kt)("th",{parentName:"tr",align:null},"Description"))),(0,n.kt)("tbody",{parentName:"table"},(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.accessibility"},"accessibility")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.accessibility"},"Accessibility")),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.coverage"},"coverage")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.coverage"},"Coverage")),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.keyboard"},"keyboard")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.keyboard"},"Keyboard")),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.mouse"},"mouse")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.mouse"},"Mouse")),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.touchscreen"},"touchscreen")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.touchscreen"},"Touchscreen")),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.tracing"},"tracing")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.tracing"},"Tracing")),(0,n.kt)("td",{parentName:"tr",align:null})))),(0,n.kt)("h2",{id:"methods"},"Methods"),(0,n.kt)("table",null,(0,n.kt)("thead",{parentName:"table"},(0,n.kt)("tr",{parentName:"thead"},(0,n.kt)("th",{parentName:"tr",align:null},"Method"),(0,n.kt)("th",{parentName:"tr",align:null},"Modifiers"),(0,n.kt)("th",{parentName:"tr",align:null},"Description"))),(0,n.kt)("tbody",{parentName:"table"},(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page._"},"$(selector)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.__1"},"$(selector)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.__"},"$$(selector)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.___1"},"$$(selector)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.__eval"},"$$eval(selector, pageFunction, args)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.__eval_1"},"$$eval(selector, pageFunction, args)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page._eval"},"$eval(selector, pageFunction, args)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page._eval_1"},"$eval(selector, pageFunction, args)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page._x"},"$x(expression)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.addscripttag"},"addScriptTag(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.addstyletag"},"addStyleTag(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align: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)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.authenticate"},"authenticate(credentials)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Provide credentials for ",(0,n.kt)("code",null,"HTTP authentication"),".")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.bringtofront"},"bringToFront()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Brings page to front (activates tab).")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.browser"},"browser()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Get the browser the page belongs to.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.browsercontext"},"browserContext()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Get the browser context that the page belongs to.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.click"},"click(selector, options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"td",href:"/puppeteer/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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.close"},"close(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.content"},"content()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.cookies"},"cookies(urls)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.createpdfstream"},"createPDFStream(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.deletecookie"},"deleteCookie(cookies)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulate"},"emulate(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Emulates given device metrics and user agent.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulatecputhrottling"},"emulateCPUThrottling(factor)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Enables CPU throttling to emulate slow CPUs.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulateidlestate"},"emulateIdleState(overrides)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulatemediafeatures"},"emulateMediaFeatures(features)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulatemediatype"},"emulateMediaType(type)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulatenetworkconditions"},"emulateNetworkConditions(networkConditions)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulatetimezone"},"emulateTimezone(timezoneId)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.emulatevisiondeficiency"},"emulateVisionDeficiency(type)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Simulates the given vision deficiency on the page.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.evaluate"},"evaluate(pageFunction, args)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.evaluatehandle"},"evaluateHandle(pageFunction, args)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.evaluateonnewdocument"},"evaluateOnNewDocument(pageFunction, args)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Adds a function which would be invoked in one of the following scenarios:- whenever the page is navigated- whenever the child frame is attached or navigated. In this case, the function is invoked in the context of the newly attached frame.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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.exposefunction"},"exposeFunction(name, pptrFunction)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align: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"),".If the puppeteerFunction returns a ",(0,n.kt)("code",null,"Promise"),", it will be awaited.NOTE: Functions installed via ",(0,n.kt)("code",null,"page.exposeFunction")," survive navigations.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.focus"},"focus(selector)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.frames"},"frames()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.goback"},"goBack(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"This method navigate to the previous page in history.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.goforward"},"goForward(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"This method navigate to the next page in history.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.goto"},"goto(url, options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.hover"},"hover(selector)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"td",href:"/puppeteer/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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.isclosed"},"isClosed()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Indicates that the page has been closed.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.isdraginterceptionenabled"},"isDragInterceptionEnabled()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.isjavascriptenabled"},"isJavaScriptEnabled()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.mainframe"},"mainFrame()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.metrics"},"metrics()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.off"},"off(eventName, handler)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.on"},"on(eventName, handler)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Listen to page events.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.once"},"once(eventName, handler)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.pdf"},"pdf(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.queryobjects"},"queryObjects(prototypeHandle)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.reload"},"reload(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.screenshot"},"screenshot(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.select"},"select(selector, values)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setbypasscsp"},"setBypassCSP(enabled)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Toggles bypassing page's Content-Security-Policy.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setcacheenabled"},"setCacheEnabled(enabled)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setcontent"},"setContent(html, options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setcookie"},"setCookie(cookies)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setdefaultnavigationtimeout"},"setDefaultNavigationTimeout(timeout)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"This setting will change the default maximum navigation time for the following methods and related shortcuts:- ",(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.goback"},"page.goBack(options)"),"- ",(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.goforward"},"page.goForward(options)"),"- ",(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.goto"},"page.goto(url,options)"),"- ",(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.reload"},"page.reload(options)"),"- ",(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setcontent"},"page.setContent(html,options)"),"- ",(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.waitfornavigation"},"page.waitForNavigation(options)"))),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setdefaulttimeout"},"setDefaultTimeout(timeout)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setdraginterception"},"setDragInterception(enabled)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setextrahttpheaders"},"setExtraHTTPHeaders(headers)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"The extra HTTP headers will be sent with every request the page initiates. NOTE: All HTTP header names are lowercased. (HTTP headers are case-insensitive, so this shouldn\u2019t impact your server code.) NOTE: page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setgeolocation"},"setGeolocation(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"Sets the page's geolocation.")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setjavascriptenabled"},"setJavaScriptEnabled(enabled)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setofflinemode"},"setOfflineMode(enabled)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setrequestinterception"},"setRequestInterception(value)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setuseragent"},"setUserAgent(userAgent, userAgentMetadata)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.setviewport"},"setViewport(viewport)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align: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.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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.tap"},"tap(selector)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{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",{parentName:"td",href:"/puppeteer/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",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.target"},"target()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.title"},"title()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.type"},"type(selector, text, options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align: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.To press a special key, like ",(0,n.kt)("code",null,"Control")," or ",(0,n.kt)("code",null,"ArrowDown"),", use ",(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.keyboard.press"},"Keyboard.press()"),".")),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.url"},"url()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.viewport"},"viewport()")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null})),(0,n.kt)("tr",{parentName:"tbody"},(0,n.kt)("td",{parentName:"tr",align:null},(0,n.kt)("a",{parentName:"td",href:"/puppeteer/api/puppeteer.page.waitforfilechooser"},"waitForFileChooser(options)")),(0,n.kt)("td",{parentName:"tr",align:null}),(0,n.kt)("td",{parentName:"tr",align:null},"This method is typically coupled with an action that triggers file choosing. The following example clicks a button that issues a file chooser and then responds with ",(0,n.kt)("code",null,"/tmp/myfile.pdf")," as if a user has selected this file.")))),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},"const [fileChooser] = await Promise.all([\n page.waitForFileChooser(),\n page.click('#upload-file-button'),\n // some button that triggers file selection\n]);\nawait fileChooser.accept(['/tmp/myfile.pdf']);\n")),(0,n.kt)("p",null,"NOTE: This must be called before the file chooser is launched. It will not return a currently active file chooser. |\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitforframe"},"waitForFrame(urlOrPredicate, options)")," | | |\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitforfunction"},"waitForFunction(pageFunction, options, args)")," | | The ",(0,n.kt)("code",null,"waitForFunction")," can be used to observe viewport size change:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre"},"const puppeteer = require('puppeteer');\n(async () => {\nconst browser = await puppeteer.launch();\nconst page = await browser.newPage();\nconst watchDog = page.waitForFunction('window.innerWidth < 100');\nawait page.setViewport({ width: 50, height: 50 });\nawait watchDog;\nawait browser.close();\n})();\n")),(0,n.kt)("p",null,"To pass arguments from node.js to the predicate of ",(0,n.kt)("code",null,"page.waitForFunction")," function:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre"},"const selector = '.foo';\nawait page.waitForFunction(\n(selector) => !!document.querySelector(selector),\n{},\nselector\n);\n")),(0,n.kt)("p",null,"The predicate of ",(0,n.kt)("code",null,"page.waitForFunction")," can be asynchronous too:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre"},"const username = 'github-username';\nawait page.waitForFunction(\nasync (username) => {\nconst githubResponse = await fetch(\n `https://api.github.com/users/${username}`\n);\nconst githubUser = await githubResponse.json();\n// show the avatar\nconst img = document.createElement('img');\nimg.src = githubUser.avatar_url;\n// wait 3 seconds\nawait new Promise((resolve, reject) => setTimeout(resolve, 3000));\nimg.remove();\n},\n{},\nusername\n);\n")),(0,n.kt)("p",null,"|\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitfornavigation"},"waitForNavigation(options)")," | | This resolves when the page navigates to a new URL or reloads. It is useful when you run code that will indirectly cause the page to navigate. Consider this example:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},"const [response] = await Promise.all([\n page.waitForNavigation(), // The promise resolves after navigation has finished\n page.click('a.my-link'), // Clicking the link will indirectly cause a navigation\n]);\n")),(0,n.kt)("p",null,"|\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitfornetworkidle"},"waitForNetworkIdle(options)")," | | |\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitforrequest"},"waitForRequest(urlOrPredicate, options)")," | | |\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitforresponse"},"waitForResponse(urlOrPredicate, options)")," | | |\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitforselector"},"waitForSelector(selector, options)")," | | 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.This method works across navigations:"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},"const puppeteer = require('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",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitforselector_1"},"waitForSelector(selector, options)")," | | |\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitfortimeout"},"waitForTimeout(milliseconds)")," | | Causes your script to wait for the given number of milliseconds. |\n| ",(0,n.kt)("a",{parentName:"p",href:"/puppeteer/api/puppeteer.page.waitforxpath"},"waitForXPath(xpath, options)")," | | 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.This method works across navigation"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},"const puppeteer = require('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",{parentName:"p",href:"/puppeteer/api/puppeteer.page.workers"},"workers()")," | | |"))}s.isMDXComponent=!0}}]);