mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(Targets): expose browser target (#2036)
This patch exposes "browser" target to the list of targets.
This commit is contained in:
parent
e8a085ccfb
commit
fc94f98247
@ -2483,7 +2483,7 @@ If the target is not of type `"page"`, returns `null`.
|
|||||||
#### target.type()
|
#### target.type()
|
||||||
- returns: <[string]>
|
- 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()
|
#### target.url()
|
||||||
- returns: <[string]>
|
- returns: <[string]>
|
||||||
|
@ -229,11 +229,11 @@ class Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {"page"|"service_worker"|"other"}
|
* @return {"page"|"service_worker"|"other"|"browser"}
|
||||||
*/
|
*/
|
||||||
type() {
|
type() {
|
||||||
const type = this._targetInfo.type;
|
const type = this._targetInfo.type;
|
||||||
if (type === 'page' || type === 'service_worker')
|
if (type === 'page' || type === 'service_worker' || type === 'browser')
|
||||||
return type;
|
return type;
|
||||||
return 'other';
|
return 'other';
|
||||||
}
|
}
|
||||||
|
@ -3608,8 +3608,7 @@ describe('Page', function() {
|
|||||||
const targets = browser.targets();
|
const targets = browser.targets();
|
||||||
expect(targets.some(target => target.type() === 'page' &&
|
expect(targets.some(target => target.type() === 'page' &&
|
||||||
target.url() === 'about:blank')).toBeTruthy('Missing blank page');
|
target.url() === 'about:blank')).toBeTruthy('Missing blank page');
|
||||||
expect(targets.some(target => target.type() === 'other' &&
|
expect(targets.some(target => target.type() === 'browser')).toBeTruthy('Missing browser target');
|
||||||
target.url() === '')).toBeTruthy('Missing browser target');
|
|
||||||
});
|
});
|
||||||
it('Browser.pages should return all of the pages', async({page, server, browser}) => {
|
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
|
// The pages will be the testing page and the original newtab page
|
||||||
@ -3618,6 +3617,11 @@ describe('Page', function() {
|
|||||||
expect(allPages).toContain(page);
|
expect(allPages).toContain(page);
|
||||||
expect(allPages[0]).not.toBe(allPages[1]);
|
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}) => {
|
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
|
// The pages will be the testing page and the original newtab page
|
||||||
const allPages = await browser.pages();
|
const allPages = await browser.pages();
|
||||||
|
Loading…
Reference in New Issue
Block a user