diff --git a/docs/api/puppeteer.browsercontext.id.md b/docs/api/puppeteer.browsercontext.id.md
new file mode 100644
index 00000000000..852039c2042
--- /dev/null
+++ b/docs/api/puppeteer.browsercontext.id.md
@@ -0,0 +1,13 @@
+---
+sidebar_label: BrowserContext.id
+---
+
+# BrowserContext.id property
+
+**Signature:**
+
+```typescript
+class BrowserContext {
+ get id(): string | undefined;
+}
+```
diff --git a/docs/api/puppeteer.browsercontext.md b/docs/api/puppeteer.browsercontext.md
index 2374e40cdec..995948371cd 100644
--- a/docs/api/puppeteer.browsercontext.md
+++ b/docs/api/puppeteer.browsercontext.md
@@ -37,6 +37,12 @@ await page.goto('https://example.com');
await context.close();
```
+## Properties
+
+| Property | Modifiers | Type | Description |
+| -------------------------------------- | --------------------- | ------------------- | ----------- |
+| [id](./puppeteer.browsercontext.id.md) | readonly
| string \| undefined | |
+
## Methods
| Method | Modifiers | Description |
diff --git a/packages/puppeteer-core/src/api/BrowserContext.ts b/packages/puppeteer-core/src/api/BrowserContext.ts
index b525fc23be8..56868760db7 100644
--- a/packages/puppeteer-core/src/api/BrowserContext.ts
+++ b/packages/puppeteer-core/src/api/BrowserContext.ts
@@ -178,4 +178,8 @@ export class BrowserContext extends EventEmitter {
close(): Promise {
throw new Error('Not implemented');
}
+
+ get id(): string | undefined {
+ return undefined;
+ }
}
diff --git a/packages/puppeteer-core/src/common/Browser.ts b/packages/puppeteer-core/src/common/Browser.ts
index 2430b68f9c8..c3052e7a7af 100644
--- a/packages/puppeteer-core/src/common/Browser.ts
+++ b/packages/puppeteer-core/src/common/Browser.ts
@@ -596,6 +596,10 @@ export class CDPBrowserContext extends BrowserContext {
this.#id = contextId;
}
+ override get id(): string | undefined {
+ return this.#id;
+ }
+
/**
* An array of all active targets inside the browser context.
*/
diff --git a/test/src/browsercontext.spec.ts b/test/src/browsercontext.spec.ts
index 45e2ddc86f0..2c9f01f02e1 100644
--- a/test/src/browsercontext.spec.ts
+++ b/test/src/browsercontext.spec.ts
@@ -227,4 +227,16 @@ describe('BrowserContext', function () {
remoteBrowser.disconnect();
await context.close();
});
+
+ it('should provide a context id', async () => {
+ const {browser} = getTestState();
+
+ expect(browser.browserContexts().length).toBe(1);
+ expect(browser.browserContexts()[0]!.id).toBeUndefined();
+
+ const context = await browser.createIncognitoBrowserContext();
+ expect(browser.browserContexts().length).toBe(2);
+ expect(browser.browserContexts()[1]!.id).toBeDefined();
+ await context.close();
+ });
});