summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/packages/puppeteer-core/src/api/Target.ts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /remote/test/puppeteer/packages/puppeteer-core/src/api/Target.ts
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/test/puppeteer/packages/puppeteer-core/src/api/Target.ts')
-rw-r--r--remote/test/puppeteer/packages/puppeteer-core/src/api/Target.ts95
1 files changed, 95 insertions, 0 deletions
diff --git a/remote/test/puppeteer/packages/puppeteer-core/src/api/Target.ts b/remote/test/puppeteer/packages/puppeteer-core/src/api/Target.ts
new file mode 100644
index 0000000000..f91b91df12
--- /dev/null
+++ b/remote/test/puppeteer/packages/puppeteer-core/src/api/Target.ts
@@ -0,0 +1,95 @@
+/**
+ * @license
+ * Copyright 2023 Google Inc.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import type {Browser} from './Browser.js';
+import type {BrowserContext} from './BrowserContext.js';
+import type {CDPSession} from './CDPSession.js';
+import type {Page} from './Page.js';
+import type {WebWorker} from './WebWorker.js';
+
+/**
+ * @public
+ */
+export enum TargetType {
+ PAGE = 'page',
+ BACKGROUND_PAGE = 'background_page',
+ SERVICE_WORKER = 'service_worker',
+ SHARED_WORKER = 'shared_worker',
+ BROWSER = 'browser',
+ WEBVIEW = 'webview',
+ OTHER = 'other',
+ /**
+ * @internal
+ */
+ TAB = 'tab',
+}
+
+/**
+ * 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
+ */
+export abstract class Target {
+ /**
+ * @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;
+ }
+
+ /**
+ * 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>;
+
+ abstract url(): string;
+
+ /**
+ * Creates a Chrome Devtools Protocol session attached to the target.
+ */
+ abstract createCDPSession(): Promise<CDPSession>;
+
+ /**
+ * Identifies what kind of target this is.
+ *
+ * @remarks
+ *
+ * See {@link https://developer.chrome.com/extensions/background_pages | docs} for more info about background pages.
+ */
+ abstract type(): TargetType;
+
+ /**
+ * Get the browser the target belongs to.
+ */
+ abstract browser(): Browser;
+
+ /**
+ * Get the browser context the target belongs to.
+ */
+ abstract browserContext(): BrowserContext;
+
+ /**
+ * Get the target that opened this target. Top-level targets return `null`.
+ */
+ abstract opener(): Target | undefined;
+}