mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: expose DevTools as a target (#10812)
This commit is contained in:
parent
14f0ab7397
commit
a540085176
@ -45,6 +45,7 @@ import {
|
|||||||
PageTarget,
|
PageTarget,
|
||||||
CDPTarget,
|
CDPTarget,
|
||||||
WorkerTarget,
|
WorkerTarget,
|
||||||
|
DevToolsTarget,
|
||||||
} from './Target.js';
|
} from './Target.js';
|
||||||
import {TargetManager, TargetManagerEmittedEvents} from './TargetManager.js';
|
import {TargetManager, TargetManagerEmittedEvents} from './TargetManager.js';
|
||||||
import {TaskQueue} from './TaskQueue.js';
|
import {TaskQueue} from './TaskQueue.js';
|
||||||
@ -340,6 +341,18 @@ export class CDPBrowser extends BrowserBase {
|
|||||||
this.#targetManager,
|
this.#targetManager,
|
||||||
createSession
|
createSession
|
||||||
);
|
);
|
||||||
|
if (targetInfo.url?.startsWith('devtools://')) {
|
||||||
|
return new DevToolsTarget(
|
||||||
|
targetInfo,
|
||||||
|
session,
|
||||||
|
context,
|
||||||
|
this.#targetManager,
|
||||||
|
createSession,
|
||||||
|
this.#ignoreHTTPSErrors,
|
||||||
|
this.#defaultViewport ?? null,
|
||||||
|
this.#screenshotTaskQueue
|
||||||
|
);
|
||||||
|
}
|
||||||
if (this.#isPageTargetCallback(targetForFilter)) {
|
if (this.#isPageTargetCallback(targetForFilter)) {
|
||||||
return new PageTarget(
|
return new PageTarget(
|
||||||
targetInfo,
|
targetInfo,
|
||||||
|
@ -299,6 +299,11 @@ export class PageTarget extends CDPTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export class DevToolsTarget extends PageTarget {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
@ -340,6 +340,26 @@ const serviceWorkerExtensionPath = path.join(
|
|||||||
]);
|
]);
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
it('should expose DevTools as a page', async () => {
|
||||||
|
const browser = await launchBrowser(
|
||||||
|
Object.assign({devtools: true}, headfulOptions)
|
||||||
|
);
|
||||||
|
const context = await browser.createIncognitoBrowserContext();
|
||||||
|
const [target] = await Promise.all([
|
||||||
|
browser.waitForTarget((target: {url: () => string | string[]}) => {
|
||||||
|
return target.url().includes('devtools://');
|
||||||
|
}),
|
||||||
|
context.newPage(),
|
||||||
|
]);
|
||||||
|
const page = await target.page();
|
||||||
|
expect(
|
||||||
|
await page?.evaluate(() => {
|
||||||
|
// @ts-expect-error wrong context.
|
||||||
|
return Boolean(DevToolsAPI);
|
||||||
|
})
|
||||||
|
).toBe(true);
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Page.bringToFront', function () {
|
describe('Page.bringToFront', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user