mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
parent
3b03ff65c7
commit
23d25a6e12
@ -2741,7 +2741,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"`, `"browser"` or `"other"`.
|
Identifies what kind of target this is. Can be `"page"`, [`"background_page"`](https://developer.chrome.com/extensions/background_pages), `"service_worker"`, `"browser"` or `"other"`.
|
||||||
|
|
||||||
#### target.url()
|
#### target.url()
|
||||||
- returns: <[string]>
|
- returns: <[string]>
|
||||||
|
@ -53,11 +53,11 @@ class Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {"page"|"service_worker"|"other"|"browser"}
|
* @return {"page"|"background_page"|"service_worker"|"other"|"browser"}
|
||||||
*/
|
*/
|
||||||
type() {
|
type() {
|
||||||
const type = this._targetInfo.type;
|
const type = this._targetInfo.type;
|
||||||
if (type === 'page' || type === 'service_worker' || type === 'browser')
|
if (type === 'page' || type === 'background_page' || type === 'service_worker' || type === 'browser')
|
||||||
return type;
|
return type;
|
||||||
return 'other';
|
return 'other';
|
||||||
}
|
}
|
||||||
|
1
test/assets/simple-extension/index.js
Normal file
1
test/assets/simple-extension/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
// Mock script for background extension
|
12
test/assets/simple-extension/manifest.json
Normal file
12
test/assets/simple-extension/manifest.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "Simple extension",
|
||||||
|
"version": "0.1",
|
||||||
|
"app": {
|
||||||
|
"background": {
|
||||||
|
"scripts": ["index.js"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"permissions": ["background"],
|
||||||
|
|
||||||
|
"manifest_version": 2
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
const {waitEvent} = require('./utils');
|
const {waitEvent} = require('./utils');
|
||||||
|
|
||||||
module.exports.addTests = function({testRunner, expect}) {
|
module.exports.addTests = function({testRunner, expect, puppeteer, browserWithExtensionOptions}) {
|
||||||
const {describe, xdescribe, fdescribe} = testRunner;
|
const {describe, xdescribe, fdescribe} = testRunner;
|
||||||
const {it, fit, xit} = testRunner;
|
const {it, fit, xit} = testRunner;
|
||||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||||
@ -36,6 +36,15 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
expect(allPages).toContain(page);
|
expect(allPages).toContain(page);
|
||||||
expect(allPages[0]).not.toBe(allPages[1]);
|
expect(allPages[0]).not.toBe(allPages[1]);
|
||||||
});
|
});
|
||||||
|
it('should allow background_page target type to pass through', async({browser}) => {
|
||||||
|
const browserWithExtension = await puppeteer.launch(browserWithExtensionOptions);
|
||||||
|
const page = await browserWithExtension.newPage();
|
||||||
|
const targets = await browserWithExtension.targets();
|
||||||
|
const backgroundPageTarget = targets.find(target => target.type() === 'background_page');
|
||||||
|
await page.close();
|
||||||
|
await browserWithExtension.close();
|
||||||
|
expect(backgroundPageTarget).toBeTruthy();
|
||||||
|
});
|
||||||
it('should contain browser target', async({browser}) => {
|
it('should contain browser target', async({browser}) => {
|
||||||
const targets = browser.targets();
|
const targets = browser.targets();
|
||||||
const browserTarget = targets.find(target => target.type() === 'browser');
|
const browserTarget = targets.find(target => target.type() === 'browser');
|
||||||
|
16
test/test.js
16
test/test.js
@ -35,6 +35,7 @@ const RESET_COLOR = '\x1b[0m';
|
|||||||
|
|
||||||
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
||||||
const executablePath = process.env.CHROME;
|
const executablePath = process.env.CHROME;
|
||||||
|
const extensionPath = path.resolve(__dirname, '../test/assets/simple-extension');
|
||||||
|
|
||||||
if (executablePath)
|
if (executablePath)
|
||||||
console.warn(`${YELLOW_COLOR}WARN: running tests with ${executablePath}${RESET_COLOR}`);
|
console.warn(`${YELLOW_COLOR}WARN: running tests with ${executablePath}${RESET_COLOR}`);
|
||||||
@ -48,6 +49,15 @@ const defaultBrowserOptions = {
|
|||||||
headless,
|
headless,
|
||||||
args: ['--no-sandbox']
|
args: ['--no-sandbox']
|
||||||
};
|
};
|
||||||
|
const browserWithExtensionOptions = {
|
||||||
|
headless: false,
|
||||||
|
executablePath,
|
||||||
|
args: [
|
||||||
|
'--no-sandbox',
|
||||||
|
`--disable-extensions-except=${extensionPath}`,
|
||||||
|
`--load-extension=${extensionPath}`,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
let parallel = 1;
|
let parallel = 1;
|
||||||
if (process.env.PPTR_PARALLEL_TESTS)
|
if (process.env.PPTR_PARALLEL_TESTS)
|
||||||
@ -69,7 +79,7 @@ if (fs.existsSync(OUTPUT_DIR))
|
|||||||
|
|
||||||
console.log('Testing on Node', process.version);
|
console.log('Testing on Node', process.version);
|
||||||
|
|
||||||
beforeAll(async state => {
|
beforeAll(async state => {
|
||||||
const assetsPath = path.join(__dirname, 'assets');
|
const assetsPath = path.join(__dirname, 'assets');
|
||||||
const cachedPath = path.join(__dirname, 'assets', 'cached');
|
const cachedPath = path.join(__dirname, 'assets', 'cached');
|
||||||
|
|
||||||
@ -131,7 +141,7 @@ describe('Page', function() {
|
|||||||
require('./jshandle.spec.js').addTests({testRunner, expect});
|
require('./jshandle.spec.js').addTests({testRunner, expect});
|
||||||
require('./network.spec.js').addTests({testRunner, expect});
|
require('./network.spec.js').addTests({testRunner, expect});
|
||||||
require('./page.spec.js').addTests({testRunner, expect, puppeteer, DeviceDescriptors, headless});
|
require('./page.spec.js').addTests({testRunner, expect, puppeteer, DeviceDescriptors, headless});
|
||||||
require('./target.spec.js').addTests({testRunner, expect});
|
require('./target.spec.js').addTests({testRunner, expect, puppeteer, browserWithExtensionOptions});
|
||||||
require('./tracing.spec.js').addTests({testRunner, expect});
|
require('./tracing.spec.js').addTests({testRunner, expect});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -139,7 +149,7 @@ describe('Page', function() {
|
|||||||
require('./puppeteer.spec.js').addTests({testRunner, expect, PROJECT_ROOT, defaultBrowserOptions});
|
require('./puppeteer.spec.js').addTests({testRunner, expect, PROJECT_ROOT, defaultBrowserOptions});
|
||||||
|
|
||||||
if (process.env.COVERAGE) {
|
if (process.env.COVERAGE) {
|
||||||
describe('COVERAGE', function(){
|
describe('COVERAGE', function() {
|
||||||
const coverage = helper.publicAPICoverage();
|
const coverage = helper.publicAPICoverage();
|
||||||
const disabled = new Set(['page.bringToFront']);
|
const disabled = new Set(['page.bringToFront']);
|
||||||
if (!headless)
|
if (!headless)
|
||||||
|
Loading…
Reference in New Issue
Block a user