puppeteer-core
Version:
A high-level API to control headless Chrome over the DevTools Protocol
171 lines (156 loc) • 4.01 kB
text/typescript
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {Target, TargetType} from '../api/Target.js';
import {UnsupportedOperation} from '../common/Errors.js';
import type {CDPSession} from '../puppeteer-core.js';
import type {BidiBrowser} from './Browser.js';
import type {BidiBrowserContext} from './BrowserContext.js';
import type {BidiFrame} from './Frame.js';
import {BidiPage} from './Page.js';
import type {BidiWebWorker} from './WebWorker.js';
/**
* @internal
*/
export class BidiBrowserTarget extends Target {
constructor(browser: BidiBrowser) {
super();
this.
}
override asPage(): Promise<BidiPage> {
throw new UnsupportedOperation();
}
override url(): string {
return '';
}
override createCDPSession(): Promise<CDPSession> {
throw new UnsupportedOperation();
}
override type(): TargetType {
return TargetType.BROWSER;
}
override browser(): BidiBrowser {
return this.
}
override browserContext(): BidiBrowserContext {
return this.
}
override opener(): Target | undefined {
throw new UnsupportedOperation();
}
}
/**
* @internal
*/
export class BidiPageTarget extends Target {
constructor(page: BidiPage) {
super();
this.
}
override async page(): Promise<BidiPage> {
return this.
}
override async asPage(): Promise<BidiPage> {
return BidiPage.from(
this.browserContext(),
this.
);
}
override url(): string {
return this.
}
override createCDPSession(): Promise<CDPSession> {
return this.
}
override type(): TargetType {
return TargetType.PAGE;
}
override browser(): BidiBrowser {
return this.browserContext().browser();
}
override browserContext(): BidiBrowserContext {
return this.
}
override opener(): Target | undefined {
throw new UnsupportedOperation();
}
}
/**
* @internal
*/
export class BidiFrameTarget extends Target {
constructor(frame: BidiFrame) {
super();
this.
}
override async page(): Promise<BidiPage> {
if (this.
this.
this.browserContext(),
this.
);
}
return this.
}
override async asPage(): Promise<BidiPage> {
return BidiPage.from(this.browserContext(), this.
}
override url(): string {
return this.
}
override createCDPSession(): Promise<CDPSession> {
return this.
}
override type(): TargetType {
return TargetType.PAGE;
}
override browser(): BidiBrowser {
return this.browserContext().browser();
}
override browserContext(): BidiBrowserContext {
return this.
}
override opener(): Target | undefined {
throw new UnsupportedOperation();
}
}
/**
* @internal
*/
export class BidiWorkerTarget extends Target {
constructor(worker: BidiWebWorker) {
super();
this.
}
override async page(): Promise<BidiPage> {
throw new UnsupportedOperation();
}
override async asPage(): Promise<BidiPage> {
throw new UnsupportedOperation();
}
override url(): string {
return this.
}
override createCDPSession(): Promise<CDPSession> {
throw new UnsupportedOperation();
}
override type(): TargetType {
return TargetType.OTHER;
}
override browser(): BidiBrowser {
return this.browserContext().browser();
}
override browserContext(): BidiBrowserContext {
return this.
}
override opener(): Target | undefined {
throw new UnsupportedOperation();
}
}