feat(target): add support for target.page for 'backgroud_page' (#2600)

This patch teaches `target.page()` method to attach to extension background pages.

Fixes #2438
This commit is contained in:
Yaniv Efraim
2018-06-14 23:58:51 +03:00
committed by Andrey Lushnikov
parent cd8d750628
commit 38f112f395
4 changed files with 16 additions and 4 deletions

View File

@@ -51,6 +51,14 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro
await browserWithExtension.close();
expect(backgroundPageTarget).toBeTruthy();
});
it('target.page() should return a background_page', async({browser}) => {
const browserWithExtension = await puppeteer.launch(extensionOptions);
const targets = await browserWithExtension.targets();
const backgroundPageTarget = targets.find(target => target.type() === 'background_page');
const page = await backgroundPageTarget.page();
expect(await page.evaluate(() => 2 * 3)).toBe(6);
await browserWithExtension.close();
});
it('should have default url when launching browser', async function() {
const browser = await puppeteer.launch(extensionOptions);
const pages = (await browser.pages()).map(page => page.url());