mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
1 line
8.1 KiB
JavaScript
1 line
8.1 KiB
JavaScript
|
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[78530],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>d});var a=n(67294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},i=Object.keys(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var l=a.createContext({}),u=function(e){var t=a.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},s=function(e){var t=u(e.components);return a.createElement(l.Provider,{value:t},e.children)},c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,l=e.parentName,s=p(e,["components","mdxType","originalType","parentName"]),m=u(n),d=r,g=m["".concat(l,".").concat(d)]||m[d]||c[d]||i;return n?a.createElement(g,o(o({ref:t},s),{},{components:n})):a.createElement(g,o({ref:t},s))}));function d(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=m;var p={};for(var l in t)hasOwnProperty.call(t,l)&&(p[l]=t[l]);p.originalType=e,p.mdxType="string"==typeof e?e:r,o[1]=p;for(var u=2;u<i;u++)o[u]=n[u];return a.createElement.apply(null,o)}return a.createElement.apply(null,n)}m.displayName="MDXCreateElement"},91978:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>p,toc:()=>u});var a=n(87462),r=(n(67294),n(3905));const i={},o="Page.waitForFunction() method",p={unversionedId:"api/puppeteer.page.waitforfunction",id:"api/puppeteer.page.waitforfunction",title:"Page.waitForFunction() method",description:"The waitForFunction can be used to observe viewport size change:",source:"@site/../docs/api/puppeteer.page.waitforfunction.md",sourceDirName:"api",slug:"/api/puppeteer.page.waitforfunction",permalink:"/api/puppeteer.page.waitforfunction",draft:!1,tags:[],version:"current",frontMatter:{},sidebar:"sidebar",previous:{title:"Page.waitForFrame() method",permalink:"/api/puppeteer.page.waitforframe"},next:{title:"Page.waitForNavigation() method",permalink:"/api/puppeteer.page.waitfornavigation"}},l={},u=[{value:"Parameters",id:"parameters",level:2}],s={toc:u};function c(e){let{components:t,...n}=e;return(0,r.kt)("wrapper",(0,a.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"pagewaitforfunction-method"},"Page.waitForFunction() method"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"waitForFunction")," can be used to observe viewport size change:"),(0,r.kt)("pre",null,(0,r.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,r.kt)("p",null,"To pass arguments from node.js to the predicate of ",(0,r.kt)("inlineCode",{parentName:"p"},"page.waitForFunction")," function:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"const selector = '.foo';\nawait page.waitForFunction(\n(selector) => !!document.querySelecto
|