Skip to content

Commit 4c2fc6b

Browse files
authored
feat(browser): add Browser.BrowserType() method (#14468)
1 parent 7e130d0 commit 4c2fc6b

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

docs/src/api/class-browser.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ Emitted when Browser gets disconnected from the browser application. This might
7979
* Browser application is closed or crashed.
8080
* The [`method: Browser.close`] method was called.
8181

82+
## method: Browser.browserType
83+
- returns: <[BrowserType]>
84+
85+
Get the browser type (chromium, firefox or webkit) that the browser belongs to.
86+
8287
## async method: Browser.close
8388

8489
In case this browser is obtained using [`method: BrowserType.launch`], closes the browser and all of its pages (if any

packages/playwright-core/src/client/browser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
5656
context._setBrowserType(browserType);
5757
}
5858

59+
browserType(): BrowserType {
60+
return this._browserType;
61+
}
62+
5963
async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {
6064
options = { ...this._browserType._defaultContextOptions, ...options };
6165
const contextOptions = await prepareBrowserContextParams(options);

packages/playwright-core/types/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12746,6 +12746,11 @@ export interface Browser extends EventEmitter {
1274612746
*/
1274712747
off(event: 'disconnected', listener: (browser: Browser) => void): this;
1274812748

12749+
/**
12750+
* Get the browser type (chromium, firefox or webkit) that the browser belongs to.
12751+
*/
12752+
browserType(): BrowserType;
12753+
1274912754
/**
1275012755
* In case this browser is obtained using
1275112756
* [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browser-type-launch), closes the

tests/library/browser.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
import { browserTest as test, expect } from '../config/browserTest';
1818

19+
test('should return browserType', function({ browser, browserType }) {
20+
expect(browser.browserType()).toBe(browserType);
21+
});
22+
1923
test('should create new page @smoke', async function({ browser }) {
2024
const page1 = await browser.newPage();
2125
expect(browser.contexts().length).toBe(1);

0 commit comments

Comments
 (0)