2023-07-21 07:04:14 +00:00
|
|
|
/**
|
2024-01-03 10:11:33 +00:00
|
|
|
* @license
|
|
|
|
* Copyright 2023 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-07-21 07:04:14 +00:00
|
|
|
*/
|
|
|
|
|
2023-12-15 12:08:28 +00:00
|
|
|
import type {Browser} from './Browser.js';
|
|
|
|
import type {BrowserContext} from './BrowserContext.js';
|
2023-09-26 16:24:24 +00:00
|
|
|
import type {CDPSession} from './CDPSession.js';
|
2023-12-15 12:08:28 +00:00
|
|
|
import type {Page} from './Page.js';
|
|
|
|
import type {WebWorker} from './WebWorker.js';
|
2023-09-13 13:47:55 +00:00
|
|
|
|
2023-07-21 07:04:14 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export enum TargetType {
|
|
|
|
PAGE = 'page',
|
|
|
|
BACKGROUND_PAGE = 'background_page',
|
|
|
|
SERVICE_WORKER = 'service_worker',
|
|
|
|
SHARED_WORKER = 'shared_worker',
|
|
|
|
BROWSER = 'browser',
|
|
|
|
WEBVIEW = 'webview',
|
|
|
|
OTHER = 'other',
|
2023-08-28 06:20:57 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
TAB = 'tab',
|
2023-07-21 07:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Target represents a
|
|
|
|
* {@link https://chromedevtools.github.io/devtools-protocol/tot/Target/ | CDP target}.
|
|
|
|
* In CDP a target is something that can be debugged such a frame, a page or a
|
|
|
|
* worker.
|
|
|
|
* @public
|
|
|
|
*/
|
2023-11-09 12:57:33 +00:00
|
|
|
export abstract class Target {
|
2023-07-21 07:04:14 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
protected constructor() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the target is not of type `"service_worker"` or `"shared_worker"`, returns `null`.
|
|
|
|
*/
|
|
|
|
async worker(): Promise<WebWorker | null> {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the target is not of type `"page"`, `"webview"` or `"background_page"`,
|
|
|
|
* returns `null`.
|
|
|
|
*/
|
|
|
|
async page(): Promise<Page | null> {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-01-02 10:32:03 +00:00
|
|
|
/**
|
|
|
|
* Forcefully creates a page for a target of any type. It is useful if you
|
|
|
|
* want to handle a CDP target of type `other` as a page. If you deal with a
|
|
|
|
* regular page target, use {@link Target.page}.
|
|
|
|
*/
|
|
|
|
abstract asPage(): Promise<Page>;
|
|
|
|
|
2023-11-09 12:57:33 +00:00
|
|
|
abstract url(): string;
|
2023-07-21 07:04:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Chrome Devtools Protocol session attached to the target.
|
|
|
|
*/
|
2023-11-09 12:57:33 +00:00
|
|
|
abstract createCDPSession(): Promise<CDPSession>;
|
2023-07-21 07:04:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Identifies what kind of target this is.
|
|
|
|
*
|
|
|
|
* @remarks
|
|
|
|
*
|
|
|
|
* See {@link https://developer.chrome.com/extensions/background_pages | docs} for more info about background pages.
|
|
|
|
*/
|
2023-11-09 12:57:33 +00:00
|
|
|
abstract type(): TargetType;
|
2023-07-21 07:04:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the browser the target belongs to.
|
|
|
|
*/
|
2023-11-09 12:57:33 +00:00
|
|
|
abstract browser(): Browser;
|
2023-07-21 07:04:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the browser context the target belongs to.
|
|
|
|
*/
|
2023-11-09 12:57:33 +00:00
|
|
|
abstract browserContext(): BrowserContext;
|
2023-07-21 07:04:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the target that opened this target. Top-level targets return `null`.
|
|
|
|
*/
|
2023-11-09 12:57:33 +00:00
|
|
|
abstract opener(): Target | undefined;
|
2023-07-21 07:04:14 +00:00
|
|
|
}
|