puppeteer/assets/js/7ea11ded.4327bc73.js

2 lines
10 KiB
JavaScript
Raw Normal View History

/*! For license information please see 7ea11ded.4327bc73.js.LICENSE.txt */
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[24174],{18223:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>a,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=t(85893),n=t(11151);const i={sidebar_label:"BrowserContext"},o="BrowserContext class",p={id:"api/puppeteer.browsercontext",title:"BrowserContext class",description:"BrowserContext represents individual user contexts within a browser.",source:"@site/versioned_docs/version-22.0.0/api/puppeteer.browsercontext.md",sourceDirName:"api",slug:"/api/puppeteer.browsercontext",permalink:"/api/puppeteer.browsercontext",draft:!1,unlisted:!1,tags:[],version:"22.0.0",frontMatter:{sidebar_label:"BrowserContext"},sidebar:"api",previous:{title:"Browser.wsEndpoint",permalink:"/api/puppeteer.browser.wsendpoint"},next:{title:"BrowserContext.browser",permalink:"/api/puppeteer.browsercontext.browser"}},a={},c=[{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 d(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,n.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.h1,{id:"browsercontext-class",children:"BrowserContext class"}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"BrowserContext"})," represents individual user contexts within a ",(0,s.jsx)(r.a,{href:"/api/puppeteer.browser",children:"browser"}),"."]}),"\n",(0,s.jsxs)(r.p,{children:["When a ",(0,s.jsx)(r.a,{href:"/api/puppeteer.browser",children:"browser"})," is launched, it has a single ",(0,s.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"})," by default. Others can be created using ",(0,s.jsx)(r.a,{href:"/api/puppeteer.browser.createbrowsercontext",children:"Browser.createBrowserContext()"}),". Each context has isolated storage (cookies/localStorage/etc.)"]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"BrowserContext"})," ",(0,s.jsx)(r.a,{href:"/api/puppeteer.eventemitter",children:"emits"})," various events which are documented in the ",(0,s.jsx)(r.a,{href:"/api/puppeteer.browsercontextevent",children:"BrowserContextEvent"})," enum."]}),"\n",(0,s.jsxs)(r.p,{children:["If a ",(0,s.jsx)(r.a,{href:"/api/puppeteer.page",children:"page"})," opens another ",(0,s.jsx)(r.a,{href:"/api/puppeteer.page",children:"page"}),", e.g. using ",(0,s.jsx)(r.code,{children:"window.open"}),", the popup will belong to the parent ",(0,s.jsx)(r.a,{href:"/api/puppeteer.page.browsercontext",children:"page's browser context"}),"."]}),"\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 BrowserContext extends EventEmitter<BrowserContextEvents>\n"})}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.strong,{children:"Extends:"})," ",(0,s.jsx)(r.a,{href:"/api/puppeteer.eventemitter",children:"EventEmitter"}),"<",(0,s.jsx)(r.a,{href:"/api/puppeteer.browsercontextevents",children:"BrowserContextEvents"}),">"]}),"\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:"BrowserContext"})," class."]}),"\n",(0,s.jsx)(r.h2,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(r.p,{children:["Creating a new ",(0,s.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),":"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-ts",children:"// Create a new browser context\nconst context = await browser.createBrowserContext();\n// Create a new page inside context.\nconst page = await context.newPage();\n// ... do stuff with page ...\nawait page.goto