1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["17400"],{19761(e,r,s){s.r(r),s.d(r,{metadata:()=>t,default:()=>h,frontMatter:()=>o,contentTitle:()=>d,toc:()=>p,assets:()=>c});var t=JSON.parse('{"id":"api/puppeteer.browsercontext","title":"BrowserContext class","description":"BrowserContext represents individual user contexts within a browser.","source":"@site/versioned_docs/version-25.12.0/api/puppeteer.browsercontext.md","sourceDirName":"api","slug":"/api/puppeteer.browsercontext","permalink":"/api/puppeteer.browsercontext","draft":false,"unlisted":false,"tags":[],"version":"25.12.0","frontMatter":{"sidebar_label":"BrowserContext"},"sidebar":"api","previous":{"title":"Browser.wsEndpoint","permalink":"/api/puppeteer.browser.wsendpoint"},"next":{"title":"BrowserContext.[asyncDisposeSymbol]","permalink":"/api/puppeteer.browsercontext._asyncdisposesymbol_"}}'),n=s(74848),i=s(28453);let o={sidebar_label:"BrowserContext"},d="BrowserContext class",c={},p=[{value:"Signature",id:"signature",level:3},{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 a(e){let r={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.header,{children:(0,n.jsx)(r.h1,{id:"browsercontext-class",children:"BrowserContext class"})}),"\n",(0,n.jsxs)(r.p,{children:[(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"BrowserContext"})," represents individual user contexts within a ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browser",children:"browser"}),"."]}),"\n",(0,n.jsxs)(r.p,{children:["When a ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browser",children:"browser"})," is launched, it has at least one default ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),". Others can be created using ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browser.createbrowsercontext",children:"Browser.createBrowserContext()"}),". Each context has isolated storage (cookies/localStorage/etc.)"]}),"\n",(0,n.jsxs)(r.p,{children:[(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"BrowserContext"})," ",(0,n.jsx)(r.a,{href:"/api/puppeteer.eventemitter",children:"emits"})," various events which are documented in the ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontextevent",children:"BrowserContextEvent"})," enum."]}),"\n",(0,n.jsxs)(r.p,{children:["If a ",(0,n.jsx)(r.a,{href:"/api/puppeteer.page",children:"page"})," opens another ",(0,n.jsx)(r.a,{href:"/api/puppeteer.page",children:"page"}),", e.g. using ",(0,n.jsx)(r.code,{children:"window.open"}),", the popup will belong to the parent ",(0,n.jsx)(r.a,{href:"/api/puppeteer.page.browsercontext",children:"page's browser context"}),"."]}),"\n",(0,n.jsx)(r.h3,{id:"signature",children:"Signature"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-typescript",children:"export declare abstract class BrowserContext extends EventEmitter<BrowserContextEvents>\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"}),"<",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontextevents",children:"BrowserContextEvents"}),">"]}),"\n",(0,n.jsx)(r.h2,{id:"remarks",children:"Remarks"}),"\n",(0,n.jsxs)(r.p,{children:["In Chrome all non-default contexts are incognito, and ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browser.defaultbrowsercontext",children:"default browser context"})," might be incognito if you provide the ",(0,n.jsx)(r.code,{children:"--incognito"})," argument when launching the browser."]}),"\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:"BrowserContext"})," class."]}),"\n",(0,n.jsx)(r.h2,{id:"example",children:"Example"}),"\n",(0,n.jsxs)(r.p,{children:["Creating a new ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),":"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.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('https://example.com');\n// Dispose context once it's no longer needed.\nawait context.close();\n"})}),"\n",(0,n.jsx)(r.h2,{id:"properties",children:"Properties"}),"\n",(0,n.jsxs)("table",{children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{children:(0,n.jsx)(r.p,{children:"Property"})}),(0,n.jsx)("th",{children:(0,n.jsx)(r.p,{children:"Modifiers"})}),(0,n.jsx)("th",{children:(0,n.jsx)(r.p,{children:"Type"})}),(0,n.jsx)("th",{children:(0,n.jsx)(r.p,{children:"Description"})})]})}),(0,n.jsxs)("tbody",{children:[(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"closed",children:"closed"})}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:(0,n.jsx)(r.code,{children:"readonly"})})}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:"boolean"})}),(0,n.jsx)("td",{children:(0,n.jsxs)(r.p,{children:["Whether this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"})," is closed."]})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"id",children:"id"})}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:(0,n.jsx)(r.code,{children:"readonly"})})}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:"string | undefined"})}),(0,n.jsx)("td",{children:(0,n.jsxs)(r.p,{children:["Identifier for this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),"."]})})]})]})]}),"\n",(0,n.jsx)(r.h2,{id:"methods",children:"Methods"}),"\n",(0,n.jsxs)("table",{children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{children:(0,n.jsx)(r.p,{children:"Method"})}),(0,n.jsx)("th",{children:(0,n.jsx)(r.p,{children:"Modifiers"})}),(0,n.jsx)("th",{children:(0,n.jsx)(r.p,{children:"Description"})})]})}),(0,n.jsxs)("tbody",{children:[(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"_asyncdisposesymbol_",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext._asyncdisposesymbol_",children:"[asyncDisposeSymbol]()"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"_disposesymbol_",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext._disposesymbol_",children:"[disposeSymbol]()"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"browser",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.browser",children:"browser()"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsxs)(r.p,{children:["Gets the ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browser",children:"browser"})," associated with this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),"."]})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"clearpermissionoverrides",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.clearpermissionoverrides",children:"clearPermissionOverrides()"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsxs)(r.p,{children:["Clears all permission overrides for this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),"."]})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"close",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.close",children:"close()"})})}),(0,n.jsx)("td",{}),(0,n.jsxs)("td",{children:[(0,n.jsxs)(r.p,{children:["Closes this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"})," and all associated ",(0,n.jsx)(r.a,{href:"/api/puppeteer.page",children:"pages"}),"."]}),(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Remarks:"})}),(0,n.jsxs)(r.p,{children:["The ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browser.defaultbrowsercontext",children:"default browser context"})," cannot be closed."]})]})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"cookies",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.cookies",children:"cookies()"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:"Gets all cookies in the browser context."})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"delete
1cookie",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.deletecookie",children:"deleteCookie(cookies)"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:"Removes cookie in this browser context."})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"deletematchingcookies",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.deletematchingcookies",children:"deleteMatchingCookies(filters)"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:"Deletes cookies matching the provided filters in this browser context."})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"newpage",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.newpage",children:"newPage(options)"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsxs)(r.p,{children:["Creates a new ",(0,n.jsx)(r.a,{href:"/api/puppeteer.page",children:"page"})," in this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),"."]})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"overridepermissions",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.overridepermissions",children:"overridePermissions(origin, permissions)"})})}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:(0,n.jsx)(r.code,{children:"deprecated"})})}),(0,n.jsxs)("td",{children:[(0,n.jsxs)(r.p,{children:["Grants this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"})," the given ",(0,n.jsx)(r.code,{children:"permissions"})," within the given ",(0,n.jsx)(r.code,{children:"origin"}),"."]}),(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Deprecated:"})}),(0,n.jsxs)(r.p,{children:["in favor of ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.setpermission",children:"BrowserContext.setPermission()"}),"."]})]})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"pages",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.pages",children:"pages(includeAll)"})})}),(0,n.jsx)("td",{}),(0,n.jsxs)("td",{children:[(0,n.jsxs)(r.p,{children:["Gets a list of all open ",(0,n.jsx)(r.a,{href:"/api/puppeteer.page",children:"pages"})," inside this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),"."]}),(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Remarks:"})}),(0,n.jsxs)(r.p,{children:["Non-visible ",(0,n.jsx)(r.a,{href:"/api/puppeteer.page",children:"pages"}),", such as ",(0,n.jsx)(r.code,{children:'"background_page"'}),", will not be listed here. You can find them using ",(0,n.jsx)(r.a,{href:"/api/puppeteer.target.page",children:"Target.page()"}),"."]})]})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"setcookie",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.setcookie",children:"setCookie(cookies)"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:"Sets a cookie in the browser context."})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"setpermission",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.setpermission",children:"setPermission(origin, permissions)"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsx)(r.p,{children:"Sets the permission for a specific origin."})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"targets",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.targets",children:"targets()"})})}),(0,n.jsx)("td",{}),(0,n.jsx)("td",{children:(0,n.jsxs)(r.p,{children:["Gets all active ",(0,n.jsx)(r.a,{href:"/api/puppeteer.target",children:"targets"})," inside this ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser context"}),"."]})})]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:(0,n.jsx)("span",{id:"waitfortarget",children:(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext.waitfortarget",children:"waitForTarget(predicate, options)"})})}),(0,n.jsx)("td",{}),(0,n.jsxs)("td",{children:[(0,n.jsxs)(r.p,{children:["Waits until a ",(0,n.jsx)(r.a,{href:"/api/puppeteer.target",children:"target"})," matching the given ",(0,n.jsx)(r.code,{children:"predicate"})," appears and returns it."]}),(0,n.jsxs)(r.p,{children:["This will look all open ",(0,n.jsx)(r.a,{href:"/api/puppeteer.browsercontext",children:"browser contexts"}),"."]})]})]})]})]})]})}function h(e={}){let{wrapper:r}={...(0,i.R)(),...e.components};return r?(0,n.jsx)(r,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},28453(e,r,s){s.d(r,{R:()=>o,x:()=>d});var t=s(96540);let n={},i=t.createContext(n);function o(e){let r=t.useContext(i);return t.useMemo(function(){return"function"==typeof e?e(r):{...r,...e}},[r,e])}function d(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:o(e.components),t.createElement(i.Provider,{value:r},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.