From 09207a71b86a5ca5e98a6ae5c8dd397bd555010b Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:56:40 +0200 Subject: [PATCH] chore: separate code to semantic folders (#10914) --- docs/api/index.md | 2 +- docs/api/puppeteer.viewport.md | 2 - packages/puppeteer-core/src/api/CDPSession.ts | 2 +- .../puppeteer-core/src/api/ElementHandle.ts | 3 +- packages/puppeteer-core/src/api/Frame.ts | 15 ++--- packages/puppeteer-core/src/api/Page.ts | 61 ++++++++++++++----- packages/puppeteer-core/src/api/Target.ts | 2 +- .../src/api/locators/DelegatedLocator.ts | 2 +- .../src/api/locators/FilteredLocator.ts | 2 +- .../src/api/locators/MappedLocator.ts | 2 +- .../src/api/locators/RaceLocator.ts | 2 +- .../src/{common => }/bidi/BidiOverCdp.ts | 8 +-- .../src/{common => }/bidi/Browser.ts | 14 ++--- .../src/{common => }/bidi/BrowserContext.ts | 8 +-- .../src/{common => }/bidi/BrowsingContext.ts | 24 +++++--- .../src/{common => }/bidi/Connection.test.ts | 2 +- .../src/{common => }/bidi/Connection.ts | 10 +-- .../src/{common => }/bidi/Dialog.ts | 2 +- .../src/{common => }/bidi/ElementHandle.ts | 4 +- .../src/{common => }/bidi/EmulationManager.ts | 0 .../src/{common => }/bidi/ExposedFunction.ts | 10 +-- .../src/{common => }/bidi/Frame.ts | 16 ++--- .../src/{common => }/bidi/HTTPRequest.ts | 4 +- .../src/{common => }/bidi/HTTPResponse.ts | 4 +- .../src/{common => }/bidi/Input.ts | 6 +- .../src/{common => }/bidi/JSHandle.ts | 6 +- .../src/{common => }/bidi/NetworkManager.ts | 4 +- .../src/{common => }/bidi/Page.ts | 36 +++++------ .../src/{common => }/bidi/Realm.ts | 14 ++--- .../src/{common => }/bidi/Sandbox.ts | 10 +-- .../src/{common => }/bidi/Serializer.ts | 4 +- .../src/{common => }/bidi/Target.ts | 6 +- .../src/{common => }/bidi/bidi.ts | 0 .../{common/bidi/utils.ts => bidi/util.ts} | 5 +- .../src/{common => cdp}/Accessibility.ts | 0 .../src/{common => cdp}/AriaQueryHandler.ts | 4 +- .../src/{common => cdp}/Binding.ts | 2 +- .../src/{common => cdp}/Browser.ts | 4 +- .../src/{common => cdp}/BrowserConnector.ts | 12 ++-- .../src/{common => cdp}/CDPSession.ts | 2 +- .../{common => cdp}/ChromeTargetManager.ts | 4 +- .../src/{common => cdp}/Connection.ts | 10 +-- .../src/{common => cdp}/Coverage.ts | 5 +- .../DeviceRequestPrompt.test.ts | 6 +- .../{common => cdp}/DeviceRequestPrompt.ts | 3 +- .../src/{common => cdp}/Dialog.ts | 0 .../src/{common => cdp}/ElementHandle.ts | 2 +- .../src/{common => cdp}/EmulationManager.ts | 5 +- .../src/{common => cdp}/ExecutionContext.ts | 54 ++++++++++++---- .../{common => cdp}/FirefoxTargetManager.ts | 2 +- .../src/{common => cdp}/Frame.ts | 2 +- .../src/{common => cdp}/FrameManager.ts | 6 +- .../src/{common => cdp}/FrameTree.ts | 0 .../src/{common => cdp}/HTTPRequest.ts | 5 +- .../src/{common => cdp}/HTTPResponse.ts | 4 +- .../src/{common => cdp}/Input.ts | 5 +- .../src/{common => cdp}/IsolatedWorld.ts | 55 ++++------------- .../src/{common => cdp}/IsolatedWorlds.ts | 0 .../src/{common => cdp}/JSHandle.ts | 3 +- .../src/{common => cdp}/LifecycleWatcher.ts | 4 +- .../{common => cdp}/NetworkEventManager.ts | 0 .../{common => cdp}/NetworkManager.test.ts | 2 +- .../src/{common => cdp}/NetworkManager.ts | 9 +-- .../src/{common => cdp}/Page.ts | 48 ++++++++------- .../PredefinedNetworkConditions.ts | 0 .../src/{common => cdp}/Puppeteer.ts | 10 +-- .../src/{common => cdp}/Target.ts | 6 +- .../src/{common => cdp}/TargetManager.ts | 2 +- .../src/{common => cdp}/Tracing.ts | 6 +- .../src/{common => cdp}/WebWorker.ts | 10 +-- packages/puppeteer-core/src/cdp/cdp.ts | 51 ++++++++++++++++ packages/puppeteer-core/src/common/Device.ts | 2 +- .../src/common/GetQueryHandler.ts | 6 +- .../puppeteer-core/src/common/QueryHandler.ts | 2 +- .../{PuppeteerViewport.ts => Viewport.ts} | 3 +- packages/puppeteer-core/src/common/common.ts | 45 +++----------- packages/puppeteer-core/src/common/util.ts | 37 ----------- .../puppeteer-core/src/node/LaunchOptions.ts | 2 +- .../NodeWebSocketTransport.ts | 0 .../src/node/ProductLauncher.ts | 16 ++--- .../puppeteer-core/src/node/PuppeteerNode.ts | 8 +-- packages/puppeteer-core/src/puppeteer-core.ts | 1 + test/src/TargetManager.spec.ts | 2 +- test/src/accessibility.spec.ts | 2 +- test/src/oopif.spec.ts | 2 +- test/src/page.spec.ts | 2 +- test/src/worker.spec.ts | 2 +- 87 files changed, 394 insertions(+), 373 deletions(-) rename packages/puppeteer-core/src/{common => }/bidi/BidiOverCdp.ts (95%) rename packages/puppeteer-core/src/{common => }/bidi/Browser.ts (96%) rename packages/puppeteer-core/src/{common => }/bidi/BrowserContext.ts (94%) rename packages/puppeteer-core/src/{common => }/bidi/BrowsingContext.ts (93%) rename packages/puppeteer-core/src/{common => }/bidi/Connection.test.ts (96%) rename packages/puppeteer-core/src/{common => }/bidi/Connection.ts (96%) rename packages/puppeteer-core/src/{common => }/bidi/Dialog.ts (97%) rename packages/puppeteer-core/src/{common => }/bidi/ElementHandle.ts (94%) rename packages/puppeteer-core/src/{common => }/bidi/EmulationManager.ts (100%) rename packages/puppeteer-core/src/{common => }/bidi/ExposedFunction.ts (96%) rename packages/puppeteer-core/src/{common => }/bidi/Frame.ts (92%) rename packages/puppeteer-core/src/{common => }/bidi/HTTPRequest.ts (96%) rename packages/puppeteer-core/src/{common => }/bidi/HTTPResponse.ts (97%) rename packages/puppeteer-core/src/{common => }/bidi/Input.ts (99%) rename packages/puppeteer-core/src/{common => }/bidi/JSHandle.ts (94%) rename packages/puppeteer-core/src/{common => }/bidi/NetworkManager.ts (98%) rename packages/puppeteer-core/src/{common => }/bidi/Page.ts (95%) rename packages/puppeteer-core/src/{common => }/bidi/Realm.ts (94%) rename packages/puppeteer-core/src/{common => }/bidi/Sandbox.ts (91%) rename packages/puppeteer-core/src/{common => }/bidi/Serializer.ts (98%) rename packages/puppeteer-core/src/{common => }/bidi/Target.ts (94%) rename packages/puppeteer-core/src/{common => }/bidi/bidi.ts (100%) rename packages/puppeteer-core/src/{common/bidi/utils.ts => bidi/util.ts} (96%) rename packages/puppeteer-core/src/{common => cdp}/Accessibility.ts (100%) rename packages/puppeteer-core/src/{common => cdp}/AriaQueryHandler.ts (96%) rename packages/puppeteer-core/src/{common => cdp}/Binding.ts (98%) rename packages/puppeteer-core/src/{common => cdp}/Browser.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/BrowserConnector.ts (92%) rename packages/puppeteer-core/src/{common => cdp}/CDPSession.ts (98%) rename packages/puppeteer-core/src/{common => cdp}/ChromeTargetManager.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/Connection.ts (97%) rename packages/puppeteer-core/src/{common => cdp}/Coverage.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/DeviceRequestPrompt.test.ts (98%) rename packages/puppeteer-core/src/{common => cdp}/DeviceRequestPrompt.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/Dialog.ts (100%) rename packages/puppeteer-core/src/{common => cdp}/ElementHandle.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/EmulationManager.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/ExecutionContext.ts (92%) rename packages/puppeteer-core/src/{common => cdp}/FirefoxTargetManager.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/Frame.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/FrameManager.ts (98%) rename packages/puppeteer-core/src/{common => cdp}/FrameTree.ts (100%) rename packages/puppeteer-core/src/{common => cdp}/HTTPRequest.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/HTTPResponse.ts (97%) rename packages/puppeteer-core/src/{common => cdp}/Input.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/IsolatedWorld.ts (88%) rename packages/puppeteer-core/src/{common => cdp}/IsolatedWorlds.ts (100%) rename packages/puppeteer-core/src/{common => cdp}/JSHandle.ts (95%) rename packages/puppeteer-core/src/{common => cdp}/LifecycleWatcher.ts (98%) rename packages/puppeteer-core/src/{common => cdp}/NetworkEventManager.ts (100%) rename packages/puppeteer-core/src/{common => cdp}/NetworkManager.test.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/NetworkManager.ts (99%) rename packages/puppeteer-core/src/{common => cdp}/Page.ts (98%) rename packages/puppeteer-core/src/{common => cdp}/PredefinedNetworkConditions.ts (100%) rename packages/puppeteer-core/src/{common => cdp}/Puppeteer.ts (97%) rename packages/puppeteer-core/src/{common => cdp}/Target.ts (98%) rename packages/puppeteer-core/src/{common => cdp}/TargetManager.ts (96%) rename packages/puppeteer-core/src/{common => cdp}/Tracing.ts (97%) rename packages/puppeteer-core/src/{common => cdp}/WebWorker.ts (94%) create mode 100644 packages/puppeteer-core/src/cdp/cdp.ts rename packages/puppeteer-core/src/common/{PuppeteerViewport.ts => Viewport.ts} (97%) rename packages/puppeteer-core/src/{common => node}/NodeWebSocketTransport.ts (100%) diff --git a/docs/api/index.md b/docs/api/index.md index 5228d5257be..4a1e020e62b 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -127,7 +127,7 @@ sidebar_label: API | [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. | | [SnapshotOptions](./puppeteer.snapshotoptions.md) | | | [TracingOptions](./puppeteer.tracingoptions.md) | | -| [Viewport](./puppeteer.viewport.md) | Sets the viewport of the page. | +| [Viewport](./puppeteer.viewport.md) | | | [WaitForOptions](./puppeteer.waitforoptions.md) | | | [WaitForSelectorOptions](./puppeteer.waitforselectoroptions.md) | | | [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md) | | diff --git a/docs/api/puppeteer.viewport.md b/docs/api/puppeteer.viewport.md index 5fa1f4d2a38..5994f841e74 100644 --- a/docs/api/puppeteer.viewport.md +++ b/docs/api/puppeteer.viewport.md @@ -4,8 +4,6 @@ sidebar_label: Viewport # Viewport interface -Sets the viewport of the page. - #### Signature: ```typescript diff --git a/packages/puppeteer-core/src/api/CDPSession.ts b/packages/puppeteer-core/src/api/CDPSession.ts index 2d14d8ec193..834b1ac1c46 100644 --- a/packages/puppeteer-core/src/api/CDPSession.ts +++ b/packages/puppeteer-core/src/api/CDPSession.ts @@ -1,6 +1,6 @@ import type {ProtocolMapping} from 'devtools-protocol/types/protocol-mapping.js'; -import type {Connection} from '../common/Connection.js'; +import type {Connection} from '../cdp/Connection.js'; import {EventEmitter, type EventType} from '../common/EventEmitter.js'; /** diff --git a/packages/puppeteer-core/src/api/ElementHandle.ts b/packages/puppeteer-core/src/api/ElementHandle.ts index 358dd8496a5..4b5e6dda278 100644 --- a/packages/puppeteer-core/src/api/ElementHandle.ts +++ b/packages/puppeteer-core/src/api/ElementHandle.ts @@ -18,7 +18,6 @@ import {type Protocol} from 'devtools-protocol'; import {type Frame} from '../api/Frame.js'; import {getQueryHandlerAndSelector} from '../common/GetQueryHandler.js'; -import {type WaitForSelectorOptions} from '../common/IsolatedWorld.js'; import {LazyArg} from '../common/LazyArg.js'; import { type ElementFor, @@ -39,7 +38,7 @@ import { type MouseClickOptions, } from './Input.js'; import {JSHandle} from './JSHandle.js'; -import {type ScreenshotOptions} from './Page.js'; +import {type ScreenshotOptions, type WaitForSelectorOptions} from './Page.js'; /** * @public diff --git a/packages/puppeteer-core/src/api/Frame.ts b/packages/puppeteer-core/src/api/Frame.ts index 3b651523ed8..989ea15b7b8 100644 --- a/packages/puppeteer-core/src/api/Frame.ts +++ b/packages/puppeteer-core/src/api/Frame.ts @@ -18,17 +18,18 @@ import type Protocol from 'devtools-protocol'; import {type ClickOptions, type ElementHandle} from '../api/ElementHandle.js'; import {type HTTPResponse} from '../api/HTTPResponse.js'; -import {type Page, type WaitTimeoutOptions} from '../api/Page.js'; -import {type DeviceRequestPrompt} from '../common/DeviceRequestPrompt.js'; +import { + type Page, + type WaitForSelectorOptions, + type WaitTimeoutOptions, +} from '../api/Page.js'; +import {type DeviceRequestPrompt} from '../cdp/DeviceRequestPrompt.js'; +import {type IsolatedWorldChart} from '../cdp/IsolatedWorld.js'; +import {type PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js'; import {EventEmitter, type EventType} from '../common/EventEmitter.js'; import {getQueryHandlerAndSelector} from '../common/GetQueryHandler.js'; import {transposeIterableHandle} from '../common/HandleIterator.js'; -import { - type IsolatedWorldChart, - type WaitForSelectorOptions, -} from '../common/IsolatedWorld.js'; import {LazyArg} from '../common/LazyArg.js'; -import {type PuppeteerLifeCycleEvent} from '../common/LifecycleWatcher.js'; import { type Awaitable, type EvaluateFunc, diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index 57fda00f50e..ba9a5409f48 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -36,12 +36,21 @@ import { } from '../../third_party/rxjs/rxjs.js'; import type {HTTPRequest} from '../api/HTTPRequest.js'; import type {HTTPResponse} from '../api/HTTPResponse.js'; -import type {Accessibility} from '../common/Accessibility.js'; -import type {BidiNetworkManager} from '../common/bidi/NetworkManager.js'; +import type {BidiNetworkManager} from '../bidi/NetworkManager.js'; +import type {Accessibility} from '../cdp/Accessibility.js'; +import type {Coverage} from '../cdp/Coverage.js'; +import {type DeviceRequestPrompt} from '../cdp/DeviceRequestPrompt.js'; +import type {PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js'; +import { + type NetworkManager as CdpNetworkManager, + type Credentials, + type NetworkConditions, + NetworkManagerEvent, +} from '../cdp/NetworkManager.js'; +import type {Tracing} from '../cdp/Tracing.js'; +import type {WebWorker} from '../cdp/WebWorker.js'; import type {ConsoleMessage} from '../common/ConsoleMessage.js'; -import type {Coverage} from '../common/Coverage.js'; import {type Device} from '../common/Device.js'; -import {type DeviceRequestPrompt} from '../common/DeviceRequestPrompt.js'; import {TargetCloseError} from '../common/Errors.js'; import { EventEmitter, @@ -50,22 +59,12 @@ import { type Handler, } from '../common/EventEmitter.js'; import type {FileChooser} from '../common/FileChooser.js'; -import type {WaitForSelectorOptions} from '../common/IsolatedWorld.js'; -import type {PuppeteerLifeCycleEvent} from '../common/LifecycleWatcher.js'; -import { - type NetworkManager as CdpNetworkManager, - type Credentials, - type NetworkConditions, - NetworkManagerEvent, -} from '../common/NetworkManager.js'; import { type LowerCasePaperFormat, paperFormats, type ParsedPDFOptions, type PDFOptions, } from '../common/PDFOptions.js'; -import type {Viewport} from '../common/PuppeteerViewport.js'; -import type {Tracing} from '../common/Tracing.js'; import type { Awaitable, EvaluateFunc, @@ -81,7 +80,7 @@ import { timeout, withSourcePuppeteerURLIfNone, } from '../common/util.js'; -import type {WebWorker} from '../common/WebWorker.js'; +import type {Viewport} from '../common/Viewport.js'; import {assert} from '../util/assert.js'; import {type Deferred} from '../util/Deferred.js'; @@ -162,6 +161,38 @@ export interface WaitForOptions { waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]; } +/** + * @public + */ +export interface WaitForSelectorOptions { + /** + * Wait for the selected element to be present in DOM and to be visible, i.e. + * to not have `display: none` or `visibility: hidden` CSS properties. + * + * @defaultValue `false` + */ + visible?: boolean; + /** + * Wait for the selected element to not be found in the DOM or to be hidden, + * i.e. have `display: none` or `visibility: hidden` CSS properties. + * + * @defaultValue `false` + */ + hidden?: boolean; + /** + * Maximum time to wait in milliseconds. Pass `0` to disable timeout. + * + * The default value can be changed by using {@link Page.setDefaultTimeout} + * + * @defaultValue `30_000` (30 seconds) + */ + timeout?: number; + /** + * A signal object that allows you to cancel a waitForSelector call. + */ + signal?: AbortSignal; +} + /** * @public */ diff --git a/packages/puppeteer-core/src/api/Target.ts b/packages/puppeteer-core/src/api/Target.ts index 90ff6e8d673..fc22f54c687 100644 --- a/packages/puppeteer-core/src/api/Target.ts +++ b/packages/puppeteer-core/src/api/Target.ts @@ -17,7 +17,7 @@ import type {Browser} from '../api/Browser.js'; import type {BrowserContext} from '../api/BrowserContext.js'; import {type Page} from '../api/Page.js'; -import {type WebWorker} from '../common/WebWorker.js'; +import {type WebWorker} from '../cdp/WebWorker.js'; import {type CDPSession} from './CDPSession.js'; diff --git a/packages/puppeteer-core/src/api/locators/DelegatedLocator.ts b/packages/puppeteer-core/src/api/locators/DelegatedLocator.ts index 62fd05b130e..1401cfce33f 100644 --- a/packages/puppeteer-core/src/api/locators/DelegatedLocator.ts +++ b/packages/puppeteer-core/src/api/locators/DelegatedLocator.ts @@ -15,7 +15,7 @@ */ import {type Observable} from '../../../third_party/rxjs/rxjs.js'; -import {type HandleFor} from '../../common/common.js'; +import {type HandleFor} from '../../common/types.js'; import {Locator, type VisibilityOption} from './locators.js'; diff --git a/packages/puppeteer-core/src/api/locators/FilteredLocator.ts b/packages/puppeteer-core/src/api/locators/FilteredLocator.ts index 2eedfe505e7..94648b9e820 100644 --- a/packages/puppeteer-core/src/api/locators/FilteredLocator.ts +++ b/packages/puppeteer-core/src/api/locators/FilteredLocator.ts @@ -22,7 +22,7 @@ import { mergeMap, throwIfEmpty, } from '../../../third_party/rxjs/rxjs.js'; -import {type Awaitable, type HandleFor} from '../../common/common.js'; +import {type Awaitable, type HandleFor} from '../../common/types.js'; import {DelegatedLocator} from './DelegatedLocator.js'; import {type ActionOptions, type Locator} from './locators.js'; diff --git a/packages/puppeteer-core/src/api/locators/MappedLocator.ts b/packages/puppeteer-core/src/api/locators/MappedLocator.ts index 3dbf7e5383f..c6b7a79499b 100644 --- a/packages/puppeteer-core/src/api/locators/MappedLocator.ts +++ b/packages/puppeteer-core/src/api/locators/MappedLocator.ts @@ -19,7 +19,7 @@ import { from, mergeMap, } from '../../../third_party/rxjs/rxjs.js'; -import {type Awaitable, type HandleFor} from '../../common/common.js'; +import {type Awaitable, type HandleFor} from '../../common/types.js'; import { type ActionOptions, diff --git a/packages/puppeteer-core/src/api/locators/RaceLocator.ts b/packages/puppeteer-core/src/api/locators/RaceLocator.ts index a17991ea2ab..9748165a252 100644 --- a/packages/puppeteer-core/src/api/locators/RaceLocator.ts +++ b/packages/puppeteer-core/src/api/locators/RaceLocator.ts @@ -15,7 +15,7 @@ */ import {type Observable, race} from '../../../third_party/rxjs/rxjs.js'; -import {type HandleFor} from '../../puppeteer-core.js'; +import {type HandleFor} from '../../common/types.js'; import {type ActionOptions, Locator} from './locators.js'; diff --git a/packages/puppeteer-core/src/common/bidi/BidiOverCdp.ts b/packages/puppeteer-core/src/bidi/BidiOverCdp.ts similarity index 95% rename from packages/puppeteer-core/src/common/bidi/BidiOverCdp.ts rename to packages/puppeteer-core/src/bidi/BidiOverCdp.ts index 5d7e4d7b896..10eba5e6534 100644 --- a/packages/puppeteer-core/src/common/bidi/BidiOverCdp.ts +++ b/packages/puppeteer-core/src/bidi/BidiOverCdp.ts @@ -18,10 +18,10 @@ import * as BidiMapper from 'chromium-bidi/lib/cjs/bidiMapper/bidiMapper.js'; import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; import type {ProtocolMapping} from 'devtools-protocol/types/protocol-mapping.js'; -import {type CDPEvents, type CDPSession} from '../../api/CDPSession.js'; -import {type Connection as CdpConnection} from '../Connection.js'; -import {TargetCloseError} from '../Errors.js'; -import {type Handler} from '../EventEmitter.js'; +import {type CDPEvents, type CDPSession} from '../api/CDPSession.js'; +import {type Connection as CdpConnection} from '../cdp/Connection.js'; +import {TargetCloseError} from '../common/Errors.js'; +import {type Handler} from '../common/EventEmitter.js'; import {BidiConnection} from './Connection.js'; diff --git a/packages/puppeteer-core/src/common/bidi/Browser.ts b/packages/puppeteer-core/src/bidi/Browser.ts similarity index 96% rename from packages/puppeteer-core/src/common/bidi/Browser.ts rename to packages/puppeteer-core/src/bidi/Browser.ts index b6785ef42d8..004ce557396 100644 --- a/packages/puppeteer-core/src/common/bidi/Browser.ts +++ b/packages/puppeteer-core/src/bidi/Browser.ts @@ -23,12 +23,12 @@ import { type BrowserCloseCallback, type BrowserContextOptions, BrowserEvent, -} from '../../api/Browser.js'; -import {BrowserContextEvent} from '../../api/BrowserContext.js'; -import {type Page} from '../../api/Page.js'; -import {type Target} from '../../api/Target.js'; -import {type Handler} from '../EventEmitter.js'; -import {type Viewport} from '../PuppeteerViewport.js'; +} from '../api/Browser.js'; +import {BrowserContextEvent} from '../api/BrowserContext.js'; +import {type Page} from '../api/Page.js'; +import {type Target} from '../api/Target.js'; +import {type Handler} from '../common/EventEmitter.js'; +import {type Viewport} from '../common/Viewport.js'; import {BidiBrowserContext} from './BrowserContext.js'; import {BrowsingContext, BrowsingContextEvent} from './BrowsingContext.js'; @@ -39,7 +39,7 @@ import { BiDiPageTarget, type BidiTarget, } from './Target.js'; -import {debugError} from './utils.js'; +import {debugError} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/bidi/BrowserContext.ts b/packages/puppeteer-core/src/bidi/BrowserContext.ts similarity index 94% rename from packages/puppeteer-core/src/common/bidi/BrowserContext.ts rename to packages/puppeteer-core/src/bidi/BrowserContext.ts index 59e94e4b194..d3fdb6562d3 100644 --- a/packages/puppeteer-core/src/common/bidi/BrowserContext.ts +++ b/packages/puppeteer-core/src/bidi/BrowserContext.ts @@ -16,10 +16,10 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {BrowserContext} from '../../api/BrowserContext.js'; -import {type Page} from '../../api/Page.js'; -import {type Target} from '../../api/Target.js'; -import {type Viewport} from '../PuppeteerViewport.js'; +import {BrowserContext} from '../api/BrowserContext.js'; +import {type Page} from '../api/Page.js'; +import {type Target} from '../api/Target.js'; +import {type Viewport} from '../common/Viewport.js'; import {type BidiBrowser} from './Browser.js'; import {type BidiConnection} from './Connection.js'; diff --git a/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts b/packages/puppeteer-core/src/bidi/BrowsingContext.ts similarity index 93% rename from packages/puppeteer-core/src/common/bidi/BrowsingContext.ts rename to packages/puppeteer-core/src/bidi/BrowsingContext.ts index ea532a08b64..564e36f16bd 100644 --- a/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts +++ b/packages/puppeteer-core/src/bidi/BrowsingContext.ts @@ -1,19 +1,23 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping.js'; -import {CDPSession} from '../../api/CDPSession.js'; -import {type WaitForOptions} from '../../api/Page.js'; -import {assert} from '../../util/assert.js'; -import {Deferred} from '../../util/Deferred.js'; -import {type Connection as CdpConnection} from '../Connection.js'; -import {ProtocolError, TargetCloseError, TimeoutError} from '../Errors.js'; -import {type EventType} from '../EventEmitter.js'; -import {type PuppeteerLifeCycleEvent} from '../LifecycleWatcher.js'; -import {setPageContent, waitWithTimeout} from '../util.js'; +import {CDPSession} from '../api/CDPSession.js'; +import {type WaitForOptions} from '../api/Page.js'; +import {type Connection as CdpConnection} from '../cdp/Connection.js'; +import {type PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js'; +import { + ProtocolError, + TargetCloseError, + TimeoutError, +} from '../common/Errors.js'; +import {type EventType} from '../common/EventEmitter.js'; +import {setPageContent, waitWithTimeout} from '../common/util.js'; +import {assert} from '../util/assert.js'; +import {Deferred} from '../util/Deferred.js'; import {type BidiConnection} from './Connection.js'; import {Realm} from './Realm.js'; -import {debugError} from './utils.js'; +import {debugError} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/bidi/Connection.test.ts b/packages/puppeteer-core/src/bidi/Connection.test.ts similarity index 96% rename from packages/puppeteer-core/src/common/bidi/Connection.test.ts rename to packages/puppeteer-core/src/bidi/Connection.test.ts index 84843e4e48a..1348b9d418e 100644 --- a/packages/puppeteer-core/src/common/bidi/Connection.test.ts +++ b/packages/puppeteer-core/src/bidi/Connection.test.ts @@ -18,7 +18,7 @@ import {describe, it} from 'node:test'; import expect from 'expect'; -import {type ConnectionTransport} from '../ConnectionTransport.js'; +import {type ConnectionTransport} from '../common/ConnectionTransport.js'; import {BidiConnection} from './Connection.js'; diff --git a/packages/puppeteer-core/src/common/bidi/Connection.ts b/packages/puppeteer-core/src/bidi/Connection.ts similarity index 96% rename from packages/puppeteer-core/src/common/bidi/Connection.ts rename to packages/puppeteer-core/src/bidi/Connection.ts index ceba194a329..2f5d997a066 100644 --- a/packages/puppeteer-core/src/common/bidi/Connection.ts +++ b/packages/puppeteer-core/src/bidi/Connection.ts @@ -16,13 +16,13 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {CallbackRegistry} from '../Connection.js'; -import {type ConnectionTransport} from '../ConnectionTransport.js'; -import {debug} from '../Debug.js'; -import {EventEmitter} from '../EventEmitter.js'; +import {CallbackRegistry} from '../cdp/Connection.js'; +import {type ConnectionTransport} from '../common/ConnectionTransport.js'; +import {debug} from '../common/Debug.js'; +import {EventEmitter} from '../common/EventEmitter.js'; import {type BrowsingContext, cdpSessions} from './BrowsingContext.js'; -import {debugError} from './utils.js'; +import {debugError} from './util.js'; const debugProtocolSend = debug('puppeteer:webDriverBiDi:SEND ►'); const debugProtocolReceive = debug('puppeteer:webDriverBiDi:RECV ◀'); diff --git a/packages/puppeteer-core/src/common/bidi/Dialog.ts b/packages/puppeteer-core/src/bidi/Dialog.ts similarity index 97% rename from packages/puppeteer-core/src/common/bidi/Dialog.ts rename to packages/puppeteer-core/src/bidi/Dialog.ts index 768e27850cb..5b7fbd80468 100644 --- a/packages/puppeteer-core/src/common/bidi/Dialog.ts +++ b/packages/puppeteer-core/src/bidi/Dialog.ts @@ -16,7 +16,7 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {Dialog} from '../../api/Dialog.js'; +import {Dialog} from '../api/Dialog.js'; import {type BrowsingContext} from './BrowsingContext.js'; diff --git a/packages/puppeteer-core/src/common/bidi/ElementHandle.ts b/packages/puppeteer-core/src/bidi/ElementHandle.ts similarity index 94% rename from packages/puppeteer-core/src/common/bidi/ElementHandle.ts rename to packages/puppeteer-core/src/bidi/ElementHandle.ts index fa4f1ab7ccc..b12ab808295 100644 --- a/packages/puppeteer-core/src/common/bidi/ElementHandle.ts +++ b/packages/puppeteer-core/src/bidi/ElementHandle.ts @@ -16,8 +16,8 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {type AutofillData, ElementHandle} from '../../api/ElementHandle.js'; -import {throwIfDisposed} from '../../util/decorators.js'; +import {type AutofillData, ElementHandle} from '../api/ElementHandle.js'; +import {throwIfDisposed} from '../util/decorators.js'; import {type BidiFrame} from './Frame.js'; import {BidiJSHandle} from './JSHandle.js'; diff --git a/packages/puppeteer-core/src/common/bidi/EmulationManager.ts b/packages/puppeteer-core/src/bidi/EmulationManager.ts similarity index 100% rename from packages/puppeteer-core/src/common/bidi/EmulationManager.ts rename to packages/puppeteer-core/src/bidi/EmulationManager.ts diff --git a/packages/puppeteer-core/src/common/bidi/ExposedFunction.ts b/packages/puppeteer-core/src/bidi/ExposedFunction.ts similarity index 96% rename from packages/puppeteer-core/src/common/bidi/ExposedFunction.ts rename to packages/puppeteer-core/src/bidi/ExposedFunction.ts index aa52b687939..46abe2880a0 100644 --- a/packages/puppeteer-core/src/common/bidi/ExposedFunction.ts +++ b/packages/puppeteer-core/src/bidi/ExposedFunction.ts @@ -16,15 +16,15 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {assert} from '../../util/assert.js'; -import {Deferred} from '../../util/Deferred.js'; -import {interpolateFunction, stringifyFunction} from '../../util/Function.js'; -import {type Awaitable, type FlattenHandle} from '../types.js'; +import {type Awaitable, type FlattenHandle} from '../common/types.js'; +import {assert} from '../util/assert.js'; +import {Deferred} from '../util/Deferred.js'; +import {interpolateFunction, stringifyFunction} from '../util/Function.js'; import {type BidiConnection} from './Connection.js'; import {type BidiFrame} from './Frame.js'; import {BidiSerializer} from './Serializer.js'; -import {debugError} from './utils.js'; +import {debugError} from './util.js'; type SendArgsChannel = (value: [id: number, args: Args]) => void; type SendResolveChannel = ( diff --git a/packages/puppeteer-core/src/common/bidi/Frame.ts b/packages/puppeteer-core/src/bidi/Frame.ts similarity index 92% rename from packages/puppeteer-core/src/common/bidi/Frame.ts rename to packages/puppeteer-core/src/bidi/Frame.ts index b3f674f7a1f..b365e486965 100644 --- a/packages/puppeteer-core/src/common/bidi/Frame.ts +++ b/packages/puppeteer-core/src/bidi/Frame.ts @@ -16,14 +16,14 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {type CDPSession} from '../../api/CDPSession.js'; -import {Frame, throwIfDetached} from '../../api/Frame.js'; -import {Deferred} from '../../util/Deferred.js'; -import {UTILITY_WORLD_NAME} from '../FrameManager.js'; -import {type PuppeteerLifeCycleEvent} from '../LifecycleWatcher.js'; -import {type TimeoutSettings} from '../TimeoutSettings.js'; -import {type Awaitable} from '../types.js'; -import {waitForEvent} from '../util.js'; +import {type CDPSession} from '../api/CDPSession.js'; +import {Frame, throwIfDetached} from '../api/Frame.js'; +import {UTILITY_WORLD_NAME} from '../cdp/FrameManager.js'; +import {type PuppeteerLifeCycleEvent} from '../cdp/LifecycleWatcher.js'; +import {type TimeoutSettings} from '../common/TimeoutSettings.js'; +import {type Awaitable} from '../common/types.js'; +import {waitForEvent} from '../common/util.js'; +import {Deferred} from '../util/Deferred.js'; import { type BrowsingContext, diff --git a/packages/puppeteer-core/src/common/bidi/HTTPRequest.ts b/packages/puppeteer-core/src/bidi/HTTPRequest.ts similarity index 96% rename from packages/puppeteer-core/src/common/bidi/HTTPRequest.ts rename to packages/puppeteer-core/src/bidi/HTTPRequest.ts index 78f281cb8e9..002f3ae4667 100644 --- a/packages/puppeteer-core/src/common/bidi/HTTPRequest.ts +++ b/packages/puppeteer-core/src/bidi/HTTPRequest.ts @@ -15,8 +15,8 @@ */ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {type Frame} from '../../api/Frame.js'; -import {HTTPRequest, type ResourceType} from '../../api/HTTPRequest.js'; +import {type Frame} from '../api/Frame.js'; +import {HTTPRequest, type ResourceType} from '../api/HTTPRequest.js'; import {type BidiHTTPResponse} from './HTTPResponse.js'; diff --git a/packages/puppeteer-core/src/common/bidi/HTTPResponse.ts b/packages/puppeteer-core/src/bidi/HTTPResponse.ts similarity index 97% rename from packages/puppeteer-core/src/common/bidi/HTTPResponse.ts rename to packages/puppeteer-core/src/bidi/HTTPResponse.ts index 9e06cdcf411..6c25f673fba 100644 --- a/packages/puppeteer-core/src/common/bidi/HTTPResponse.ts +++ b/packages/puppeteer-core/src/bidi/HTTPResponse.ts @@ -16,11 +16,11 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; import type Protocol from 'devtools-protocol'; -import {type Frame} from '../../api/Frame.js'; +import {type Frame} from '../api/Frame.js'; import { HTTPResponse as HTTPResponse, type RemoteAddress, -} from '../../api/HTTPResponse.js'; +} from '../api/HTTPResponse.js'; import {type BidiHTTPRequest} from './HTTPRequest.js'; diff --git a/packages/puppeteer-core/src/common/bidi/Input.ts b/packages/puppeteer-core/src/bidi/Input.ts similarity index 99% rename from packages/puppeteer-core/src/common/bidi/Input.ts rename to packages/puppeteer-core/src/bidi/Input.ts index b60fbb0a26c..c57baee4b64 100644 --- a/packages/puppeteer-core/src/common/bidi/Input.ts +++ b/packages/puppeteer-core/src/bidi/Input.ts @@ -16,7 +16,7 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {type Point} from '../../api/ElementHandle.js'; +import {type Point} from '../api/ElementHandle.js'; import { Keyboard as BaseKeyboard, Mouse as BaseMouse, @@ -29,8 +29,8 @@ import { type MouseMoveOptions, type MouseOptions, type MouseWheelOptions, -} from '../../api/Input.js'; -import {type KeyInput} from '../USKeyboardLayout.js'; +} from '../api/Input.js'; +import {type KeyInput} from '../common/USKeyboardLayout.js'; import {type BrowsingContext} from './BrowsingContext.js'; diff --git a/packages/puppeteer-core/src/common/bidi/JSHandle.ts b/packages/puppeteer-core/src/bidi/JSHandle.ts similarity index 94% rename from packages/puppeteer-core/src/common/bidi/JSHandle.ts rename to packages/puppeteer-core/src/bidi/JSHandle.ts index 2d74000bfbc..18df84c5862 100644 --- a/packages/puppeteer-core/src/common/bidi/JSHandle.ts +++ b/packages/puppeteer-core/src/bidi/JSHandle.ts @@ -17,13 +17,13 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; import type Protocol from 'devtools-protocol'; -import {type ElementHandle} from '../../api/ElementHandle.js'; -import {JSHandle} from '../../api/JSHandle.js'; +import {type ElementHandle} from '../api/ElementHandle.js'; +import {JSHandle} from '../api/JSHandle.js'; import {type Realm} from './Realm.js'; import {type Sandbox} from './Sandbox.js'; import {BidiSerializer} from './Serializer.js'; -import {releaseReference} from './utils.js'; +import {releaseReference} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/bidi/NetworkManager.ts b/packages/puppeteer-core/src/bidi/NetworkManager.ts similarity index 98% rename from packages/puppeteer-core/src/common/bidi/NetworkManager.ts rename to packages/puppeteer-core/src/bidi/NetworkManager.ts index 6f0d93b5046..670ef2a095a 100644 --- a/packages/puppeteer-core/src/common/bidi/NetworkManager.ts +++ b/packages/puppeteer-core/src/bidi/NetworkManager.ts @@ -16,12 +16,12 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; +import {NetworkManagerEvent} from '../cdp/NetworkManager.js'; import { EventEmitter, EventSubscription, type EventType, -} from '../EventEmitter.js'; -import {NetworkManagerEvent} from '../NetworkManager.js'; +} from '../common/EventEmitter.js'; import {type BidiConnection} from './Connection.js'; import {type BidiFrame} from './Frame.js'; diff --git a/packages/puppeteer-core/src/common/bidi/Page.ts b/packages/puppeteer-core/src/bidi/Page.ts similarity index 95% rename from packages/puppeteer-core/src/common/bidi/Page.ts rename to packages/puppeteer-core/src/bidi/Page.ts index df3acfb8980..3df2cf33ea8 100644 --- a/packages/puppeteer-core/src/common/bidi/Page.ts +++ b/packages/puppeteer-core/src/bidi/Page.ts @@ -19,7 +19,7 @@ import type {Readable} from 'stream'; import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; import type Protocol from 'devtools-protocol'; -import {type CDPSession} from '../../api/CDPSession.js'; +import {type CDPSession} from '../api/CDPSession.js'; import { type GeolocationOptions, type MediaFeature, @@ -28,25 +28,22 @@ import { PageEvent, type ScreenshotOptions, type WaitForOptions, -} from '../../api/Page.js'; -import {assert} from '../../util/assert.js'; -import {Deferred} from '../../util/Deferred.js'; -import {Accessibility} from '../Accessibility.js'; +} from '../api/Page.js'; +import {Accessibility} from '../cdp/Accessibility.js'; +import {Coverage} from '../cdp/Coverage.js'; +import {EmulationManager as CdpEmulationManager} from '../cdp/EmulationManager.js'; +import {FrameTree} from '../cdp/FrameTree.js'; +import {NetworkManagerEvent} from '../cdp/NetworkManager.js'; +import {Tracing} from '../cdp/Tracing.js'; import { ConsoleMessage, type ConsoleMessageLocation, -} from '../ConsoleMessage.js'; -import {Coverage} from '../Coverage.js'; -import {EmulationManager as CdpEmulationManager} from '../EmulationManager.js'; -import {TargetCloseError} from '../Errors.js'; -import {type Handler} from '../EventEmitter.js'; -import {FrameTree} from '../FrameTree.js'; -import {NetworkManagerEvent} from '../NetworkManager.js'; -import {type PDFOptions} from '../PDFOptions.js'; -import {type Viewport} from '../PuppeteerViewport.js'; -import {TimeoutSettings} from '../TimeoutSettings.js'; -import {Tracing} from '../Tracing.js'; -import {type Awaitable} from '../types.js'; +} from '../common/ConsoleMessage.js'; +import {TargetCloseError} from '../common/Errors.js'; +import {type Handler} from '../common/EventEmitter.js'; +import {type PDFOptions} from '../common/PDFOptions.js'; +import {TimeoutSettings} from '../common/TimeoutSettings.js'; +import {type Awaitable} from '../common/types.js'; import { debugError, evaluationString, @@ -54,7 +51,10 @@ import { validateDialogType, waitForEvent, waitWithTimeout, -} from '../util.js'; +} from '../common/util.js'; +import {type Viewport} from '../common/Viewport.js'; +import {assert} from '../util/assert.js'; +import {Deferred} from '../util/Deferred.js'; import {type BidiBrowser} from './Browser.js'; import {type BidiBrowserContext} from './BrowserContext.js'; diff --git a/packages/puppeteer-core/src/common/bidi/Realm.ts b/packages/puppeteer-core/src/bidi/Realm.ts similarity index 94% rename from packages/puppeteer-core/src/common/bidi/Realm.ts rename to packages/puppeteer-core/src/bidi/Realm.ts index 304e3f9ae90..d15d2ef1f27 100644 --- a/packages/puppeteer-core/src/common/bidi/Realm.ts +++ b/packages/puppeteer-core/src/bidi/Realm.ts @@ -1,22 +1,22 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import type PuppeteerUtil from '../../injected/injected.js'; -import {stringifyFunction} from '../../util/Function.js'; -import {EventEmitter, type EventType} from '../EventEmitter.js'; -import {scriptInjector} from '../ScriptInjector.js'; -import {type EvaluateFunc, type HandleFor} from '../types.js'; +import {EventEmitter, type EventType} from '../common/EventEmitter.js'; +import {scriptInjector} from '../common/ScriptInjector.js'; +import {type EvaluateFunc, type HandleFor} from '../common/types.js'; import { PuppeteerURL, getSourcePuppeteerURLIfAvailable, isString, -} from '../util.js'; +} from '../common/util.js'; +import type PuppeteerUtil from '../injected/injected.js'; +import {stringifyFunction} from '../util/Function.js'; import {type BidiConnection} from './Connection.js'; import {BidiElementHandle} from './ElementHandle.js'; import {BidiJSHandle} from './JSHandle.js'; import {type Sandbox} from './Sandbox.js'; import {BidiSerializer} from './Serializer.js'; -import {createEvaluationError} from './utils.js'; +import {createEvaluationError} from './util.js'; export const SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m; diff --git a/packages/puppeteer-core/src/common/bidi/Sandbox.ts b/packages/puppeteer-core/src/bidi/Sandbox.ts similarity index 91% rename from packages/puppeteer-core/src/common/bidi/Sandbox.ts rename to packages/puppeteer-core/src/bidi/Sandbox.ts index aaad4ef0a45..f7bfd4a8c30 100644 --- a/packages/puppeteer-core/src/common/bidi/Sandbox.ts +++ b/packages/puppeteer-core/src/bidi/Sandbox.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import {type JSHandle} from '../../api/JSHandle.js'; -import {Realm} from '../../api/Realm.js'; -import {type TimeoutSettings} from '../TimeoutSettings.js'; -import {type EvaluateFunc, type HandleFor} from '../types.js'; -import {withSourcePuppeteerURLIfNone} from '../util.js'; +import {type JSHandle} from '../api/JSHandle.js'; +import {Realm} from '../api/Realm.js'; +import {type TimeoutSettings} from '../common/TimeoutSettings.js'; +import {type EvaluateFunc, type HandleFor} from '../common/types.js'; +import {withSourcePuppeteerURLIfNone} from '../common/util.js'; import {type BrowsingContext} from './BrowsingContext.js'; import {type BidiFrame} from './Frame.js'; diff --git a/packages/puppeteer-core/src/common/bidi/Serializer.ts b/packages/puppeteer-core/src/bidi/Serializer.ts similarity index 98% rename from packages/puppeteer-core/src/common/bidi/Serializer.ts rename to packages/puppeteer-core/src/bidi/Serializer.ts index 3fcced34f96..47f7a6da9a5 100644 --- a/packages/puppeteer-core/src/common/bidi/Serializer.ts +++ b/packages/puppeteer-core/src/bidi/Serializer.ts @@ -16,8 +16,8 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {LazyArg} from '../LazyArg.js'; -import {debugError, isDate, isPlainObject, isRegExp} from '../util.js'; +import {LazyArg} from '../common/LazyArg.js'; +import {debugError, isDate, isPlainObject, isRegExp} from '../common/util.js'; import {BidiElementHandle} from './ElementHandle.js'; import {BidiJSHandle} from './JSHandle.js'; diff --git a/packages/puppeteer-core/src/common/bidi/Target.ts b/packages/puppeteer-core/src/bidi/Target.ts similarity index 94% rename from packages/puppeteer-core/src/common/bidi/Target.ts rename to packages/puppeteer-core/src/bidi/Target.ts index f62d8a42d24..c8d2d7841fb 100644 --- a/packages/puppeteer-core/src/common/bidi/Target.ts +++ b/packages/puppeteer-core/src/bidi/Target.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import {type CDPSession} from '../../api/CDPSession.js'; -import {Target, TargetType} from '../../api/Target.js'; -import type {WebWorker} from '../WebWorker.js'; +import {type CDPSession} from '../api/CDPSession.js'; +import {Target, TargetType} from '../api/Target.js'; +import type {WebWorker} from '../cdp/WebWorker.js'; import {type BidiBrowser} from './Browser.js'; import {type BidiBrowserContext} from './BrowserContext.js'; diff --git a/packages/puppeteer-core/src/common/bidi/bidi.ts b/packages/puppeteer-core/src/bidi/bidi.ts similarity index 100% rename from packages/puppeteer-core/src/common/bidi/bidi.ts rename to packages/puppeteer-core/src/bidi/bidi.ts diff --git a/packages/puppeteer-core/src/common/bidi/utils.ts b/packages/puppeteer-core/src/bidi/util.ts similarity index 96% rename from packages/puppeteer-core/src/common/bidi/utils.ts rename to packages/puppeteer-core/src/bidi/util.ts index a24f492327e..4ff68f33ed2 100644 --- a/packages/puppeteer-core/src/common/bidi/utils.ts +++ b/packages/puppeteer-core/src/bidi/util.ts @@ -16,8 +16,8 @@ import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; -import {debug} from '../Debug.js'; -import {PuppeteerURL} from '../util.js'; +import {debug} from '../common/Debug.js'; +import {PuppeteerURL} from '../common/util.js'; import {type Realm} from './Realm.js'; import {BidiSerializer} from './Serializer.js'; @@ -26,6 +26,7 @@ import {BidiSerializer} from './Serializer.js'; * @internal */ export const debugError = debug('puppeteer:error'); + /** * @internal */ diff --git a/packages/puppeteer-core/src/common/Accessibility.ts b/packages/puppeteer-core/src/cdp/Accessibility.ts similarity index 100% rename from packages/puppeteer-core/src/common/Accessibility.ts rename to packages/puppeteer-core/src/cdp/Accessibility.ts diff --git a/packages/puppeteer-core/src/common/AriaQueryHandler.ts b/packages/puppeteer-core/src/cdp/AriaQueryHandler.ts similarity index 96% rename from packages/puppeteer-core/src/common/AriaQueryHandler.ts rename to packages/puppeteer-core/src/cdp/AriaQueryHandler.ts index d6219c1adcb..1a79a229753 100644 --- a/packages/puppeteer-core/src/common/AriaQueryHandler.ts +++ b/packages/puppeteer-core/src/cdp/AriaQueryHandler.ts @@ -18,12 +18,12 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import {type ElementHandle} from '../api/ElementHandle.js'; +import {QueryHandler, type QuerySelector} from '../common/QueryHandler.js'; +import {type AwaitableIterable} from '../common/types.js'; import {assert} from '../util/assert.js'; import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js'; import {type IsolatedWorld} from './IsolatedWorld.js'; -import {QueryHandler, type QuerySelector} from './QueryHandler.js'; -import {type AwaitableIterable} from './types.js'; const queryAXTree = async ( client: CDPSession, diff --git a/packages/puppeteer-core/src/common/Binding.ts b/packages/puppeteer-core/src/cdp/Binding.ts similarity index 98% rename from packages/puppeteer-core/src/common/Binding.ts rename to packages/puppeteer-core/src/cdp/Binding.ts index a256ca50ae0..0231fb4c625 100644 --- a/packages/puppeteer-core/src/common/Binding.ts +++ b/packages/puppeteer-core/src/cdp/Binding.ts @@ -1,8 +1,8 @@ import {JSHandle} from '../api/JSHandle.js'; +import {debugError} from '../common/util.js'; import {isErrorLike} from '../util/ErrorLike.js'; import {type ExecutionContext} from './ExecutionContext.js'; -import {debugError} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/Browser.ts b/packages/puppeteer-core/src/cdp/Browser.ts similarity index 99% rename from packages/puppeteer-core/src/common/Browser.ts rename to packages/puppeteer-core/src/cdp/Browser.ts index 2998bf57ac1..f34a0a96008 100644 --- a/packages/puppeteer-core/src/common/Browser.ts +++ b/packages/puppeteer-core/src/cdp/Browser.ts @@ -32,13 +32,14 @@ import {BrowserContext, BrowserContextEvent} from '../api/BrowserContext.js'; import {type CDPSession, CDPSessionEvent} from '../api/CDPSession.js'; import {type Page} from '../api/Page.js'; import {type Target} from '../api/Target.js'; +import {TaskQueue} from '../common/TaskQueue.js'; +import {type Viewport} from '../common/Viewport.js'; import {USE_TAB_TARGET} from '../environment.js'; import {assert} from '../util/assert.js'; import {ChromeTargetManager} from './ChromeTargetManager.js'; import {type Connection} from './Connection.js'; import {FirefoxTargetManager} from './FirefoxTargetManager.js'; -import {type Viewport} from './PuppeteerViewport.js'; import { type CdpTarget, DevToolsTarget, @@ -48,7 +49,6 @@ import { WorkerTarget, } from './Target.js'; import {type TargetManager, TargetManagerEvent} from './TargetManager.js'; -import {TaskQueue} from './TaskQueue.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/BrowserConnector.ts b/packages/puppeteer-core/src/cdp/BrowserConnector.ts similarity index 92% rename from packages/puppeteer-core/src/common/BrowserConnector.ts rename to packages/puppeteer-core/src/cdp/BrowserConnector.ts index 6217b8cf5e5..229023c9acb 100644 --- a/packages/puppeteer-core/src/common/BrowserConnector.ts +++ b/packages/puppeteer-core/src/cdp/BrowserConnector.ts @@ -18,17 +18,17 @@ import { type IsPageTargetCallback, type TargetFilterCallback, } from '../api/Browser.js'; +import {type ConnectionTransport} from '../common/ConnectionTransport.js'; +import {getFetch} from '../common/fetch.js'; +import {debugError} from '../common/util.js'; +import {type Viewport} from '../common/Viewport.js'; import {isNode} from '../environment.js'; import {assert} from '../util/assert.js'; import {isErrorLike} from '../util/ErrorLike.js'; import {CdpBrowser} from './Browser.js'; import {Connection} from './Connection.js'; -import {type ConnectionTransport} from './ConnectionTransport.js'; -import {getFetch} from './fetch.js'; import type {ConnectOptions} from './Puppeteer.js'; -import {type Viewport} from './PuppeteerViewport.js'; -import {debugError} from './util.js'; /** * Generic browser options that can be passed when launching any browser or when * connecting to an existing browser instance. @@ -72,8 +72,8 @@ export interface BrowserConnectOptions { const getWebSocketTransportClass = async () => { return isNode - ? (await import('./NodeWebSocketTransport.js')).NodeWebSocketTransport - : (await import('./BrowserWebSocketTransport.js')) + ? (await import('../node/NodeWebSocketTransport.js')).NodeWebSocketTransport + : (await import('../common/BrowserWebSocketTransport.js')) .BrowserWebSocketTransport; }; diff --git a/packages/puppeteer-core/src/common/CDPSession.ts b/packages/puppeteer-core/src/cdp/CDPSession.ts similarity index 98% rename from packages/puppeteer-core/src/common/CDPSession.ts rename to packages/puppeteer-core/src/cdp/CDPSession.ts index d6d6e95263f..525ba08fbf5 100644 --- a/packages/puppeteer-core/src/common/CDPSession.ts +++ b/packages/puppeteer-core/src/cdp/CDPSession.ts @@ -5,6 +5,7 @@ import { CDPSession, CDPSessionEvent, } from '../api/CDPSession.js'; +import {TargetCloseError} from '../common/Errors.js'; import {assert} from '../util/assert.js'; import { @@ -12,7 +13,6 @@ import { type Connection, createProtocolErrorMessage, } from './Connection.js'; -import {TargetCloseError} from './Errors.js'; import {type CdpTarget} from './Target.js'; /** diff --git a/packages/puppeteer-core/src/common/ChromeTargetManager.ts b/packages/puppeteer-core/src/cdp/ChromeTargetManager.ts similarity index 99% rename from packages/puppeteer-core/src/common/ChromeTargetManager.ts rename to packages/puppeteer-core/src/cdp/ChromeTargetManager.ts index 0388db786f9..fee446f36c6 100644 --- a/packages/puppeteer-core/src/common/ChromeTargetManager.ts +++ b/packages/puppeteer-core/src/cdp/ChromeTargetManager.ts @@ -19,11 +19,12 @@ import {type Protocol} from 'devtools-protocol'; import {type TargetFilterCallback} from '../api/Browser.js'; import {CDPSession, CDPSessionEvent} from '../api/CDPSession.js'; import {TargetType} from '../api/Target.js'; +import {EventEmitter} from '../common/EventEmitter.js'; +import {debugError} from '../common/util.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; import {type Connection} from './Connection.js'; -import {EventEmitter} from './EventEmitter.js'; import {CdpTarget, InitializationStatus} from './Target.js'; import { type TargetFactory, @@ -31,7 +32,6 @@ import { TargetManagerEvent, type TargetManagerEvents, } from './TargetManager.js'; -import {debugError} from './util.js'; function isTargetExposed(target: CdpTarget): boolean { return target.type() !== TargetType.TAB && !target._subtype(); diff --git a/packages/puppeteer-core/src/common/Connection.ts b/packages/puppeteer-core/src/cdp/Connection.ts similarity index 97% rename from packages/puppeteer-core/src/common/Connection.ts rename to packages/puppeteer-core/src/cdp/Connection.ts index 9466e27f567..efab77b1a7e 100644 --- a/packages/puppeteer-core/src/common/Connection.ts +++ b/packages/puppeteer-core/src/cdp/Connection.ts @@ -22,14 +22,14 @@ import { CDPSessionEvent, type CDPSessionEvents, } from '../api/CDPSession.js'; +import {ConnectionTransport} from '../common/ConnectionTransport.js'; +import {debug} from '../common/Debug.js'; +import {ProtocolError, TargetCloseError} from '../common/Errors.js'; +import {EventEmitter} from '../common/EventEmitter.js'; +import {debugError} from '../common/util.js'; import {Deferred} from '../util/Deferred.js'; import {CdpCDPSession} from './CDPSession.js'; -import {ConnectionTransport} from './ConnectionTransport.js'; -import {debug} from './Debug.js'; -import {ProtocolError, TargetCloseError} from './Errors.js'; -import {EventEmitter} from './EventEmitter.js'; -import {debugError} from './util.js'; const debugProtocolSend = debug('puppeteer:protocol:SEND ►'); const debugProtocolReceive = debug('puppeteer:protocol:RECV ◀'); diff --git a/packages/puppeteer-core/src/common/Coverage.ts b/packages/puppeteer-core/src/cdp/Coverage.ts similarity index 99% rename from packages/puppeteer-core/src/common/Coverage.ts rename to packages/puppeteer-core/src/cdp/Coverage.ts index b64a308ff52..54dc508b7a6 100644 --- a/packages/puppeteer-core/src/common/Coverage.ts +++ b/packages/puppeteer-core/src/cdp/Coverage.ts @@ -17,11 +17,10 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; +import {EventSubscription} from '../common/EventEmitter.js'; +import {debugError, PuppeteerURL} from '../common/util.js'; import {assert} from '../util/assert.js'; -import {EventSubscription} from './EventEmitter.js'; -import {debugError, PuppeteerURL} from './util.js'; - /** * The CoverageEntry class represents one entry of the coverage report. * @public diff --git a/packages/puppeteer-core/src/common/DeviceRequestPrompt.test.ts b/packages/puppeteer-core/src/cdp/DeviceRequestPrompt.test.ts similarity index 98% rename from packages/puppeteer-core/src/common/DeviceRequestPrompt.test.ts rename to packages/puppeteer-core/src/cdp/DeviceRequestPrompt.test.ts index f2522524f6e..cf18b07950a 100644 --- a/packages/puppeteer-core/src/common/DeviceRequestPrompt.test.ts +++ b/packages/puppeteer-core/src/cdp/DeviceRequestPrompt.test.ts @@ -19,15 +19,15 @@ import {describe, it} from 'node:test'; import expect from 'expect'; import {type CDPSessionEvents} from '../api/CDPSession.js'; +import {TimeoutError} from '../common/Errors.js'; +import {EventEmitter} from '../common/EventEmitter.js'; +import {TimeoutSettings} from '../common/TimeoutSettings.js'; import { DeviceRequestPrompt, DeviceRequestPromptDevice, DeviceRequestPromptManager, } from './DeviceRequestPrompt.js'; -import {TimeoutError} from './Errors.js'; -import {EventEmitter} from './EventEmitter.js'; -import {TimeoutSettings} from './TimeoutSettings.js'; class MockCDPSession extends EventEmitter { async send(): Promise {} diff --git a/packages/puppeteer-core/src/common/DeviceRequestPrompt.ts b/packages/puppeteer-core/src/cdp/DeviceRequestPrompt.ts similarity index 99% rename from packages/puppeteer-core/src/common/DeviceRequestPrompt.ts rename to packages/puppeteer-core/src/cdp/DeviceRequestPrompt.ts index a88015cdfac..5c10ff2fb2e 100644 --- a/packages/puppeteer-core/src/common/DeviceRequestPrompt.ts +++ b/packages/puppeteer-core/src/cdp/DeviceRequestPrompt.ts @@ -18,11 +18,10 @@ import type Protocol from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import {type WaitTimeoutOptions} from '../api/Page.js'; +import {type TimeoutSettings} from '../common/TimeoutSettings.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; -import {type TimeoutSettings} from './TimeoutSettings.js'; - /** * Device in a request prompt. * diff --git a/packages/puppeteer-core/src/common/Dialog.ts b/packages/puppeteer-core/src/cdp/Dialog.ts similarity index 100% rename from packages/puppeteer-core/src/common/Dialog.ts rename to packages/puppeteer-core/src/cdp/Dialog.ts diff --git a/packages/puppeteer-core/src/common/ElementHandle.ts b/packages/puppeteer-core/src/cdp/ElementHandle.ts similarity index 99% rename from packages/puppeteer-core/src/common/ElementHandle.ts rename to packages/puppeteer-core/src/cdp/ElementHandle.ts index 1c7346b62ad..a0fe4e4014f 100644 --- a/packages/puppeteer-core/src/common/ElementHandle.ts +++ b/packages/puppeteer-core/src/cdp/ElementHandle.ts @@ -19,6 +19,7 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import {type AutofillData, ElementHandle} from '../api/ElementHandle.js'; import {type Page, type ScreenshotOptions} from '../api/Page.js'; +import {debugError} from '../common/util.js'; import {assert} from '../util/assert.js'; import {throwIfDisposed} from '../util/decorators.js'; @@ -26,7 +27,6 @@ import {type CdpFrame} from './Frame.js'; import {type FrameManager} from './FrameManager.js'; import {type IsolatedWorld} from './IsolatedWorld.js'; import {CdpJSHandle} from './JSHandle.js'; -import {debugError} from './util.js'; /** * The CdpElementHandle extends ElementHandle now to keep compatibility diff --git a/packages/puppeteer-core/src/common/EmulationManager.ts b/packages/puppeteer-core/src/cdp/EmulationManager.ts similarity index 99% rename from packages/puppeteer-core/src/common/EmulationManager.ts rename to packages/puppeteer-core/src/cdp/EmulationManager.ts index 0552a61d177..593ac5a2bea 100644 --- a/packages/puppeteer-core/src/common/EmulationManager.ts +++ b/packages/puppeteer-core/src/cdp/EmulationManager.ts @@ -17,13 +17,12 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession, CDPSessionEvent} from '../api/CDPSession.js'; import {type GeolocationOptions, type MediaFeature} from '../api/Page.js'; +import {debugError} from '../common/util.js'; +import {type Viewport} from '../common/Viewport.js'; import {assert} from '../util/assert.js'; import {invokeAtMostOnceForArguments} from '../util/decorators.js'; import {isErrorLike} from '../util/ErrorLike.js'; -import {type Viewport} from './PuppeteerViewport.js'; -import {debugError} from './util.js'; - interface ViewportState { viewport?: Viewport; active: boolean; diff --git a/packages/puppeteer-core/src/common/ExecutionContext.ts b/packages/puppeteer-core/src/cdp/ExecutionContext.ts similarity index 92% rename from packages/puppeteer-core/src/common/ExecutionContext.ts rename to packages/puppeteer-core/src/cdp/ExecutionContext.ts index bb28c6973a7..19647b624c8 100644 --- a/packages/puppeteer-core/src/common/ExecutionContext.ts +++ b/packages/puppeteer-core/src/cdp/ExecutionContext.ts @@ -19,6 +19,17 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import type {ElementHandle} from '../api/ElementHandle.js'; import {type JSHandle} from '../api/JSHandle.js'; +import {LazyArg} from '../common/LazyArg.js'; +import {scriptInjector} from '../common/ScriptInjector.js'; +import {type EvaluateFunc, type HandleFor} from '../common/types.js'; +import { + PuppeteerURL, + createEvaluationError, + debugError, + getSourcePuppeteerURLIfAvailable, + isString, + valueFromRemoteObject, +} from '../common/util.js'; import type PuppeteerUtil from '../injected/injected.js'; import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js'; import {stringifyFunction} from '../util/Function.js'; @@ -28,17 +39,6 @@ import {Binding} from './Binding.js'; import {CdpElementHandle} from './ElementHandle.js'; import {type IsolatedWorld} from './IsolatedWorld.js'; import {CdpJSHandle} from './JSHandle.js'; -import {LazyArg} from './LazyArg.js'; -import {scriptInjector} from './ScriptInjector.js'; -import {type EvaluateFunc, type HandleFor} from './types.js'; -import { - PuppeteerURL, - createEvaluationError, - createCdpHandle, - getSourcePuppeteerURLIfAvailable, - isString, - valueFromRemoteObject, -} from './util.js'; const SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m; @@ -391,3 +391,35 @@ const rewriteError = (error: Error): Protocol.Runtime.EvaluateResponse => { } throw error; }; + +/** + * @internal + */ +export function createCdpHandle( + realm: IsolatedWorld, + remoteObject: Protocol.Runtime.RemoteObject +): JSHandle | ElementHandle { + if (remoteObject.subtype === 'node') { + return new CdpElementHandle(realm, remoteObject); + } + return new CdpJSHandle(realm, remoteObject); +} + +/** + * @internal + */ +export async function releaseObject( + client: CDPSession, + remoteObject: Protocol.Runtime.RemoteObject +): Promise { + if (!remoteObject.objectId) { + return; + } + await client + .send('Runtime.releaseObject', {objectId: remoteObject.objectId}) + .catch(error => { + // Exceptions might happen in case of a page been navigated or closed. + // Swallow these since they are harmless and we don't leak anything in this case. + debugError(error); + }); +} diff --git a/packages/puppeteer-core/src/common/FirefoxTargetManager.ts b/packages/puppeteer-core/src/cdp/FirefoxTargetManager.ts similarity index 99% rename from packages/puppeteer-core/src/common/FirefoxTargetManager.ts rename to packages/puppeteer-core/src/cdp/FirefoxTargetManager.ts index 5d86a07f823..06842cdbdcb 100644 --- a/packages/puppeteer-core/src/common/FirefoxTargetManager.ts +++ b/packages/puppeteer-core/src/cdp/FirefoxTargetManager.ts @@ -18,11 +18,11 @@ import {type Protocol} from 'devtools-protocol'; import {type TargetFilterCallback} from '../api/Browser.js'; import {type CDPSession, CDPSessionEvent} from '../api/CDPSession.js'; +import {EventEmitter} from '../common/EventEmitter.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; import {type Connection} from './Connection.js'; -import {EventEmitter} from './EventEmitter.js'; import {type CdpTarget} from './Target.js'; import { type TargetFactory, diff --git a/packages/puppeteer-core/src/common/Frame.ts b/packages/puppeteer-core/src/cdp/Frame.ts similarity index 99% rename from packages/puppeteer-core/src/common/Frame.ts rename to packages/puppeteer-core/src/cdp/Frame.ts index 15031adf710..82ddba36dde 100644 --- a/packages/puppeteer-core/src/common/Frame.ts +++ b/packages/puppeteer-core/src/cdp/Frame.ts @@ -20,6 +20,7 @@ import {type CDPSession} from '../api/CDPSession.js'; import {Frame, FrameEvent, throwIfDetached} from '../api/Frame.js'; import {type HTTPResponse} from '../api/HTTPResponse.js'; import {type Page, type WaitTimeoutOptions} from '../api/Page.js'; +import {setPageContent} from '../common/util.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; import {isErrorLike} from '../util/ErrorLike.js'; @@ -35,7 +36,6 @@ import { LifecycleWatcher, type PuppeteerLifeCycleEvent, } from './LifecycleWatcher.js'; -import {setPageContent} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/FrameManager.ts b/packages/puppeteer-core/src/cdp/FrameManager.ts similarity index 98% rename from packages/puppeteer-core/src/common/FrameManager.ts rename to packages/puppeteer-core/src/cdp/FrameManager.ts index bceb3e54da9..480ca6f9a5b 100644 --- a/packages/puppeteer-core/src/common/FrameManager.ts +++ b/packages/puppeteer-core/src/cdp/FrameManager.ts @@ -19,6 +19,9 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession, CDPSessionEvent} from '../api/CDPSession.js'; import {FrameEvent} from '../api/Frame.js'; import {type Page} from '../api/Page.js'; +import {EventEmitter, type EventType} from '../common/EventEmitter.js'; +import {type TimeoutSettings} from '../common/TimeoutSettings.js'; +import {debugError, PuppeteerURL} from '../common/util.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; import {isErrorLike} from '../util/ErrorLike.js'; @@ -26,7 +29,6 @@ import {isErrorLike} from '../util/ErrorLike.js'; import {CdpCDPSession} from './CDPSession.js'; import {isTargetClosedError} from './Connection.js'; import {DeviceRequestPromptManager} from './DeviceRequestPrompt.js'; -import {EventEmitter, type EventType} from './EventEmitter.js'; import {ExecutionContext} from './ExecutionContext.js'; import {CdpFrame} from './Frame.js'; import {FrameTree} from './FrameTree.js'; @@ -34,8 +36,6 @@ import {type IsolatedWorld} from './IsolatedWorld.js'; import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; import {NetworkManager} from './NetworkManager.js'; import {type CdpTarget} from './Target.js'; -import {type TimeoutSettings} from './TimeoutSettings.js'; -import {debugError, PuppeteerURL} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/FrameTree.ts b/packages/puppeteer-core/src/cdp/FrameTree.ts similarity index 100% rename from packages/puppeteer-core/src/common/FrameTree.ts rename to packages/puppeteer-core/src/cdp/FrameTree.ts diff --git a/packages/puppeteer-core/src/common/HTTPRequest.ts b/packages/puppeteer-core/src/cdp/HTTPRequest.ts similarity index 99% rename from packages/puppeteer-core/src/common/HTTPRequest.ts rename to packages/puppeteer-core/src/cdp/HTTPRequest.ts index 26d15b30f9e..9d809d6b719 100644 --- a/packages/puppeteer-core/src/common/HTTPRequest.ts +++ b/packages/puppeteer-core/src/cdp/HTTPRequest.ts @@ -29,11 +29,10 @@ import { STATUS_TEXTS, } from '../api/HTTPRequest.js'; import {type HTTPResponse} from '../api/HTTPResponse.js'; +import {type ProtocolError} from '../common/Errors.js'; +import {debugError, isString} from '../common/util.js'; import {assert} from '../util/assert.js'; -import {type ProtocolError} from './Errors.js'; -import {debugError, isString} from './util.js'; - /** * @internal */ diff --git a/packages/puppeteer-core/src/common/HTTPResponse.ts b/packages/puppeteer-core/src/cdp/HTTPResponse.ts similarity index 97% rename from packages/puppeteer-core/src/common/HTTPResponse.ts rename to packages/puppeteer-core/src/cdp/HTTPResponse.ts index e62bc229770..ced72739eb3 100644 --- a/packages/puppeteer-core/src/common/HTTPResponse.ts +++ b/packages/puppeteer-core/src/cdp/HTTPResponse.ts @@ -18,11 +18,11 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import {type Frame} from '../api/Frame.js'; import {HTTPResponse, type RemoteAddress} from '../api/HTTPResponse.js'; +import {ProtocolError} from '../common/Errors.js'; +import {SecurityDetails} from '../common/SecurityDetails.js'; import {Deferred} from '../util/Deferred.js'; -import {ProtocolError} from './Errors.js'; import {type CdpHTTPRequest} from './HTTPRequest.js'; -import {SecurityDetails} from './SecurityDetails.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/Input.ts b/packages/puppeteer-core/src/cdp/Input.ts similarity index 99% rename from packages/puppeteer-core/src/common/Input.ts rename to packages/puppeteer-core/src/cdp/Input.ts index d6097b87077..8fb1faa65cd 100644 --- a/packages/puppeteer-core/src/common/Input.ts +++ b/packages/puppeteer-core/src/cdp/Input.ts @@ -31,13 +31,12 @@ import { Touchscreen, type KeyboardTypeOptions, } from '../api/Input.js'; -import {assert} from '../util/assert.js'; - import { _keyDefinitions, type KeyDefinition, type KeyInput, -} from './USKeyboardLayout.js'; +} from '../common/USKeyboardLayout.js'; +import {assert} from '../util/assert.js'; type KeyDescription = Required< Pick diff --git a/packages/puppeteer-core/src/common/IsolatedWorld.ts b/packages/puppeteer-core/src/cdp/IsolatedWorld.ts similarity index 88% rename from packages/puppeteer-core/src/common/IsolatedWorld.ts rename to packages/puppeteer-core/src/cdp/IsolatedWorld.ts index 74769b8ade9..fc6e6625cc0 100644 --- a/packages/puppeteer-core/src/common/IsolatedWorld.ts +++ b/packages/puppeteer-core/src/cdp/IsolatedWorld.ts @@ -19,58 +19,25 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import {type JSHandle} from '../api/JSHandle.js'; import {Realm} from '../api/Realm.js'; -import {Deferred} from '../util/Deferred.js'; - -import {type Binding} from './Binding.js'; -import {type ExecutionContext} from './ExecutionContext.js'; -import {CdpFrame} from './Frame.js'; -import {type MAIN_WORLD, type PUPPETEER_WORLD} from './IsolatedWorlds.js'; -import {type TimeoutSettings} from './TimeoutSettings.js'; +import {type TimeoutSettings} from '../common/TimeoutSettings.js'; import { type BindingPayload, type EvaluateFunc, type HandleFor, -} from './types.js'; +} from '../common/types.js'; import { - addPageBinding, - createCdpHandle, - debugError, Mutex, + addPageBinding, + debugError, withSourcePuppeteerURLIfNone, -} from './util.js'; -import {type WebWorker} from './WebWorker.js'; +} from '../common/util.js'; +import {Deferred} from '../util/Deferred.js'; -/** - * @public - */ -export interface WaitForSelectorOptions { - /** - * Wait for the selected element to be present in DOM and to be visible, i.e. - * to not have `display: none` or `visibility: hidden` CSS properties. - * - * @defaultValue `false` - */ - visible?: boolean; - /** - * Wait for the selected element to not be found in the DOM or to be hidden, - * i.e. have `display: none` or `visibility: hidden` CSS properties. - * - * @defaultValue `false` - */ - hidden?: boolean; - /** - * Maximum time to wait in milliseconds. Pass `0` to disable timeout. - * - * The default value can be changed by using {@link Page.setDefaultTimeout} - * - * @defaultValue `30_000` (30 seconds) - */ - timeout?: number; - /** - * A signal object that allows you to cancel a waitForSelector call. - */ - signal?: AbortSignal; -} +import {type Binding} from './Binding.js'; +import {type ExecutionContext, createCdpHandle} from './ExecutionContext.js'; +import {CdpFrame} from './Frame.js'; +import {type MAIN_WORLD, type PUPPETEER_WORLD} from './IsolatedWorlds.js'; +import {type WebWorker} from './WebWorker.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/IsolatedWorlds.ts b/packages/puppeteer-core/src/cdp/IsolatedWorlds.ts similarity index 100% rename from packages/puppeteer-core/src/common/IsolatedWorlds.ts rename to packages/puppeteer-core/src/cdp/IsolatedWorlds.ts diff --git a/packages/puppeteer-core/src/common/JSHandle.ts b/packages/puppeteer-core/src/cdp/JSHandle.ts similarity index 95% rename from packages/puppeteer-core/src/common/JSHandle.ts rename to packages/puppeteer-core/src/cdp/JSHandle.ts index 32606ec4202..750192edf65 100644 --- a/packages/puppeteer-core/src/common/JSHandle.ts +++ b/packages/puppeteer-core/src/cdp/JSHandle.ts @@ -18,10 +18,11 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import {JSHandle} from '../api/JSHandle.js'; +import {valueFromRemoteObject} from '../common/util.js'; import type {CdpElementHandle} from './ElementHandle.js'; +import {releaseObject} from './ExecutionContext.js'; import {type IsolatedWorld} from './IsolatedWorld.js'; -import {releaseObject, valueFromRemoteObject} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/common/LifecycleWatcher.ts b/packages/puppeteer-core/src/cdp/LifecycleWatcher.ts similarity index 98% rename from packages/puppeteer-core/src/common/LifecycleWatcher.ts rename to packages/puppeteer-core/src/cdp/LifecycleWatcher.ts index 4da63d9793b..490d5b9c192 100644 --- a/packages/puppeteer-core/src/common/LifecycleWatcher.ts +++ b/packages/puppeteer-core/src/cdp/LifecycleWatcher.ts @@ -18,11 +18,11 @@ import type Protocol from 'devtools-protocol'; import {type Frame, FrameEvent} from '../api/Frame.js'; import {type HTTPResponse} from '../api/HTTPResponse.js'; +import {type TimeoutError} from '../common/Errors.js'; +import {EventSubscription} from '../common/EventEmitter.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; -import {type TimeoutError} from './Errors.js'; -import {EventSubscription} from './EventEmitter.js'; import {type CdpFrame} from './Frame.js'; import {FrameManagerEvent} from './FrameManager.js'; import {type CdpHTTPRequest} from './HTTPRequest.js'; diff --git a/packages/puppeteer-core/src/common/NetworkEventManager.ts b/packages/puppeteer-core/src/cdp/NetworkEventManager.ts similarity index 100% rename from packages/puppeteer-core/src/common/NetworkEventManager.ts rename to packages/puppeteer-core/src/cdp/NetworkEventManager.ts diff --git a/packages/puppeteer-core/src/common/NetworkManager.test.ts b/packages/puppeteer-core/src/cdp/NetworkManager.test.ts similarity index 99% rename from packages/puppeteer-core/src/common/NetworkManager.test.ts rename to packages/puppeteer-core/src/cdp/NetworkManager.test.ts index 873e17212e3..2b87e155cf3 100644 --- a/packages/puppeteer-core/src/common/NetworkManager.test.ts +++ b/packages/puppeteer-core/src/cdp/NetworkManager.test.ts @@ -21,8 +21,8 @@ import expect from 'expect'; import {type CDPSessionEvents} from '../api/CDPSession.js'; import {type HTTPRequest} from '../api/HTTPRequest.js'; import {type HTTPResponse} from '../api/HTTPResponse.js'; +import {EventEmitter} from '../common/EventEmitter.js'; -import {EventEmitter} from './EventEmitter.js'; import {type CdpFrame} from './Frame.js'; import {NetworkManager, NetworkManagerEvent} from './NetworkManager.js'; diff --git a/packages/puppeteer-core/src/common/NetworkManager.ts b/packages/puppeteer-core/src/cdp/NetworkManager.ts similarity index 99% rename from packages/puppeteer-core/src/common/NetworkManager.ts rename to packages/puppeteer-core/src/cdp/NetworkManager.ts index e08fb0f7b0b..ba23036eb0b 100644 --- a/packages/puppeteer-core/src/common/NetworkManager.ts +++ b/packages/puppeteer-core/src/cdp/NetworkManager.ts @@ -18,20 +18,20 @@ import type {Protocol} from 'devtools-protocol'; import {type CDPSession, CDPSessionEvent} from '../api/CDPSession.js'; import type {Frame} from '../api/Frame.js'; -import {assert} from '../util/assert.js'; - import { EventEmitter, EventSubscription, type EventType, -} from './EventEmitter.js'; +} from '../common/EventEmitter.js'; +import {debugError, isString} from '../common/util.js'; +import {assert} from '../util/assert.js'; + import {CdpHTTPRequest} from './HTTPRequest.js'; import {CdpHTTPResponse} from './HTTPResponse.js'; import { type FetchRequestId, NetworkEventManager, } from './NetworkEventManager.js'; -import {debugError, isString} from './util.js'; /** * @public @@ -52,6 +52,7 @@ export interface NetworkConditions { // Latency (ms) latency: number; } + /** * @public */ diff --git a/packages/puppeteer-core/src/common/Page.ts b/packages/puppeteer-core/src/cdp/Page.ts similarity index 98% rename from packages/puppeteer-core/src/common/Page.ts rename to packages/puppeteer-core/src/cdp/Page.ts index 15643922be7..608c7937f53 100644 --- a/packages/puppeteer-core/src/common/Page.ts +++ b/packages/puppeteer-core/src/cdp/Page.ts @@ -38,6 +38,30 @@ import { type WaitForOptions, type WaitTimeoutOptions, } from '../api/Page.js'; +import { + ConsoleMessage, + type ConsoleMessageType, +} from '../common/ConsoleMessage.js'; +import {TargetCloseError} from '../common/Errors.js'; +import {FileChooser} from '../common/FileChooser.js'; +import {type PDFOptions} from '../common/PDFOptions.js'; +import {type TaskQueue} from '../common/TaskQueue.js'; +import {TimeoutSettings} from '../common/TimeoutSettings.js'; +import {type BindingPayload, type HandleFor} from '../common/types.js'; +import { + createClientError, + debugError, + evaluationString, + getReadableAsBuffer, + getReadableFromProtocolStream, + isString, + pageBindingInitString, + validateDialogType, + valueFromRemoteObject, + waitForEvent, + waitWithTimeout, +} from '../common/util.js'; +import {type Viewport} from '../common/Viewport.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; import {isErrorLike} from '../util/ErrorLike.js'; @@ -46,13 +70,11 @@ import {Accessibility} from './Accessibility.js'; import {Binding} from './Binding.js'; import {CdpCDPSession} from './CDPSession.js'; import {isTargetClosedError} from './Connection.js'; -import {ConsoleMessage, type ConsoleMessageType} from './ConsoleMessage.js'; import {Coverage} from './Coverage.js'; import {type DeviceRequestPrompt} from './DeviceRequestPrompt.js'; import {CdpDialog} from './Dialog.js'; import {EmulationManager} from './EmulationManager.js'; -import {TargetCloseError} from './Errors.js'; -import {FileChooser} from './FileChooser.js'; +import {createCdpHandle, releaseObject} from './ExecutionContext.js'; import {type CdpFrame} from './Frame.js'; import {FrameManager, FrameManagerEvent} from './FrameManager.js'; import {CdpKeyboard, CdpMouse, CdpTouchscreen} from './Input.js'; @@ -62,29 +84,9 @@ import { type NetworkConditions, NetworkManagerEvent, } from './NetworkManager.js'; -import {type PDFOptions} from './PDFOptions.js'; -import {type Viewport} from './PuppeteerViewport.js'; import {type CdpTarget} from './Target.js'; import {TargetManagerEvent} from './TargetManager.js'; -import {type TaskQueue} from './TaskQueue.js'; -import {TimeoutSettings} from './TimeoutSettings.js'; import {Tracing} from './Tracing.js'; -import {type BindingPayload, type HandleFor} from './types.js'; -import { - createCdpHandle, - createClientError, - debugError, - evaluationString, - getReadableAsBuffer, - getReadableFromProtocolStream, - isString, - pageBindingInitString, - releaseObject, - validateDialogType, - valueFromRemoteObject, - waitForEvent, - waitWithTimeout, -} from './util.js'; import {WebWorker} from './WebWorker.js'; /** diff --git a/packages/puppeteer-core/src/common/PredefinedNetworkConditions.ts b/packages/puppeteer-core/src/cdp/PredefinedNetworkConditions.ts similarity index 100% rename from packages/puppeteer-core/src/common/PredefinedNetworkConditions.ts rename to packages/puppeteer-core/src/cdp/PredefinedNetworkConditions.ts diff --git a/packages/puppeteer-core/src/common/Puppeteer.ts b/packages/puppeteer-core/src/cdp/Puppeteer.ts similarity index 97% rename from packages/puppeteer-core/src/common/Puppeteer.ts rename to packages/puppeteer-core/src/cdp/Puppeteer.ts index 52df673868d..148331839b3 100644 --- a/packages/puppeteer-core/src/common/Puppeteer.ts +++ b/packages/puppeteer-core/src/cdp/Puppeteer.ts @@ -15,16 +15,16 @@ */ import {type Browser} from '../api/Browser.js'; +import {type ConnectionTransport} from '../common/ConnectionTransport.js'; +import { + type CustomQueryHandler, + customQueryHandlers, +} from '../common/CustomQueryHandler.js'; import { type BrowserConnectOptions, _connectToCdpBrowser, } from './BrowserConnector.js'; -import {type ConnectionTransport} from './ConnectionTransport.js'; -import { - type CustomQueryHandler, - customQueryHandlers, -} from './CustomQueryHandler.js'; /** * Settings that are common to the Puppeteer class, regardless of environment. diff --git a/packages/puppeteer-core/src/common/Target.ts b/packages/puppeteer-core/src/cdp/Target.ts similarity index 98% rename from packages/puppeteer-core/src/common/Target.ts rename to packages/puppeteer-core/src/cdp/Target.ts index ba3dd30dd65..48ed6e33f59 100644 --- a/packages/puppeteer-core/src/common/Target.ts +++ b/packages/puppeteer-core/src/cdp/Target.ts @@ -21,14 +21,14 @@ import type {BrowserContext} from '../api/BrowserContext.js'; import {type CDPSession} from '../api/CDPSession.js'; import {type Page, PageEvent} from '../api/Page.js'; import {Target, TargetType} from '../api/Target.js'; +import {type TaskQueue} from '../common/TaskQueue.js'; +import {debugError} from '../common/util.js'; +import {type Viewport} from '../common/Viewport.js'; import {Deferred} from '../util/Deferred.js'; import {CdpCDPSession} from './CDPSession.js'; import {CdpPage} from './Page.js'; -import {type Viewport} from './PuppeteerViewport.js'; import {type TargetManager} from './TargetManager.js'; -import {type TaskQueue} from './TaskQueue.js'; -import {debugError} from './util.js'; import {WebWorker} from './WebWorker.js'; /** diff --git a/packages/puppeteer-core/src/common/TargetManager.ts b/packages/puppeteer-core/src/cdp/TargetManager.ts similarity index 96% rename from packages/puppeteer-core/src/common/TargetManager.ts rename to packages/puppeteer-core/src/cdp/TargetManager.ts index 22caefd7648..6a4b4ef606c 100644 --- a/packages/puppeteer-core/src/common/TargetManager.ts +++ b/packages/puppeteer-core/src/cdp/TargetManager.ts @@ -17,8 +17,8 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; +import {type EventEmitter, type EventType} from '../common/EventEmitter.js'; -import {type EventEmitter, type EventType} from './EventEmitter.js'; import {type CdpTarget} from './Target.js'; /** diff --git a/packages/puppeteer-core/src/common/Tracing.ts b/packages/puppeteer-core/src/cdp/Tracing.ts similarity index 97% rename from packages/puppeteer-core/src/common/Tracing.ts rename to packages/puppeteer-core/src/cdp/Tracing.ts index ac9ffff0bde..2c01b20ae9c 100644 --- a/packages/puppeteer-core/src/common/Tracing.ts +++ b/packages/puppeteer-core/src/cdp/Tracing.ts @@ -14,12 +14,14 @@ * limitations under the License. */ import {type CDPSession} from '../api/CDPSession.js'; +import { + getReadableAsBuffer, + getReadableFromProtocolStream, +} from '../common/util.js'; import {assert} from '../util/assert.js'; import {Deferred} from '../util/Deferred.js'; import {isErrorLike} from '../util/ErrorLike.js'; -import {getReadableAsBuffer, getReadableFromProtocolStream} from './util.js'; - /** * @public */ diff --git a/packages/puppeteer-core/src/common/WebWorker.ts b/packages/puppeteer-core/src/cdp/WebWorker.ts similarity index 94% rename from packages/puppeteer-core/src/common/WebWorker.ts rename to packages/puppeteer-core/src/cdp/WebWorker.ts index 6631a31657f..667a62757de 100644 --- a/packages/puppeteer-core/src/common/WebWorker.ts +++ b/packages/puppeteer-core/src/cdp/WebWorker.ts @@ -17,15 +17,15 @@ import {type Protocol} from 'devtools-protocol'; import {type CDPSession} from '../api/CDPSession.js'; import {type Realm} from '../api/Realm.js'; +import {type ConsoleMessageType} from '../common/ConsoleMessage.js'; +import {EventEmitter, type EventType} from '../common/EventEmitter.js'; +import {TimeoutSettings} from '../common/TimeoutSettings.js'; +import {type EvaluateFunc, type HandleFor} from '../common/types.js'; +import {debugError, withSourcePuppeteerURLIfNone} from '../common/util.js'; -import {type ConsoleMessageType} from './ConsoleMessage.js'; -import {EventEmitter, type EventType} from './EventEmitter.js'; import {ExecutionContext} from './ExecutionContext.js'; import {IsolatedWorld} from './IsolatedWorld.js'; import {CdpJSHandle} from './JSHandle.js'; -import {TimeoutSettings} from './TimeoutSettings.js'; -import {type EvaluateFunc, type HandleFor} from './types.js'; -import {debugError, withSourcePuppeteerURLIfNone} from './util.js'; /** * @internal diff --git a/packages/puppeteer-core/src/cdp/cdp.ts b/packages/puppeteer-core/src/cdp/cdp.ts new file mode 100644 index 00000000000..7b07690adb9 --- /dev/null +++ b/packages/puppeteer-core/src/cdp/cdp.ts @@ -0,0 +1,51 @@ +/** + * Copyright 2023 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './Accessibility.js'; +export * from './AriaQueryHandler.js'; +export * from './Binding.js'; +export * from './Browser.js'; +export * from './BrowserConnector.js'; +export * from './CDPSession.js'; +export * from './ChromeTargetManager.js'; +export * from './Connection.js'; +export * from './Coverage.js'; +export * from './DeviceRequestPrompt.js'; +export * from './Dialog.js'; +export * from './ElementHandle.js'; +export * from './EmulationManager.js'; +export * from './ExecutionContext.js'; +export * from './FirefoxTargetManager.js'; +export * from './Frame.js'; +export * from './FrameManager.js'; +export * from './FrameTree.js'; +export * from './HTTPRequest.js'; +export * from './HTTPResponse.js'; +export * from './Input.js'; +export * from './IsolatedWorld.js'; +export * from './IsolatedWorlds.js'; +export * from './JSHandle.js'; +export * from './LifecycleWatcher.js'; +export * from './NetworkEventManager.js'; +export * from './NetworkManager.js'; +export * from './Page.js'; +export * from './PredefinedNetworkConditions.js'; +export * from './Puppeteer.js'; +export * from './Target.js'; +export * from './TargetManager.js'; +export * from './Tracing.js'; +export * from './WebWorker.js'; +export * from './cdp.js'; diff --git a/packages/puppeteer-core/src/common/Device.ts b/packages/puppeteer-core/src/common/Device.ts index b99154b2713..b0795108b60 100644 --- a/packages/puppeteer-core/src/common/Device.ts +++ b/packages/puppeteer-core/src/common/Device.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {type Viewport} from './PuppeteerViewport.js'; +import {type Viewport} from './Viewport.js'; /** * @public diff --git a/packages/puppeteer-core/src/common/GetQueryHandler.ts b/packages/puppeteer-core/src/common/GetQueryHandler.ts index 405f09e2c5d..1b599aeb3db 100644 --- a/packages/puppeteer-core/src/common/GetQueryHandler.ts +++ b/packages/puppeteer-core/src/common/GetQueryHandler.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import {ARIAQueryHandler} from './AriaQueryHandler.js'; +import {ARIAQueryHandler} from '../cdp/AriaQueryHandler.js'; + import {customQueryHandlers} from './CustomQueryHandler.js'; import {PierceQueryHandler} from './PierceQueryHandler.js'; import {PQueryHandler} from './PQueryHandler.js'; @@ -22,6 +23,9 @@ import type {QueryHandler} from './QueryHandler.js'; import {TextQueryHandler} from './TextQueryHandler.js'; import {XPathQueryHandler} from './XPathQueryHandler.js'; +/** + * @internal + */ export const BUILTIN_QUERY_HANDLERS = Object.freeze({ aria: ARIAQueryHandler, pierce: PierceQueryHandler, diff --git a/packages/puppeteer-core/src/common/QueryHandler.ts b/packages/puppeteer-core/src/common/QueryHandler.ts index 1831a21e8e3..609748e0369 100644 --- a/packages/puppeteer-core/src/common/QueryHandler.ts +++ b/packages/puppeteer-core/src/common/QueryHandler.ts @@ -16,12 +16,12 @@ import {ElementHandle} from '../api/ElementHandle.js'; import type {Frame} from '../api/Frame.js'; +import type {WaitForSelectorOptions} from '../api/Page.js'; import type PuppeteerUtil from '../injected/injected.js'; import {isErrorLike} from '../util/ErrorLike.js'; import {interpolateFunction, stringifyFunction} from '../util/Function.js'; import {transposeIterableHandle} from './HandleIterator.js'; -import type {WaitForSelectorOptions} from './IsolatedWorld.js'; import {LazyArg} from './LazyArg.js'; import type {Awaitable, AwaitableIterable} from './types.js'; diff --git a/packages/puppeteer-core/src/common/PuppeteerViewport.ts b/packages/puppeteer-core/src/common/Viewport.ts similarity index 97% rename from packages/puppeteer-core/src/common/PuppeteerViewport.ts rename to packages/puppeteer-core/src/common/Viewport.ts index 953b327c015..5edcac91f37 100644 --- a/packages/puppeteer-core/src/common/PuppeteerViewport.ts +++ b/packages/puppeteer-core/src/common/Viewport.ts @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + /** - * - * Sets the viewport of the page. * @public */ export interface Viewport { diff --git a/packages/puppeteer-core/src/common/common.ts b/packages/puppeteer-core/src/common/common.ts index f4dcf3c2dd6..e6444bc4e78 100644 --- a/packages/puppeteer-core/src/common/common.ts +++ b/packages/puppeteer-core/src/common/common.ts @@ -14,61 +14,34 @@ * limitations under the License. */ -export * from './Accessibility.js'; -export * from './AriaQueryHandler.js'; -export * from './Binding.js'; -export * from './Browser.js'; -export * from './BrowserConnector.js'; export * from './BrowserWebSocketTransport.js'; -export * from './CDPSession.js'; -export * from './ChromeTargetManager.js'; export * from './Configuration.js'; -export * from './Connection.js'; export * from './ConnectionTransport.js'; export * from './ConsoleMessage.js'; -export * from './Coverage.js'; export * from './CustomQueryHandler.js'; export * from './Debug.js'; export * from './Device.js'; -export * from './DeviceRequestPrompt.js'; -export * from './Dialog.js'; -export * from './ElementHandle.js'; -export * from './EmulationManager.js'; export * from './Errors.js'; export * from './EventEmitter.js'; -export * from './ExecutionContext.js'; export * from './FileChooser.js'; -export * from './FirefoxTargetManager.js'; -export * from './Frame.js'; -export * from './FrameManager.js'; -export * from './FrameTree.js'; -export * from './HTTPRequest.js'; -export * from './HTTPResponse.js'; -export * from './Input.js'; -export * from './IsolatedWorld.js'; -export * from './IsolatedWorlds.js'; -export * from './JSHandle.js'; +export * from './GetQueryHandler.js'; +export * from './HandleIterator.js'; export * from './LazyArg.js'; -export * from './LifecycleWatcher.js'; -export * from './NetworkEventManager.js'; -export * from './NetworkManager.js'; -export * from './NodeWebSocketTransport.js'; export * from './PDFOptions.js'; -export * from './Page.js'; -export * from './PredefinedNetworkConditions.js'; +export * from './PQueryHandler.js'; +export * from './PierceQueryHandler.js'; export * from './Product.js'; -export * from './Puppeteer.js'; -export * from './PuppeteerViewport.js'; export * from './QueryHandler.js'; +export * from './ScriptInjector.js'; export * from './SecurityDetails.js'; -export * from './Target.js'; -export * from './TargetManager.js'; export * from './TaskQueue.js'; +export * from './TextQueryHandler.js'; export * from './TimeoutSettings.js'; -export * from './Tracing.js'; export * from './USKeyboardLayout.js'; +export * from './Viewport.js'; export * from './WaitTask.js'; -export * from './WebWorker.js'; +export * from './XPathQueryHandler.js'; +export * from './common.js'; export * from './fetch.js'; export * from './types.js'; export * from './util.js'; diff --git a/packages/puppeteer-core/src/common/util.ts b/packages/puppeteer-core/src/common/util.ts index 9eda53ead38..eb0eac019af 100644 --- a/packages/puppeteer-core/src/common/util.ts +++ b/packages/puppeteer-core/src/common/util.ts @@ -25,8 +25,6 @@ import { type Observable, } from '../../third_party/rxjs/rxjs.js'; import type {CDPSession} from '../api/CDPSession.js'; -import type {ElementHandle} from '../api/ElementHandle.js'; -import type {JSHandle} from '../api/JSHandle.js'; import {type Page} from '../api/Page.js'; import {isNode} from '../environment.js'; import {assert} from '../util/assert.js'; @@ -34,11 +32,8 @@ import {Deferred} from '../util/Deferred.js'; import {isErrorLike} from '../util/ErrorLike.js'; import {debug} from './Debug.js'; -import {CdpElementHandle} from './ElementHandle.js'; import {TimeoutError} from './Errors.js'; import {EventSubscription} from './EventEmitter.js'; -import {type IsolatedWorld} from './IsolatedWorld.js'; -import {CdpJSHandle} from './JSHandle.js'; import {type Awaitable} from './types.js'; /** @@ -293,25 +288,6 @@ export function valueFromRemoteObject( return remoteObject.value; } -/** - * @internal - */ -export async function releaseObject( - client: CDPSession, - remoteObject: Protocol.Runtime.RemoteObject -): Promise { - if (!remoteObject.objectId) { - return; - } - await client - .send('Runtime.releaseObject', {objectId: remoteObject.objectId}) - .catch(error => { - // Exceptions might happen in case of a page been navigated or closed. - // Swallow these since they are harmless and we don't leak anything in this case. - debugError(error); - }); -} - /** * @internal */ @@ -380,19 +356,6 @@ export async function waitForEvent( } } -/** - * @internal - */ -export function createCdpHandle( - realm: IsolatedWorld, - remoteObject: Protocol.Runtime.RemoteObject -): JSHandle | ElementHandle { - if (remoteObject.subtype === 'node') { - return new CdpElementHandle(realm, remoteObject); - } - return new CdpJSHandle(realm, remoteObject); -} - /** * @internal */ diff --git a/packages/puppeteer-core/src/node/LaunchOptions.ts b/packages/puppeteer-core/src/node/LaunchOptions.ts index 0b0f8f268a0..ad9ba7ace79 100644 --- a/packages/puppeteer-core/src/node/LaunchOptions.ts +++ b/packages/puppeteer-core/src/node/LaunchOptions.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {type BrowserConnectOptions} from '../common/BrowserConnector.js'; +import {type BrowserConnectOptions} from '../cdp/BrowserConnector.js'; import {type Product} from '../common/Product.js'; /** diff --git a/packages/puppeteer-core/src/common/NodeWebSocketTransport.ts b/packages/puppeteer-core/src/node/NodeWebSocketTransport.ts similarity index 100% rename from packages/puppeteer-core/src/common/NodeWebSocketTransport.ts rename to packages/puppeteer-core/src/node/NodeWebSocketTransport.ts diff --git a/packages/puppeteer-core/src/node/ProductLauncher.ts b/packages/puppeteer-core/src/node/ProductLauncher.ts index eef368c3189..06bc36e9f6a 100644 --- a/packages/puppeteer-core/src/node/ProductLauncher.ts +++ b/packages/puppeteer-core/src/node/ProductLauncher.ts @@ -27,19 +27,19 @@ import { } from '@puppeteer/browsers'; import {type Browser, type BrowserCloseCallback} from '../api/Browser.js'; -import {CdpBrowser} from '../common/Browser.js'; -import {Connection} from '../common/Connection.js'; +import {CdpBrowser} from '../cdp/Browser.js'; +import {Connection} from '../cdp/Connection.js'; import {TimeoutError} from '../common/Errors.js'; -import {NodeWebSocketTransport as WebSocketTransport} from '../common/NodeWebSocketTransport.js'; import {type Product} from '../common/Product.js'; -import {type Viewport} from '../common/PuppeteerViewport.js'; import {debugError} from '../common/util.js'; +import {type Viewport} from '../common/Viewport.js'; import { type BrowserLaunchArgumentOptions, type ChromeReleaseChannel, type PuppeteerNodeLaunchOptions, } from './LaunchOptions.js'; +import {NodeWebSocketTransport as WebSocketTransport} from './NodeWebSocketTransport.js'; import {PipeTransport} from './PipeTransport.js'; import {type PuppeteerNode} from './PuppeteerNode.js'; @@ -335,9 +335,7 @@ export class ProductLauncher { } ): Promise { // TODO: use other options too. - const BiDi = await import( - /* webpackIgnore: true */ '../common/bidi/bidi.js' - ); + const BiDi = await import(/* webpackIgnore: true */ '../bidi/bidi.js'); const bidiConnection = await BiDi.connectBidiOverCdp(connection); return await BiDi.BidiBrowser.create({ connection: bidiConnection, @@ -368,9 +366,7 @@ export class ProductLauncher { opts.timeout )) + '/session'; const transport = await WebSocketTransport.create(browserWSEndpoint); - const BiDi = await import( - /* webpackIgnore: true */ '../common/bidi/bidi.js' - ); + const BiDi = await import(/* webpackIgnore: true */ '../bidi/bidi.js'); const bidiConnection = new BiDi.BidiConnection( browserWSEndpoint, transport, diff --git a/packages/puppeteer-core/src/node/PuppeteerNode.ts b/packages/puppeteer-core/src/node/PuppeteerNode.ts index 94d50333f40..f25a7a66744 100644 --- a/packages/puppeteer-core/src/node/PuppeteerNode.ts +++ b/packages/puppeteer-core/src/node/PuppeteerNode.ts @@ -23,14 +23,14 @@ import { } from '@puppeteer/browsers'; import {type Browser} from '../api/Browser.js'; -import {type BrowserConnectOptions} from '../common/BrowserConnector.js'; -import {type Configuration} from '../common/Configuration.js'; -import {type Product} from '../common/Product.js'; +import {type BrowserConnectOptions} from '../cdp/BrowserConnector.js'; import { type CommonPuppeteerSettings, type ConnectOptions, Puppeteer, -} from '../common/Puppeteer.js'; +} from '../cdp/Puppeteer.js'; +import {type Configuration} from '../common/Configuration.js'; +import {type Product} from '../common/Product.js'; import {PUPPETEER_REVISIONS} from '../revisions.js'; import {ChromeLauncher} from './ChromeLauncher.js'; diff --git a/packages/puppeteer-core/src/puppeteer-core.ts b/packages/puppeteer-core/src/puppeteer-core.ts index 08cb8092a51..40f903f308c 100644 --- a/packages/puppeteer-core/src/puppeteer-core.ts +++ b/packages/puppeteer-core/src/puppeteer-core.ts @@ -17,6 +17,7 @@ export {Protocol} from 'devtools-protocol'; export * from './api/api.js'; +export * from './cdp/cdp.js'; export * from './common/common.js'; export * from './node/node.js'; export * from './revisions.js'; diff --git a/test/src/TargetManager.spec.ts b/test/src/TargetManager.spec.ts index 0d3403d245e..a0b46a5b575 100644 --- a/test/src/TargetManager.spec.ts +++ b/test/src/TargetManager.spec.ts @@ -15,7 +15,7 @@ */ import expect from 'expect'; -import {type CdpBrowser} from 'puppeteer-core/internal/common/Browser.js'; +import {type CdpBrowser} from 'puppeteer-core/internal/cdp/Browser.js'; import {getTestState, launch} from './mocha-utils.js'; import {attachFrame} from './utils.js'; diff --git a/test/src/accessibility.spec.ts b/test/src/accessibility.spec.ts index bfdb709eadc..e13d567d921 100644 --- a/test/src/accessibility.spec.ts +++ b/test/src/accessibility.spec.ts @@ -17,7 +17,7 @@ import assert from 'assert'; import expect from 'expect'; -import {type SerializedAXNode} from 'puppeteer-core/internal/common/Accessibility.js'; +import {type SerializedAXNode} from 'puppeteer-core/internal/cdp/Accessibility.js'; import {getTestState, setupTestBrowserHooks} from './mocha-utils.js'; diff --git a/test/src/oopif.spec.ts b/test/src/oopif.spec.ts index d3219879f83..62f856eba3e 100644 --- a/test/src/oopif.spec.ts +++ b/test/src/oopif.spec.ts @@ -16,7 +16,7 @@ import expect from 'expect'; import {type BrowserContext} from 'puppeteer-core/internal/api/BrowserContext.js'; -import {type CdpTarget} from 'puppeteer-core/internal/common/Target.js'; +import {type CdpTarget} from 'puppeteer-core/internal/cdp/Target.js'; import {describeWithDebugLogs, getTestState, launch} from './mocha-utils.js'; import {attachFrame, detachFrame, navigateFrame} from './utils.js'; diff --git a/test/src/page.spec.ts b/test/src/page.spec.ts index ac9885c99fc..662ccf8d128 100644 --- a/test/src/page.spec.ts +++ b/test/src/page.spec.ts @@ -22,8 +22,8 @@ import expect from 'expect'; import {KnownDevices, TimeoutError} from 'puppeteer'; import {CDPSession} from 'puppeteer-core/internal/api/CDPSession.js'; import {type Metrics, type Page} from 'puppeteer-core/internal/api/Page.js'; +import {type CdpPage} from 'puppeteer-core/internal/cdp/Page.js'; import {type ConsoleMessage} from 'puppeteer-core/internal/common/ConsoleMessage.js'; -import {type CdpPage} from 'puppeteer-core/internal/common/Page.js'; import sinon from 'sinon'; import {getTestState, setupTestBrowserHooks} from './mocha-utils.js'; diff --git a/test/src/worker.spec.ts b/test/src/worker.spec.ts index 39504934535..8fb6e56fb03 100644 --- a/test/src/worker.spec.ts +++ b/test/src/worker.spec.ts @@ -15,8 +15,8 @@ */ import expect from 'expect'; +import {type WebWorker} from 'puppeteer-core/internal/cdp/WebWorker.js'; import {type ConsoleMessage} from 'puppeteer-core/internal/common/ConsoleMessage.js'; -import {type WebWorker} from 'puppeteer-core/internal/common/WebWorker.js'; import {getTestState, setupTestBrowserHooks} from './mocha-utils.js'; import {waitEvent} from './utils.js';