puppeteer/assets/js/95ee5c6b.6aed4c7c.js

2 lines
6.2 KiB
JavaScript
Raw Normal View History

/*! For license information please see 95ee5c6b.6aed4c7c.js.LICENSE.txt */
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[8978],{11385:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>p});var r=t(85893),a=t(11151);const i={sidebar_label:"Page.waitForFunction"},o="Page.waitForFunction() method",s={id:"api/puppeteer.page.waitforfunction",title:"Page.waitForFunction() method",description:"Waits for the provided function, pageFunction, to return a truthy value when evaluated in the page's context.",source:"@site/versioned_docs/version-22.0.0/api/puppeteer.page.waitforfunction.md",sourceDirName:"api",slug:"/api/puppeteer.page.waitforfunction",permalink:"/api/puppeteer.page.waitforfunction",draft:!1,unlisted:!1,tags:[],version:"22.0.0",frontMatter:{sidebar_label:"Page.waitForFunction"},sidebar:"api",previous:{title:"Page.waitForFrame",permalink:"/api/puppeteer.page.waitforframe"},next:{title:"Page.waitForNavigation",permalink:"/api/puppeteer.page.waitfornavigation"}},c={},p=[{value:"Signature:",id:"signature",level:4},{value:"Parameters",id:"parameters",level:2},{value:"Example 1",id:"example-1",level:2},{value:"Example 2",id:"example-2",level:2},{value:"Example 3",id:"example-3",level:2}];function l(e){const n={a:"a",code:"code",em:"em",h1:"h1",h2:"h2",h4:"h4",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"pagewaitforfunction-method",children:"Page.waitForFunction() method"}),"\n",(0,r.jsxs)(n.p,{children:["Waits for the provided function, ",(0,r.jsx)(n.code,{children:"pageFunction"}),", to return a truthy value when evaluated in the page's context."]}),"\n",(0,r.jsx)(n.h4,{id:"signature",children:"Signature:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-typescript",children:"class Page {\n waitForFunction<\n Params extends unknown[],\n Func extends EvaluateFunc<Params> = EvaluateFunc<Params>,\n >(\n pageFunction: Func | string,\n options?: FrameWaitForFunctionOptions,\n ...args: Params\n ): Promise<HandleFor<Awaited<ReturnType<Func>>>>;\n}\n"})}),"\n",(0,r.jsx)(n.h2,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(n.table,{children:[(0,r.jsx)(n.thead,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.th,{children:"Parameter"}),(0,r.jsx)(n.th,{children:"Type"}),(0,r.jsx)(n.th,{children:"Description"})]})}),(0,r.jsxs)(n.tbody,{children:[(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"pageFunction"}),(0,r.jsx)(n.td,{children:"Func | string"}),(0,r.jsx)(n.td,{children:"Function to be evaluated in browser context until it returns a truthy value."})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"options"}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.a,{href:"/api/puppeteer.framewaitforfunctionoptions",children:"FrameWaitForFunctionOptions"})}),(0,r.jsxs)(n.td,{children:[(0,r.jsx)(n.em,{children:"(Optional)"})," Options for configuring waiting behavior."]})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:"args"}),(0,r.jsx)(n.td,{children:"Params"}),(0,r.jsx)(n.td,{})]})]})]}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,r.jsxs)(n.p,{children:["Promise<",(0,r.jsx)(n.a,{href:"/api/puppeteer.handlefor",children:"HandleFor"}),"<Awaited<ReturnType<Func>>>>"]}),"\n",(0,r.jsx)(n.h2,{id:"example-1",children:"Example 1"}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.a,{href:"/api/puppeteer.page.waitforfunction",children:"Page.waitForFunction()"})," can be used to observe a viewport size change:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n(async () => {\n const browser = await puppeteer.launch();\n const page = await browser.newPage();\n const watchDog = page.waitForFunction('window.innerWidth < 100');\n await page.setViewport({width: 50, height: 50});\n await watchDog;\n await browser.close();\n})();\n"})}),"\n",(0,r.jsx)(n.h2,{id:"example-2",children:"Example 2"}),"\n",(0,r.jsxs)(n.p,{children:["Arguments