mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
2 lines
7.1 KiB
JavaScript
2 lines
7.1 KiB
JavaScript
/*! For license information please see 1240da76.41c53efe.js.LICENSE.txt */
|
|
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[44587],{35682:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>i,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>a,toc:()=>d});var n=t(85893),s=t(11151);const o={sidebar_label:"WebWorker"},l="WebWorker class",a={id:"api/puppeteer.webworker",title:"WebWorker class",description:"This class represents a WebWorker.",source:"@site/versioned_docs/version-21.6.1/api/puppeteer.webworker.md",sourceDirName:"api",slug:"/api/puppeteer.webworker",permalink:"/api/puppeteer.webworker",draft:!1,unlisted:!1,tags:[],version:"21.6.1",frontMatter:{sidebar_label:"WebWorker"},sidebar:"api",previous:{title:"Page.workers",permalink:"/api/puppeteer.page.workers"},next:{title:"WebWorker.evaluate",permalink:"/api/puppeteer.webworker.evaluate"}},i={},d=[{value:"Signature:",id:"signature",level:4},{value:"Remarks",id:"remarks",level:2},{value:"Example",id:"example",level:2},{value:"Properties",id:"properties",level:2},{value:"Methods",id:"methods",level:2}];function c(e){const r={a:"a",code:"code",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,s.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.h1,{id:"webworker-class",children:"WebWorker class"}),"\n",(0,n.jsxs)(r.p,{children:["This class represents a ",(0,n.jsx)(r.a,{href:"https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API",children:"WebWorker"}),"."]}),"\n",(0,n.jsx)(r.h4,{id:"signature",children:"Signature:"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-typescript",children:"export declare class WebWorker extends EventEmitter<Record<EventType, unknown>>\n"})}),"\n",(0,n.jsxs)(r.p,{children:[(0,n.jsx)(r.strong,{children:"Extends:"})," ",(0,n.jsx)(r.a,{href:"/api/puppeteer.eventemitter",children:"EventEmitter"}),"<Record<",(0,n.jsx)(r.a,{href:"/api/puppeteer.eventtype",children:"EventType"}),", unknown>>"]}),"\n",(0,n.jsx)(r.h2,{id:"remarks",children:"Remarks"}),"\n",(0,n.jsxs)(r.p,{children:["The events ",(0,n.jsx)(r.code,{children:"workercreated"})," and ",(0,n.jsx)(r.code,{children:"workerdestroyed"})," are emitted on the page object to signal the worker lifecycle."]}),"\n",(0,n.jsxs)(r.p,{children:["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.jsx)(r.code,{children:"WebWorker"})," class."]}),"\n",(0,n.jsx)(r.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-ts",children:"page.on('workercreated', worker =>\n console.log('Worker created: ' + worker.url())\n);\npage.on('workerdestroyed', worker =>\n console.log('Worker destroyed: ' + worker.url())\n);\n\nconsole.log('Current workers:');\nfor (const worker of page.workers()) {\n console.log(' ' + worker.url());\n}\n"})}),"\n",(0,n.jsx)(r.h2,{id:"properties",children:"Properties"}),"\n",(0,n.jsxs)(r.table,{children:[(0,n.jsx)(r.thead,{children:(0,n.jsxs)(r.tr,{children:[(0,n.jsx)(r.th,{children:"Property"}),(0,n.jsx)(r.th,{children:"Modifiers"}),(0,n.jsx)(r.th,{children:"Type"}),(0,n.jsx)(r.th,{children:"Description"})]})}),(0,n.jsx)(r.tbody,{children:(0,n.jsxs)(r.tr,{children:[(0,n.jsx)(r.td,{children:"client"}),(0,n.jsx)(r.td,{children:(0,n.jsx)("code",{children:"readonly"})}),(0,n.jsx)(r.td,{children:(0,n.jsx)(r.a,{href:"/api/puppeteer.cdpsession",children:"CDPSession"})}),(0,n.jsx)(r.td,{children:"The CDP session client the WebWorker belongs to."})]})})]}),"\n",(0,n.jsx)(r.h2,{id:"methods",children:"Methods"}),"\n",(0,n.jsxs)(r.table,{children:[(0,n.jsx)(r.thead,{children:(0,n.jsxs)(r.tr,{children:[(0,n.jsx)(r.th,{children:"Method"}),(0,n.jsx)(r.th,{children:"Modifiers"}),(0,n.jsx)(r.th,{children:"Description"})]})}),(0,n.jsxs)(r.tbody,{children:[(0,n.jsxs)(r.tr,{children:[(0,n.jsx)(r.td,{children:(0,n.jsx)(r.a,{href:"/api/puppeteer.webworker.evaluate",children:"evaluate(pageFunction, args)"})}),(0,n.jsx)(r.td,{}),(0,n.jsxs)(r.td,{children:["If the function passed to the ",(0,n.jsx)("code",{children:"worker.evaluate"})," returns a Promise, then ",(0,n.jsx)("code",{children:"worker.evaluate"})," would wait for the promise to resolve and return its value. If the function passed to the ",(0,n.jsx)("code",{children:"worker.evaluate"})," returns a non-serializable value, then ",(0,n.jsx)("code",{children:"worker.evaluate"})," resolves to ",(0,n.jsx)("code",{children:"undefined"}),". DevTools Protocol also supports transferring some additional values that are not serializable by ",(0,n.jsx)("code",{children:"JSON"}),": ",(0,n.jsx)("code",{children:"-0"}),", ",(0,n.jsx)("code",{children:"NaN"}),", ",(0,n.jsx)("code",{children:"Infinity"}),", ",(0,n.jsx)("code",{children:"-Infinity"}),", and bigint literals. Shortcut for ",(0,n.jsx)("code",{children:"await worker.executionContext()).evaluate(pageFunction, ...args)"}),"."]})]}),(0,n.jsxs)(r.tr,{children:[(0,n.jsx)(r.td,{children:(0,n.jsx)(r.a,{href:"/api/puppeteer.webworker.evaluatehandle",children:"evaluateHandle(pageFunction, args)"})}),(0,n.jsx)(r.td,{}),(0,n.jsxs)(r.td,{children:["The only difference between ",(0,n.jsx)("code",{children:"worker.evaluate"})," and ",(0,n.jsx)("code",{children:"worker.evaluateHandle"})," is that ",(0,n.jsx)("code",{children:"worker.evaluateHandle"})," returns in-page object (JSHandle). If the function passed to the ",(0,n.jsx)("code",{children:"worker.evaluateHandle"})," returns a ",(0,n.jsx)("code",{children:"Promise"}),", then ",(0,n.jsx)("code",{children:"worker.evaluateHandle"})," would wait for the promise to resolve and return its value. Shortcut for ",(0,n.jsx)("code",{children:"await worker.executionContext()).evaluateHandle(pageFunction, ...args)"})]})]}),(0,n.jsxs)(r.tr,{children:[(0,n.jsx)(r.td,{children:(0,n.jsx)(r.a,{href:"/api/puppeteer.webworker.url",children:"url()"})}),(0,n.jsx)(r.td,{}),(0,n.jsx)(r.td,{children:"The URL of this web worker."})]})]})]})]})}function h(e={}){const{wrapper:r}={...(0,s.a)(),...e.components};return r?(0,n.jsx)(r,{...e,children:(0,n.jsx)(c,{...e})}):c(e)}},75251:(e,r,t)=>{var n=t(67294),s=Symbol.for("react.element"),o=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,a=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function d(e,r,t){var n,o={},d=null,c=null;for(n in void 0!==t&&(d=""+t),void 0!==r.key&&(d=""+r.key),void 0!==r.ref&&(c=r.ref),r)l.call(r,n)&&!i.hasOwnProperty(n)&&(o[n]=r[n]);if(e&&e.defaultProps)for(n in r=e.defaultProps)void 0===o[n]&&(o[n]=r[n]);return{$$typeof:s,type:e,key:d,ref:c,props:o,_owner:a.current}}r.Fragment=o,r.jsx=d,r.jsxs=d},85893:(e,r,t)=>{e.exports=t(75251)},11151:(e,r,t)=>{t.d(r,{Z:()=>a,a:()=>l});var n=t(67294);const s={},o=n.createContext(s);function l(e){const r=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function a(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),n.createElement(o.Provider,{value:r},e.children)}}}]); |