mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
parent
51b2f0576d
commit
2a0eefb99f
@ -317,11 +317,12 @@ export class ChromeTargetManager extends EventEmitter implements TargetManager {
|
|||||||
) {
|
) {
|
||||||
this.#finishInitializationIfReady(targetInfo.targetId);
|
this.#finishInitializationIfReady(targetInfo.targetId);
|
||||||
await silentDetach();
|
await silentDetach();
|
||||||
if (parentSession instanceof CDPSession) {
|
if (this.#attachedTargetsByTargetId.has(targetInfo.targetId)) {
|
||||||
const target = this.#targetFactory(targetInfo);
|
return;
|
||||||
this.#attachedTargetsByTargetId.set(targetInfo.targetId, target);
|
|
||||||
this.emit(TargetManagerEmittedEvents.TargetAvailable, target);
|
|
||||||
}
|
}
|
||||||
|
const target = this.#targetFactory(targetInfo);
|
||||||
|
this.#attachedTargetsByTargetId.set(targetInfo.targetId, target);
|
||||||
|
this.emit(TargetManagerEmittedEvents.TargetAvailable, target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
test/assets/serviceworkers/extension/background.js
Normal file
1
test/assets/serviceworkers/extension/background.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
// empty
|
9
test/assets/serviceworkers/extension/manifest.json
Normal file
9
test/assets/serviceworkers/extension/manifest.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "Simple extension",
|
||||||
|
"version": "0.1",
|
||||||
|
"background": {
|
||||||
|
"service_worker": "background.js"
|
||||||
|
},
|
||||||
|
"permissions": ["background", "activeTab"],
|
||||||
|
"manifest_version": 3
|
||||||
|
}
|
@ -36,6 +36,13 @@ const mkdtempAsync = promisify(fs.mkdtemp);
|
|||||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||||
|
|
||||||
const extensionPath = path.join(__dirname, '../assets', 'simple-extension');
|
const extensionPath = path.join(__dirname, '../assets', 'simple-extension');
|
||||||
|
const serviceWorkerExtensionPath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'assets',
|
||||||
|
'serviceworkers',
|
||||||
|
'extension'
|
||||||
|
);
|
||||||
|
|
||||||
describeChromeOnly('headful tests', function () {
|
describeChromeOnly('headful tests', function () {
|
||||||
/* These tests fire up an actual browser so let's
|
/* These tests fire up an actual browser so let's
|
||||||
@ -120,7 +127,7 @@ describeChromeOnly('headful tests', function () {
|
|||||||
);
|
);
|
||||||
const page = await browserWithExtension.newPage();
|
const page = await browserWithExtension.newPage();
|
||||||
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
||||||
(target: {type: () => string}) => {
|
target => {
|
||||||
return target.type() === 'background_page';
|
return target.type() === 'background_page';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -128,6 +135,26 @@ describeChromeOnly('headful tests', function () {
|
|||||||
await browserWithExtension.close();
|
await browserWithExtension.close();
|
||||||
expect(backgroundPageTarget).toBeTruthy();
|
expect(backgroundPageTarget).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
it('service_worker target type should be available', async () => {
|
||||||
|
const {puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
|
const browserWithExtension = await launchBrowser(puppeteer, {
|
||||||
|
...defaultBrowserOptions,
|
||||||
|
headless: false,
|
||||||
|
args: [
|
||||||
|
`--disable-extensions-except=${serviceWorkerExtensionPath}`,
|
||||||
|
`--load-extension=${serviceWorkerExtensionPath}`,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const page = await browserWithExtension.newPage();
|
||||||
|
const serviceWorkerTarget = await browserWithExtension.waitForTarget(
|
||||||
|
target => {
|
||||||
|
return target.type() === 'service_worker';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
await page.close();
|
||||||
|
await browserWithExtension.close();
|
||||||
|
expect(serviceWorkerTarget).toBeTruthy();
|
||||||
|
});
|
||||||
it('target.page() should return a background_page', async function () {
|
it('target.page() should return a background_page', async function () {
|
||||||
const {puppeteer} = getTestState();
|
const {puppeteer} = getTestState();
|
||||||
const browserWithExtension = await launchBrowser(
|
const browserWithExtension = await launchBrowser(
|
||||||
@ -135,7 +162,7 @@ describeChromeOnly('headful tests', function () {
|
|||||||
extensionOptions
|
extensionOptions
|
||||||
);
|
);
|
||||||
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
||||||
(target: {type: () => string}) => {
|
target => {
|
||||||
return target.type() === 'background_page';
|
return target.type() === 'background_page';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user