mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: deprecate Page.prototype.target
(#11872)
This commit is contained in:
parent
86c3988e26
commit
15c986c2bc
@ -4,6 +4,10 @@ sidebar_label: Page.target
|
|||||||
|
|
||||||
# Page.target() method
|
# Page.target() method
|
||||||
|
|
||||||
|
> Warning: This API is now obsolete.
|
||||||
|
>
|
||||||
|
> Use [Page.createCDPSession()](./puppeteer.page.createcdpsession.md) directly.
|
||||||
|
|
||||||
A target this page was created from.
|
A target this page was created from.
|
||||||
|
|
||||||
#### Signature:
|
#### Signature:
|
||||||
|
@ -757,6 +757,8 @@ export abstract class Page extends EventEmitter<PageEvents> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A target this page was created from.
|
* A target this page was created from.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link Page.createCDPSession} directly.
|
||||||
*/
|
*/
|
||||||
abstract target(): Target;
|
abstract target(): Target;
|
||||||
|
|
||||||
|
@ -181,9 +181,9 @@ describe('BrowserContext', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(context1.targets()).toHaveLength(1);
|
expect(context1.targets()).toHaveLength(1);
|
||||||
expect(context1.targets()[0]).toBe(page1.target());
|
expect(await context1.targets()[0]?.page()).toBe(page1);
|
||||||
expect(context2.targets()).toHaveLength(1);
|
expect(context2.targets()).toHaveLength(1);
|
||||||
expect(context2.targets()[0]).toBe(page2.target());
|
expect(await context2.targets()[0]?.page()).toBe(page2);
|
||||||
|
|
||||||
// Make sure pages don't share localstorage or cookies.
|
// Make sure pages don't share localstorage or cookies.
|
||||||
expect(
|
expect(
|
||||||
|
@ -472,7 +472,7 @@ describe('OOPIF', function () {
|
|||||||
const {server, page} = state;
|
const {server, page} = state;
|
||||||
|
|
||||||
// Setup our session listeners to observe OOPIF activity.
|
// Setup our session listeners to observe OOPIF activity.
|
||||||
const session = await page.target().createCDPSession();
|
const session = await page.createCDPSession();
|
||||||
const networkEvents: string[] = [];
|
const networkEvents: string[] = [];
|
||||||
const otherSessions: CDPSession[] = [];
|
const otherSessions: CDPSession[] = [];
|
||||||
await session.send('Target.setAutoAttach', {
|
await session.send('Target.setAutoAttach', {
|
||||||
|
@ -583,14 +583,10 @@ describe('Page', function () {
|
|||||||
// 3. After that, remove the iframe.
|
// 3. After that, remove the iframe.
|
||||||
frame.remove();
|
frame.remove();
|
||||||
});
|
});
|
||||||
const popupTarget = page
|
// 4. The target should always be the last one.
|
||||||
.browserContext()
|
const popupTarget = page.browserContext().targets().at(-1)!;
|
||||||
.targets()
|
// 5. Connect to the popup and make sure it doesn't throw and is not the same page.
|
||||||
.find(target => {
|
expect(await popupTarget.page()).not.toBe(page);
|
||||||
return target !== page.target();
|
|
||||||
})!;
|
|
||||||
// 4. Connect to the popup and make sure it doesn't throw.
|
|
||||||
await popupTarget.page();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ describe('request interception', function () {
|
|||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
await page.setRequestInterception(true);
|
await page.setRequestInterception(true);
|
||||||
|
|
||||||
const cdp = await page.target().createCDPSession();
|
const cdp = await page.createCDPSession();
|
||||||
await cdp.send('DOM.enable');
|
await cdp.send('DOM.enable');
|
||||||
const urls: string[] = [];
|
const urls: string[] = [];
|
||||||
page.on('request', request => {
|
page.on('request', request => {
|
||||||
|
Loading…
Reference in New Issue
Block a user