Skip to content

Commit

Permalink
feat(Targets): expose browser target (puppeteer#2036)
Browse files Browse the repository at this point in the history
This patch exposes "browser" target to the list of targets.
  • Loading branch information
aslushnikov authored Feb 15, 2018
1 parent e8a085c commit fc94f98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ If the target is not of type `"page"`, returns `null`.
#### target.type()
- returns: <[string]>

Identifies what kind of target this is. Can be `"page"`, `"service_worker"`, or `"other"`.
Identifies what kind of target this is. Can be `"page"`, `"service_worker"`, `"browser"` or `"other"`.

#### target.url()
- returns: <[string]>
Expand Down
4 changes: 2 additions & 2 deletions lib/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ class Target {
}

/**
* @return {"page"|"service_worker"|"other"}
* @return {"page"|"service_worker"|"other"|"browser"}
*/
type() {
const type = this._targetInfo.type;
if (type === 'page' || type === 'service_worker')
if (type === 'page' || type === 'service_worker' || type === 'browser')
return type;
return 'other';
}
Expand Down
8 changes: 6 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3608,8 +3608,7 @@ describe('Page', function() {
const targets = browser.targets();
expect(targets.some(target => target.type() === 'page' &&
target.url() === 'about:blank')).toBeTruthy('Missing blank page');
expect(targets.some(target => target.type() === 'other' &&
target.url() === '')).toBeTruthy('Missing browser target');
expect(targets.some(target => target.type() === 'browser')).toBeTruthy('Missing browser target');
});
it('Browser.pages should return all of the pages', async({page, server, browser}) => {
// The pages will be the testing page and the original newtab page
Expand All @@ -3618,6 +3617,11 @@ describe('Page', function() {
expect(allPages).toContain(page);
expect(allPages[0]).not.toBe(allPages[1]);
});
it('should contain browser target', async({browser}) => {
const targets = browser.targets();
const browserTarget = targets.find(target => target.type() === 'browser');
expect(browserTarget).toBeTruthy();
});
it('should be able to use the default page in the browser', async({page, server, browser}) => {
// The pages will be the testing page and the original newtab page
const allPages = await browser.pages();
Expand Down

0 comments on commit fc94f98

Please sign in to comment.