Skip to content

Commit

Permalink
feat: introduce page.browserContext() (#3655)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Dec 12, 2018
1 parent 4346fa1 commit c90392b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/api.md
Expand Up @@ -96,6 +96,7 @@
* [page.authenticate(credentials)](#pageauthenticatecredentials)
* [page.bringToFront()](#pagebringtofront)
* [page.browser()](#pagebrowser)
* [page.browserContext()](#pagebrowsercontext)
* [page.click(selector[, options])](#pageclickselector-options)
* [page.close([options])](#pagecloseoptions)
* [page.content()](#pagecontent)
Expand Down Expand Up @@ -1099,6 +1100,12 @@ Brings page to front (activates tab).

Get the browser the page belongs to.

#### page.browserContext()

- returns: <[BrowserContext]>

Get the browser context that the page belongs to.

#### page.click(selector[, options])
- `selector` <[string]> A [selector] to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.
- `options` <[Object]>
Expand Down
7 changes: 7 additions & 0 deletions lib/Page.js
Expand Up @@ -172,6 +172,13 @@ class Page extends EventEmitter {
return this._target.browser();
}

/**
* @return {!Puppeteer.BrowserContext}
*/
browserContext() {
return this._target.browserContext();
}

_onTargetCrashed() {
this.emit('error', new Error('Page crashed!'));
}
Expand Down
6 changes: 6 additions & 0 deletions test/page.spec.js
Expand Up @@ -918,4 +918,10 @@ module.exports.addTests = function({testRunner, expect, headless}) {
expect(page.browser()).toBe(browser);
});
});

describe('Page.browserContext', function() {
it('should return the correct browser instance', async function({page, context, browser}) {
expect(page.browserContext()).toBe(context);
});
});
};

0 comments on commit c90392b

Please sign in to comment.