2022-07-05 13:41:43 +00:00
---
sidebar_label: BrowserContext
---
# BrowserContext class
2024-02-05 09:43:37 +00:00
[BrowserContext ](./puppeteer.browsercontext.md ) represents individual user contexts within a [browser ](./puppeteer.browser.md ).
2023-09-18 18:11:55 +00:00
2024-02-05 09:43:37 +00:00
When a [browser ](./puppeteer.browser.md ) is launched, it has a single [browser context ](./puppeteer.browsercontext.md ) by default. Others can be created using [Browser.createBrowserContext() ](./puppeteer.browser.createbrowsercontext.md ). Each context has isolated storage (cookies/localStorage/etc.)
2023-09-18 18:11:55 +00:00
[BrowserContext ](./puppeteer.browsercontext.md ) [emits ](./puppeteer.eventemitter.md ) various events which are documented in the [BrowserContextEvent ](./puppeteer.browsercontextevent.md ) enum.
If a [page ](./puppeteer.page.md ) opens another [page ](./puppeteer.page.md ), e.g. using `window.open` , the popup will belong to the parent [page's browser context ](./puppeteer.page.browsercontext.md ).
2022-07-05 13:41:43 +00:00
2022-10-24 07:07:05 +00:00
#### Signature:
2022-07-05 13:41:43 +00:00
```typescript
2023-09-18 18:11:55 +00:00
export declare abstract class BrowserContext extends EventEmitter< BrowserContextEvents >
2022-07-05 13:41:43 +00:00
```
2023-09-13 13:47:55 +00:00
**Extends:** [EventEmitter ](./puppeteer.eventemitter.md )< [BrowserContextEvents](./puppeteer.browsercontextevents.md)>
2022-07-05 13:41:43 +00:00
## Remarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `BrowserContext` class.
## Example
2024-02-05 09:43:37 +00:00
Creating a new [browser context ](./puppeteer.browsercontext.md ):
2023-09-18 18:11:55 +00:00
2022-07-05 13:41:43 +00:00
```ts
2024-02-05 09:43:37 +00:00
// Create a new browser context
const context = await browser.createBrowserContext();
2022-07-05 13:41:43 +00:00
// Create a new page inside context.
const page = await context.newPage();
// ... do stuff with page ...
await page.goto('https://example.com');
// Dispose context once it's no longer needed.
await context.close();
```
2022-10-19 08:30:57 +00:00
## Properties
2024-03-20 15:03:14 +00:00
< table > < thead > < tr > < th >
Property
< / th > < th >
Modifiers
< / th > < th >
Type
< / th > < th >
Description
< / th > < / tr > < / thead >
< tbody > < tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "closed" > closed< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
`readonly`
< / td > < td >
boolean
< / td > < td >
Whether this [browser context ](./puppeteer.browsercontext.md ) is closed.
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "id" > id< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
`readonly`
< / td > < td >
string \| undefined
< / td > < td >
Identifier for this [browser context ](./puppeteer.browsercontext.md ).
< / td > < / tr >
< / tbody > < / table >
2022-10-19 08:30:57 +00:00
2022-07-05 13:41:43 +00:00
## Methods
2024-03-20 15:03:14 +00:00
< table > < thead > < tr > < th >
Method
< / th > < th >
Modifiers
< / th > < th >
Description
< / th > < / tr > < / thead >
< tbody > < tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "browser" > [browser()](./puppeteer.browsercontext.browser.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Gets the [browser ](./puppeteer.browser.md ) associated with this [browser context ](./puppeteer.browsercontext.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "clearpermissionoverrides" > [clearPermissionOverrides()](./puppeteer.browsercontext.clearpermissionoverrides.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Clears all permission overrides for this [browser context ](./puppeteer.browsercontext.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "close" > [close()](./puppeteer.browsercontext.close.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Closes this [browser context ](./puppeteer.browsercontext.md ) and all associated [pages ](./puppeteer.page.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "isincognito" > [isIncognito()](./puppeteer.browsercontext.isincognito.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
2024-04-04 07:17:26 +00:00
`deprecated`
2024-03-20 15:03:14 +00:00
< / td > < td >
Whether this [browser context ](./puppeteer.browsercontext.md ) is incognito.
In Chrome, the [default browser context ](./puppeteer.browser.defaultbrowsercontext.md ) is the only non-incognito browser context.
2024-04-04 07:17:26 +00:00
**Deprecated:**
2024-04-09 10:36:02 +00:00
In Chrome, the [default browser context ](./puppeteer.browser.defaultbrowsercontext.md ) can also be "incognito" if configured via the arguments and in such cases this getter returns wrong results (see https://github.com/puppeteer/puppeteer/issues/8836). Also, the term "incognito" is not applicable to other browsers. To migrate, check the [default browser context ](./puppeteer.browser.defaultbrowsercontext.md ) instead: in Chrome all non-default contexts are incognito, and the default context might be incognito if you provide the `--incognito` argument when launching the browser.
2024-04-04 07:17:26 +00:00
2024-03-20 15:03:14 +00:00
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "newpage" > [newPage()](./puppeteer.browsercontext.newpage.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Creates a new [page ](./puppeteer.page.md ) in this [browser context ](./puppeteer.browsercontext.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "overridepermissions" > [overridePermissions(origin, permissions)](./puppeteer.browsercontext.overridepermissions.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Grants this [browser context ](./puppeteer.browsercontext.md ) the given `permissions` within the given `origin` .
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "pages" > [pages()](./puppeteer.browsercontext.pages.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Gets a list of all open [pages ](./puppeteer.page.md ) inside this [browser context ](./puppeteer.browsercontext.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "targets" > [targets()](./puppeteer.browsercontext.targets.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Gets all active [targets ](./puppeteer.target.md ) inside this [browser context ](./puppeteer.browsercontext.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "waitfortarget" > [waitForTarget(predicate, options)](./puppeteer.browsercontext.waitfortarget.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Waits until a [target ](./puppeteer.target.md ) matching the given `predicate` appears and returns it.
This will look all open [browser contexts ](./puppeteer.browsercontext.md ).
< / td > < / tr >
< / tbody > < / table >