mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
/*! For license information please see 335642b7.c71be61a.js.LICENSE.txt */
|
|
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[84999],{65872:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>a,contentTitle:()=>p,default:()=>h,frontMatter:()=>i,metadata:()=>o,toc:()=>c});var s=t(85893),n=t(11151);const i={sidebar_label:"Browser"},p="Browser class",o={id:"api/puppeteer.browser",title:"Browser class",description:"Browser represents a browser instance that is either:",source:"@site/../docs/api/puppeteer.browser.md",sourceDirName:"api",slug:"/api/puppeteer.browser",permalink:"/next/api/puppeteer.browser",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{sidebar_label:"Browser"},sidebar:"api",previous:{title:"Puppeteer.unregisterCustomQueryHandler",permalink:"/next/api/puppeteer.puppeteer.unregistercustomqueryhandler"},next:{title:"Browser.browserContexts",permalink:"/next/api/puppeteer.browser.browsercontexts"}},a={},c=[{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}];function d(e){const r={a:"a",code:"code",h1:"h1",h2:"h2",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,n.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.h1,{id:"browser-class",children:"Browser class"}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"})," represents a browser instance that is either:"]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["connected to via ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.puppeteer.connect",children:"Puppeteer.connect()"})," or - launched by ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.puppeteernode.launch",children:"PuppeteerNode.launch()"}),"."]}),"\n"]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"})," ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.eventemitter",children:"emits"})," various events which are documented in the ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browserevent",children:"BrowserEvent"})," enum."]}),"\n",(0,s.jsx)(r.h4,{id:"signature",children:"Signature:"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-typescript",children:"export declare abstract class Browser extends EventEmitter<BrowserEvents>\n"})}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.strong,{children:"Extends:"})," ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.eventemitter",children:"EventEmitter"}),"<",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browserevents",children:"BrowserEvents"}),">"]}),"\n",(0,s.jsx)(r.h2,{id:"remarks",children:"Remarks"}),"\n",(0,s.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,s.jsx)(r.code,{children:"Browser"})," class."]}),"\n",(0,s.jsx)(r.h2,{id:"example-1",children:"Example 1"}),"\n",(0,s.jsxs)(r.p,{children:["Using a ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"})," to create a ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"Page"}),":"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n\nconst browser = await puppeteer.launch();\nconst page = await browser.newPage();\nawait page.goto('https://example.com');\nawait browser.close();\n"})}),"\n",(0,s.jsx)(r.h2,{id:"example-2",children:"Example 2"}),"\n",(0,s.jsxs)(r.p,{children:["Disconnecting from and reconnecting to a ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"}),":"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n\nconst browser = await puppeteer.launch();\n// Store the endpoint to be able to reconnect to the browser.\nconst browserWSEndpoint = browser.wsEndpoint();\n// Disconnect puppeteer from the browser.\nawait browser.disconnect();\n\n// Use the endpoint to reestablish a connection\nconst browser2 = await puppeteer.connect({browserWSEndpoint});\n// Close the browser.\nawait browser2.close();\n"})}),"\n",(0,s.jsx)(r.h2,{id:"properties",children:"Properties"}),"\n",(0,s.jsxs)(r.table,{children:[(0,s.jsx)(r.thead,{children:(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.th,{children:"Property"}),(0,s.jsx)(r.th,{children:"Modifiers"}),(0,s.jsx)(r.th,{children:"Type"}),(0,s.jsx)(r.th,{children:"Description"})]})}),(0,s.jsxs)(r.tbody,{children:[(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:"connected"}),(0,s.jsx)(r.td,{children:(0,s.jsx)("code",{children:"readonly"})}),(0,s.jsx)(r.td,{children:"boolean"}),(0,s.jsxs)(r.td,{children:["Whether Puppeteer is connected to this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"}),"."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:"debugInfo"}),(0,s.jsx)(r.td,{children:(0,s.jsx)("code",{children:"readonly"})}),(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.debuginfo",children:"DebugInfo"})}),(0,s.jsx)(r.td,{children:"Get debug information from Puppeteer."})]})]})]}),"\n",(0,s.jsx)(r.h2,{id:"methods",children:"Methods"}),"\n",(0,s.jsxs)(r.table,{children:[(0,s.jsx)(r.thead,{children:(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.th,{children:"Method"}),(0,s.jsx)(r.th,{children:"Modifiers"}),(0,s.jsx)(r.th,{children:"Description"})]})}),(0,s.jsxs)(r.tbody,{children:[(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.browsercontexts",children:"browserContexts()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Gets a list of open ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser contexts"}),"."]}),(0,s.jsxs)("p",{children:["In a newly-created ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"}),", this will return a single instance of ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"BrowserContext"}),"."]})]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.close",children:"close()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:["Closes this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"})," and all associated ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"pages"}),"."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.createbrowsercontext",children:"createBrowserContext(options)"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Creates a new ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser context"}),"."]}),(0,s.jsxs)("p",{children:["This won't share cookies/cache with other ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser contexts"}),"."]})]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.defaultbrowsercontext",children:"defaultBrowserContext()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:["Gets the default ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser context"}),"."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.disconnect",children:"disconnect()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:["Disconnects Puppeteer from this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"}),", but leaves the process running."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.isconnected",children:"isConnected()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:["Whether Puppeteer is connected to this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"}),"."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.newpage",children:"newPage()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:["Creates a new ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"page"})," in the ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.defaultbrowsercontext",children:"default browser context"}),"."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.pages",children:"pages()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Gets a list of all open ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"pages"})," inside this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"}),"."]}),(0,s.jsxs)("p",{children:["If there ar multiple ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser contexts"}),", this returns all ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"pages"})," in all ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser contexts"}),"."]})]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.process",children:"process()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:["Gets the associated ",(0,s.jsx)(r.a,{href:"https://nodejs.org/api/child_process.html#class-childprocess",children:"ChildProcess"}),"."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.target",children:"target()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:["Gets the ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.target",children:"target"})," associated with the ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.defaultbrowsercontext",children:"default browser context"}),")."]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.targets",children:"targets()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Gets all active ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.target",children:"targets"}),"."]}),(0,s.jsxs)("p",{children:["In case of multiple ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser contexts"}),", this returns all ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.target",children:"targets"})," in all ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser contexts"}),"."]})]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.useragent",children:"userAgent()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Gets this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser's"})," original user agent."]}),(0,s.jsxs)("p",{children:[(0,s.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"Pages"})," can override the user agent with ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.page.setuseragent",children:"Page.setUserAgent()"}),"."]})]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.version",children:"version()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Gets a string representing this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser's"})," name and version."]}),(0,s.jsxs)("p",{children:["For headless browser, this is similar to ",(0,s.jsx)("code",{children:'"HeadlessChrome/61.0.3153.0"'}),". For non-headless or new-headless, this is similar to ",(0,s.jsx)("code",{children:'"Chrome/61.0.3153.0"'}),". For Firefox, it is similar to ",(0,s.jsx)("code",{children:'"Firefox/116.0a1"'}),"."]}),(0,s.jsxs)("p",{children:["The format of ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.version",children:"Browser.version()"})," might change with future releases of browsers."]})]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.waitfortarget",children:"waitForTarget(predicate, options)"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Waits until a ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.target",children:"target"})," matching the given ",(0,s.jsx)("code",{children:"predicate"})," appears and returns it."]}),(0,s.jsxs)("p",{children:["This will look all open ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser contexts"}),"."]})]})]}),(0,s.jsxs)(r.tr,{children:[(0,s.jsx)(r.td,{children:(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser.wsendpoint",children:"wsEndpoint()"})}),(0,s.jsx)(r.td,{}),(0,s.jsxs)(r.td,{children:[(0,s.jsxs)("p",{children:["Gets the WebSocket URL to connect to this ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"}),"."]}),(0,s.jsxs)("p",{children:["This is usually used with ",(0,s.jsx)(r.a,{href:"/next/api/puppeteer.puppeteer.connect",children:"Puppeteer.connect()"}),"."]}),(0,s.jsxs)("p",{children:["You can find the debugger URL (",(0,s.jsx)("code",{children:"webSocketDebuggerUrl"}),") from ",(0,s.jsx)("code",{children:(0,s.jsx)(r.a,{href:"http://HOST:PORT/json/version",children:"http://HOST:PORT/json/version"})}),"."]}),(0,s.jsxs)("p",{children:["See ",(0,s.jsx)(r.a,{href:"https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target",children:"browser endpoint"})," for more information."]})]})]})]})]})]})}function h(e={}){const{wrapper:r}={...(0,n.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},75251:(e,r,t)=>{var s=t(67294),n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),p=Object.prototype.hasOwnProperty,o=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function c(e,r,t){var s,i={},c=null,d=null;for(s in void 0!==t&&(c=""+t),void 0!==r.key&&(c=""+r.key),void 0!==r.ref&&(d=r.ref),r)p.call(r,s)&&!a.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps)for(s in r=e.defaultProps)void 0===i[s]&&(i[s]=r[s]);return{$$typeof:n,type:e,key:c,ref:d,props:i,_owner:o.current}}r.Fragment=i,r.jsx=c,r.jsxs=c},85893:(e,r,t)=>{e.exports=t(75251)},11151:(e,r,t)=>{t.d(r,{Z:()=>o,a:()=>p});var s=t(67294);const n={},i=s.createContext(n);function p(e){const r=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function o(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:p(e.components),s.createElement(i.Provider,{value:r},e.children)}}}]); |