diff --git a/docs/api/puppeteer.elementhandle.autofill.md b/docs/api/puppeteer.elementhandle.autofill.md index 13a7306620a..2bd4c90fc74 100644 --- a/docs/api/puppeteer.elementhandle.autofill.md +++ b/docs/api/puppeteer.elementhandle.autofill.md @@ -10,7 +10,7 @@ If the element is a form input, you can use [ElementHandle.autofill()](./puppete ```typescript class ElementHandle { - autofill(data: AutofillData): Promise; + abstract autofill(data: AutofillData): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.click.md b/docs/api/puppeteer.elementhandle.click.md index a94f93ca078..568e9f40da9 100644 --- a/docs/api/puppeteer.elementhandle.click.md +++ b/docs/api/puppeteer.elementhandle.click.md @@ -10,7 +10,10 @@ This method scrolls element into view if needed, and then uses [Page.mouse](./pu ```typescript class ElementHandle { - click(this: ElementHandle, options?: ClickOptions): Promise; + abstract click( + this: ElementHandle, + options?: ClickOptions + ): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.contentframe.md b/docs/api/puppeteer.elementhandle.contentframe.md index 9a866ce2e49..925efd901ae 100644 --- a/docs/api/puppeteer.elementhandle.contentframe.md +++ b/docs/api/puppeteer.elementhandle.contentframe.md @@ -4,13 +4,13 @@ sidebar_label: ElementHandle.contentFrame # ElementHandle.contentFrame() method -Resolves the frame associated with the element. +Resolves the frame associated with the element, if any. Always exists for HTMLIFrameElements. #### Signature: ```typescript class ElementHandle { - contentFrame(this: ElementHandle): Promise; + abstract contentFrame(this: ElementHandle): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.contentframe_1.md b/docs/api/puppeteer.elementhandle.contentframe_1.md index cca79cec048..aabe37eceb7 100644 --- a/docs/api/puppeteer.elementhandle.contentframe_1.md +++ b/docs/api/puppeteer.elementhandle.contentframe_1.md @@ -8,7 +8,7 @@ sidebar_label: ElementHandle.contentFrame_1 ```typescript class ElementHandle { - contentFrame(): Promise; + abstract contentFrame(): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.hover.md b/docs/api/puppeteer.elementhandle.hover.md index af325f51d91..356742d3edf 100644 --- a/docs/api/puppeteer.elementhandle.hover.md +++ b/docs/api/puppeteer.elementhandle.hover.md @@ -10,7 +10,7 @@ This method scrolls element into view if needed, and then uses [Page](./puppetee ```typescript class ElementHandle { - hover(this: ElementHandle): Promise; + abstract hover(this: ElementHandle): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.md b/docs/api/puppeteer.elementhandle.md index ff8614347a7..e30a42bf300 100644 --- a/docs/api/puppeteer.elementhandle.md +++ b/docs/api/puppeteer.elementhandle.md @@ -9,7 +9,7 @@ ElementHandle represents an in-page DOM element. #### Signature: ```typescript -export declare class ElementHandle extends JSHandle +export declare abstract class ElementHandle extends JSHandle ``` **Extends:** [JSHandle](./puppeteer.jshandle.md)<ElementType> @@ -41,9 +41,9 @@ The constructor for this class is marked as internal. Third-party code should no ## Properties -| Property | Modifiers | Type | Description | -| -------- | --------------------- | ----------------------------- | ----------- | -| frame | readonly | [Frame](./puppeteer.frame.md) | | +| Property | Modifiers | Type | Description | +| -------- | --------------------- | ----------------------------- | ------------------------------------------ | +| frame | readonly | [Frame](./puppeteer.frame.md) | Frame corresponding to the current handle. | ## Methods @@ -60,7 +60,7 @@ The constructor for this class is marked as internal. Third-party code should no | [boxModel()](./puppeteer.elementhandle.boxmodel.md) | | This method returns boxes of the element, or null if the element is not visible. | | [click(this, options)](./puppeteer.elementhandle.click.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to click in the center of the element. If the element is detached from DOM, the method throws an error. | | [clickablePoint(offset)](./puppeteer.elementhandle.clickablepoint.md) | | Returns the middle point within an element unless a specific offset is provided. | -| [contentFrame(this)](./puppeteer.elementhandle.contentframe.md) | | Resolves the frame associated with the element. | +| [contentFrame(this)](./puppeteer.elementhandle.contentframe.md) | | Resolves the frame associated with the element, if any. Always exists for HTMLIFrameElements. | | [contentFrame()](./puppeteer.elementhandle.contentframe_1.md) | | | | [drag(this, target)](./puppeteer.elementhandle.drag.md) | | This method creates and captures a dragevent from the element. | | [dragAndDrop(this, target, options)](./puppeteer.elementhandle.draganddrop.md) | | This method triggers a dragenter, dragover, and drop on the element. | diff --git a/docs/api/puppeteer.elementhandle.press.md b/docs/api/puppeteer.elementhandle.press.md index acfb8cc55d3..c3267ef50af 100644 --- a/docs/api/puppeteer.elementhandle.press.md +++ b/docs/api/puppeteer.elementhandle.press.md @@ -10,7 +10,10 @@ Focuses the element, and then uses [Keyboard.down()](./puppeteer.keyboard.down.m ```typescript class ElementHandle { - press(key: KeyInput, options?: Readonly): Promise; + abstract press( + key: KeyInput, + options?: Readonly + ): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.tap.md b/docs/api/puppeteer.elementhandle.tap.md index 18eb8d08bbd..dcfdbe28f66 100644 --- a/docs/api/puppeteer.elementhandle.tap.md +++ b/docs/api/puppeteer.elementhandle.tap.md @@ -10,7 +10,7 @@ This method scrolls element into view if needed, and then uses [Touchscreen.tap( ```typescript class ElementHandle { - tap(this: ElementHandle): Promise; + abstract tap(this: ElementHandle): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.touchend.md b/docs/api/puppeteer.elementhandle.touchend.md index 037605aa2b4..02e6bba96dc 100644 --- a/docs/api/puppeteer.elementhandle.touchend.md +++ b/docs/api/puppeteer.elementhandle.touchend.md @@ -8,7 +8,7 @@ sidebar_label: ElementHandle.touchEnd ```typescript class ElementHandle { - touchEnd(this: ElementHandle): Promise; + abstract touchEnd(this: ElementHandle): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.touchmove.md b/docs/api/puppeteer.elementhandle.touchmove.md index f2221a7fc80..e55a741ddce 100644 --- a/docs/api/puppeteer.elementhandle.touchmove.md +++ b/docs/api/puppeteer.elementhandle.touchmove.md @@ -8,7 +8,7 @@ sidebar_label: ElementHandle.touchMove ```typescript class ElementHandle { - touchMove(this: ElementHandle): Promise; + abstract touchMove(this: ElementHandle): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.touchstart.md b/docs/api/puppeteer.elementhandle.touchstart.md index 2fda4fe719e..0dbfe450007 100644 --- a/docs/api/puppeteer.elementhandle.touchstart.md +++ b/docs/api/puppeteer.elementhandle.touchstart.md @@ -8,7 +8,7 @@ sidebar_label: ElementHandle.touchStart ```typescript class ElementHandle { - touchStart(this: ElementHandle): Promise; + abstract touchStart(this: ElementHandle): Promise; } ``` diff --git a/docs/api/puppeteer.elementhandle.type.md b/docs/api/puppeteer.elementhandle.type.md index 5682e3ee081..48bb67fa22e 100644 --- a/docs/api/puppeteer.elementhandle.type.md +++ b/docs/api/puppeteer.elementhandle.type.md @@ -12,7 +12,10 @@ To press a special key, like `Control` or `ArrowDown`, use [ElementHandle.press( ```typescript class ElementHandle { - type(text: string, options?: Readonly): Promise; + abstract type( + text: string, + options?: Readonly + ): Promise; } ``` diff --git a/docs/api/puppeteer.jshandle.aselement.md b/docs/api/puppeteer.jshandle.aselement.md index c2107434c56..f46bd4f58f3 100644 --- a/docs/api/puppeteer.jshandle.aselement.md +++ b/docs/api/puppeteer.jshandle.aselement.md @@ -10,7 +10,7 @@ Either `null` or the handle itself if the handle is an instance of [ElementHandl ```typescript class JSHandle { - asElement(): ElementHandle | null; + abstract asElement(): ElementHandle | null; } ``` diff --git a/docs/api/puppeteer.jshandle.dispose.md b/docs/api/puppeteer.jshandle.dispose.md index ec318903a32..a5d3a2efa46 100644 --- a/docs/api/puppeteer.jshandle.dispose.md +++ b/docs/api/puppeteer.jshandle.dispose.md @@ -10,7 +10,7 @@ Releases the object referenced by the handle for garbage collection. ```typescript class JSHandle { - dispose(): Promise; + abstract dispose(): Promise; } ``` diff --git a/docs/api/puppeteer.jshandle.evaluate.md b/docs/api/puppeteer.jshandle.evaluate.md index a888acd18cb..78b4b1df122 100644 --- a/docs/api/puppeteer.jshandle.evaluate.md +++ b/docs/api/puppeteer.jshandle.evaluate.md @@ -10,7 +10,7 @@ Evaluates the given function with the current handle as its first argument. ```typescript class JSHandle { - evaluate< + abstract evaluate< Params extends unknown[], Func extends EvaluateFuncWith = EvaluateFuncWith, >( diff --git a/docs/api/puppeteer.jshandle.evaluatehandle.md b/docs/api/puppeteer.jshandle.evaluatehandle.md index 4c5c35f5ffb..339f1cc452d 100644 --- a/docs/api/puppeteer.jshandle.evaluatehandle.md +++ b/docs/api/puppeteer.jshandle.evaluatehandle.md @@ -10,7 +10,7 @@ Evaluates the given function with the current handle as its first argument. ```typescript class JSHandle { - evaluateHandle< + abstract evaluateHandle< Params extends unknown[], Func extends EvaluateFuncWith = EvaluateFuncWith, >( diff --git a/docs/api/puppeteer.jshandle.getproperties.md b/docs/api/puppeteer.jshandle.getproperties.md index f6ddb06ca48..c0bf247a804 100644 --- a/docs/api/puppeteer.jshandle.getproperties.md +++ b/docs/api/puppeteer.jshandle.getproperties.md @@ -10,13 +10,13 @@ Gets a map of handles representing the properties of the current handle. ```typescript class JSHandle { - getProperties(): Promise>; + abstract getProperties(): Promise>>; } ``` **Returns:** -Promise<Map<string, [JSHandle](./puppeteer.jshandle.md)>> +Promise<Map<string, [JSHandle](./puppeteer.jshandle.md)<unknown>>> ## Example diff --git a/docs/api/puppeteer.jshandle.getproperty.md b/docs/api/puppeteer.jshandle.getproperty.md index 8493699f170..a2516f27b6c 100644 --- a/docs/api/puppeteer.jshandle.getproperty.md +++ b/docs/api/puppeteer.jshandle.getproperty.md @@ -10,7 +10,7 @@ Fetches a single property from the referenced object. ```typescript class JSHandle { - getProperty( + abstract getProperty( propertyName: HandleOr ): Promise>; } diff --git a/docs/api/puppeteer.jshandle.getproperty_1.md b/docs/api/puppeteer.jshandle.getproperty_1.md index a61431d4a6a..7c2c9f00c83 100644 --- a/docs/api/puppeteer.jshandle.getproperty_1.md +++ b/docs/api/puppeteer.jshandle.getproperty_1.md @@ -8,7 +8,7 @@ sidebar_label: JSHandle.getProperty_1 ```typescript class JSHandle { - getProperty(propertyName: string): Promise>; + abstract getProperty(propertyName: string): Promise>; } ``` diff --git a/docs/api/puppeteer.jshandle.getproperty_2.md b/docs/api/puppeteer.jshandle.getproperty_2.md deleted file mode 100644 index 09923079cbe..00000000000 --- a/docs/api/puppeteer.jshandle.getproperty_2.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -sidebar_label: JSHandle.getProperty_2 ---- - -# JSHandle.getProperty() method - -#### Signature: - -```typescript -class JSHandle { - getProperty( - propertyName: HandleOr - ): Promise>; -} -``` - -## Parameters - -| Parameter | Type | Description | -| ------------ | -------------------------------------------- | ----------- | -| propertyName | [HandleOr](./puppeteer.handleor.md)<K> | | - -**Returns:** - -Promise<[HandleFor](./puppeteer.handlefor.md)<T\[K\]>> diff --git a/docs/api/puppeteer.jshandle.jsonvalue.md b/docs/api/puppeteer.jshandle.jsonvalue.md index 6f33818ba28..33bf5f98a30 100644 --- a/docs/api/puppeteer.jshandle.jsonvalue.md +++ b/docs/api/puppeteer.jshandle.jsonvalue.md @@ -10,7 +10,7 @@ A vanilla object representing the serializable portions of the referenced object ```typescript class JSHandle { - jsonValue(): Promise; + abstract jsonValue(): Promise; } ``` diff --git a/docs/api/puppeteer.jshandle.md b/docs/api/puppeteer.jshandle.md index f5c50954d9c..46d29459354 100644 --- a/docs/api/puppeteer.jshandle.md +++ b/docs/api/puppeteer.jshandle.md @@ -13,7 +13,7 @@ Handles can be used as arguments for any evaluation function such as [Page.$eval #### Signature: ```typescript -export declare class JSHandle +export declare abstract class JSHandle ``` ## Remarks @@ -43,7 +43,6 @@ const windowHandle = await page.evaluateHandle(() => window); | [getProperties()](./puppeteer.jshandle.getproperties.md) | | Gets a map of handles representing the properties of the current handle. | | [getProperty(propertyName)](./puppeteer.jshandle.getproperty.md) | | Fetches a single property from the referenced object. | | [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | | -| [getProperty(propertyName)](./puppeteer.jshandle.getproperty_2.md) | | | | [jsonValue()](./puppeteer.jshandle.jsonvalue.md) | | A vanilla object representing the serializable portions of the referenced object. | | [remoteObject()](./puppeteer.jshandle.remoteobject.md) | | Provides access to the [Protocol.Runtime.RemoteObject](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject) backing this handle. | | [toString()](./puppeteer.jshandle.tostring.md) | | Returns a string representation of the JSHandle. | diff --git a/docs/api/puppeteer.jshandle.remoteobject.md b/docs/api/puppeteer.jshandle.remoteobject.md index 7c29daae1d6..f25a9bbacc0 100644 --- a/docs/api/puppeteer.jshandle.remoteobject.md +++ b/docs/api/puppeteer.jshandle.remoteobject.md @@ -10,7 +10,7 @@ Provides access to the [Protocol.Runtime.RemoteObject](https://chromedevtools.gi ```typescript class JSHandle { - remoteObject(): Protocol.Runtime.RemoteObject; + abstract remoteObject(): Protocol.Runtime.RemoteObject; } ``` diff --git a/docs/api/puppeteer.jshandle.tostring.md b/docs/api/puppeteer.jshandle.tostring.md index f077f2d1512..d2e950a8c93 100644 --- a/docs/api/puppeteer.jshandle.tostring.md +++ b/docs/api/puppeteer.jshandle.tostring.md @@ -10,7 +10,7 @@ Returns a string representation of the JSHandle. ```typescript class JSHandle { - toString(): string; + abstract toString(): string; } ``` diff --git a/packages/puppeteer-core/src/api/ElementHandle.ts b/packages/puppeteer-core/src/api/ElementHandle.ts index 7d8a1ef6d1c..571aa8d43a5 100644 --- a/packages/puppeteer-core/src/api/ElementHandle.ts +++ b/packages/puppeteer-core/src/api/ElementHandle.ts @@ -17,8 +17,6 @@ import {Protocol} from 'devtools-protocol'; import {Frame} from '../api/Frame.js'; -import {CDPSession} from '../common/Connection.js'; -import {ExecutionContext} from '../common/ExecutionContext.js'; import {getQueryHandlerAndSelector} from '../common/GetQueryHandler.js'; import {WaitForSelectorOptions} from '../common/IsolatedWorld.js'; import {LazyArg} from '../common/LazyArg.js'; @@ -39,9 +37,9 @@ import {assert} from '../util/assert.js'; import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js'; import { + KeyboardTypeOptions, KeyPressOptions, MouseClickOptions, - KeyboardTypeOptions, } from './Input.js'; import {JSHandle} from './JSHandle.js'; import {ScreenshotOptions} from './Page.js'; @@ -143,7 +141,7 @@ export interface Point { * @public */ -export class ElementHandle< +export abstract class ElementHandle< ElementType extends Node = Element, > extends JSHandle { /** @@ -242,6 +240,13 @@ export class ElementHandle< return this.handle.toString(); } + /** + * @internal + */ + override remoteObject(): Protocol.Runtime.RemoteObject { + return this.handle.remoteObject(); + } + /** * @internal */ @@ -254,22 +259,9 @@ export class ElementHandle< } /** - * @internal + * Frame corresponding to the current handle. */ - override executionContext(): ExecutionContext { - throw new Error('Not implemented'); - } - - /** - * @internal - */ - override get client(): CDPSession { - throw new Error('Not implemented'); - } - - get frame(): Frame { - throw new Error('Not implemented'); - } + abstract get frame(): Frame; /** * Queries the current element for an element matching the given selector. @@ -629,13 +621,11 @@ export class ElementHandle< } /** - * Resolves the frame associated with the element. + * Resolves the frame associated with the element, if any. Always exists for + * HTMLIFrameElements. */ - async contentFrame(this: ElementHandle): Promise; - async contentFrame(): Promise; - async contentFrame(): Promise { - throw new Error('Not implemented'); - } + abstract contentFrame(this: ElementHandle): Promise; + abstract contentFrame(): Promise; /** * Returns the middle point within an element unless a specific offset is provided. @@ -650,22 +640,17 @@ export class ElementHandle< * uses {@link Page} to hover over the center of the element. * If the element is detached from DOM, the method throws an error. */ - async hover(this: ElementHandle): Promise { - throw new Error('Not implemented'); - } + abstract hover(this: ElementHandle): Promise; /** * This method scrolls element into view if needed, and then * uses {@link Page | Page.mouse} to click in the center of the element. * If the element is detached from DOM, the method throws an error. */ - async click( + abstract click( this: ElementHandle, options?: ClickOptions ): Promise; - async click(this: ElementHandle): Promise { - throw new Error('Not implemented'); - } /** * This method creates and captures a dragevent from the element. @@ -807,21 +792,13 @@ export class ElementHandle< * {@link Touchscreen.tap} to tap in the center of the element. * If the element is detached from DOM, the method throws an error. */ - async tap(this: ElementHandle): Promise { - throw new Error('Not implemented'); - } + abstract tap(this: ElementHandle): Promise; - async touchStart(this: ElementHandle): Promise { - throw new Error('Not implemented'); - } + abstract touchStart(this: ElementHandle): Promise; - async touchMove(this: ElementHandle): Promise { - throw new Error('Not implemented'); - } + abstract touchMove(this: ElementHandle): Promise; - async touchEnd(this: ElementHandle): Promise { - throw new Error('Not implemented'); - } + abstract touchEnd(this: ElementHandle): Promise; /** * Calls {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus | focus} on the element. @@ -860,13 +837,10 @@ export class ElementHandle< * * @param options - Delay in milliseconds. Defaults to 0. */ - async type( + abstract type( text: string, options?: Readonly ): Promise; - async type(): Promise { - throw new Error('Not implemented'); - } /** * Focuses the element, and then uses {@link Keyboard.down} and {@link Keyboard.up}. @@ -882,13 +856,10 @@ export class ElementHandle< * @param key - Name of key to press, such as `ArrowLeft`. * See {@link KeyInput} for a list of all key names. */ - async press( + abstract press( key: KeyInput, options?: Readonly ): Promise; - async press(): Promise { - throw new Error('Not implemented'); - } /** * This method returns the bounding box of the element (relative to the main frame), @@ -1205,9 +1176,7 @@ export class ElementHandle< /** * @internal */ - assertElementHasWorld(): asserts this { - assert(this.executionContext()._world); - } + abstract assertElementHasWorld(): asserts this; /** * If the element is a form input, you can use {@link ElementHandle.autofill} @@ -1234,10 +1203,7 @@ export class ElementHandle< * }); * ``` */ - autofill(data: AutofillData): Promise; - autofill(): Promise { - throw new Error('Not implemented'); - } + abstract autofill(data: AutofillData): Promise; } /** diff --git a/packages/puppeteer-core/src/api/JSHandle.ts b/packages/puppeteer-core/src/api/JSHandle.ts index 20d53c6aae9..3b4635bcbd8 100644 --- a/packages/puppeteer-core/src/api/JSHandle.ts +++ b/packages/puppeteer-core/src/api/JSHandle.ts @@ -16,8 +16,6 @@ import Protocol from 'devtools-protocol'; -import {CDPSession} from '../common/Connection.js'; -import {ExecutionContext} from '../common/ExecutionContext.js'; import {EvaluateFuncWith, HandleFor, HandleOr} from '../common/types.js'; import {ElementHandle} from './ElementHandle.js'; @@ -43,7 +41,7 @@ import {ElementHandle} from './ElementHandle.js'; * * @public */ -export class JSHandle { +export abstract class JSHandle { /** * Used for nominally typing {@link JSHandle}. */ @@ -61,62 +59,36 @@ export class JSHandle { throw new Error('Not implemented'); } - /** - * @internal - */ - executionContext(): ExecutionContext { - throw new Error('Not implemented'); - } - - /** - * @internal - */ - get client(): CDPSession { - throw new Error('Not implemented'); - } - /** * Evaluates the given function with the current handle as its first argument. */ - async evaluate< + abstract evaluate< Params extends unknown[], Func extends EvaluateFuncWith = EvaluateFuncWith, >( pageFunction: Func | string, ...args: Params ): Promise>>; - async evaluate(): Promise { - throw new Error('Not implemented'); - } /** * Evaluates the given function with the current handle as its first argument. * */ - async evaluateHandle< + abstract evaluateHandle< Params extends unknown[], Func extends EvaluateFuncWith = EvaluateFuncWith, >( pageFunction: Func | string, ...args: Params ): Promise>>>; - async evaluateHandle(): Promise> { - throw new Error('Not implemented'); - } /** * Fetches a single property from the referenced object. */ - async getProperty( + abstract getProperty( propertyName: HandleOr ): Promise>; - async getProperty(propertyName: string): Promise>; - async getProperty( - propertyName: HandleOr - ): Promise>; - async getProperty(): Promise> { - throw new Error('Not implemented'); - } + abstract getProperty(propertyName: string): Promise>; /** * Gets a map of handles representing the properties of the current handle. @@ -136,9 +108,7 @@ export class JSHandle { * children; // holds elementHandles to all children of document.body * ``` */ - async getProperties(): Promise> { - throw new Error('Not implemented'); - } + abstract getProperties(): Promise>>; /** * A vanilla object representing the serializable portions of the @@ -148,24 +118,18 @@ export class JSHandle { * @remarks * If the object has a `toJSON` function, it **will not** be called. */ - async jsonValue(): Promise { - throw new Error('Not implemented'); - } + abstract jsonValue(): Promise; /** * Either `null` or the handle itself if the handle is an * instance of {@link ElementHandle}. */ - asElement(): ElementHandle | null { - throw new Error('Not implemented'); - } + abstract asElement(): ElementHandle | null; /** * Releases the object referenced by the handle for garbage collection. */ - async dispose(): Promise { - throw new Error('Not implemented'); - } + abstract dispose(): Promise; /** * Returns a string representation of the JSHandle. @@ -173,23 +137,17 @@ export class JSHandle { * @remarks * Useful during debugging. */ - toString(): string { - throw new Error('Not implemented'); - } + abstract toString(): string; /** * @internal */ - get id(): string | undefined { - throw new Error('Not implemented'); - } + abstract get id(): string | undefined; /** * Provides access to the * {@link https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject | Protocol.Runtime.RemoteObject} * backing this handle. */ - remoteObject(): Protocol.Runtime.RemoteObject { - throw new Error('Not implemented'); - } + abstract remoteObject(): Protocol.Runtime.RemoteObject; } diff --git a/packages/puppeteer-core/src/common/AriaQueryHandler.ts b/packages/puppeteer-core/src/common/AriaQueryHandler.ts index 7db917834df..4f22dc36db0 100644 --- a/packages/puppeteer-core/src/common/AriaQueryHandler.ts +++ b/packages/puppeteer-core/src/common/AriaQueryHandler.ts @@ -21,6 +21,7 @@ import {assert} from '../util/assert.js'; import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js'; import {CDPSession} from './Connection.js'; +import {CDPJSHandle} from './JSHandle.js'; import {QueryHandler, QuerySelector} from './QueryHandler.js'; import {AwaitableIterable} from './types.js'; @@ -105,7 +106,9 @@ export class ARIAQueryHandler extends QueryHandler { element: ElementHandle, selector: string ): AwaitableIterable> { - const context = element.executionContext(); + const context = ( + element as unknown as CDPJSHandle + ).executionContext(); const {name, role} = parseARIASelector(selector); const results = await queryAXTree(context._client, element, name, role); const world = context._world!; diff --git a/packages/puppeteer-core/src/common/ElementHandle.ts b/packages/puppeteer-core/src/common/ElementHandle.ts index 947d65ab986..ba8414442f2 100644 --- a/packages/puppeteer-core/src/common/ElementHandle.ts +++ b/packages/puppeteer-core/src/common/ElementHandle.ts @@ -76,14 +76,14 @@ export class CDPElementHandle< /** * @internal */ - override executionContext(): ExecutionContext { + executionContext(): ExecutionContext { return this.handle.executionContext(); } /** * @internal */ - override get client(): CDPSession { + get client(): CDPSession { return this.handle.client; } @@ -527,6 +527,10 @@ export class CDPElementHandle< card: data.creditCard, }); } + + override assertElementHasWorld(): asserts this { + assert(this.executionContext()._world); + } } function computeQuadArea(quad: Point[]): number { diff --git a/packages/puppeteer-core/src/common/ExecutionContext.ts b/packages/puppeteer-core/src/common/ExecutionContext.ts index bd734246bf2..e1def30719c 100644 --- a/packages/puppeteer-core/src/common/ExecutionContext.ts +++ b/packages/puppeteer-core/src/common/ExecutionContext.ts @@ -105,12 +105,14 @@ export class ExecutionContext { selector: string ): Promise> => { const results = ARIAQueryHandler.queryAll(element, selector); - return element.executionContext().evaluateHandle( - (...elements) => { - return elements; - }, - ...(await AsyncIterableUtil.collect(results)) - ); + return (element as unknown as CDPJSHandle) + .executionContext() + .evaluateHandle( + (...elements) => { + return elements; + }, + ...(await AsyncIterableUtil.collect(results)) + ); }) as (...args: unknown[]) => unknown) ), ]); diff --git a/packages/puppeteer-core/src/common/IsolatedWorld.ts b/packages/puppeteer-core/src/common/IsolatedWorld.ts index 8f8bcd61182..f9c0c1ce58f 100644 --- a/packages/puppeteer-core/src/common/IsolatedWorld.ts +++ b/packages/puppeteer-core/src/common/IsolatedWorld.ts @@ -29,6 +29,7 @@ import {ExecutionContext} from './ExecutionContext.js'; import {Frame} from './Frame.js'; import {FrameManager} from './FrameManager.js'; import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; +import {CDPJSHandle} from './JSHandle.js'; import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js'; import {TimeoutSettings} from './TimeoutSettings.js'; import { @@ -500,7 +501,7 @@ export class IsolatedWorld implements Realm { async adoptHandle>(handle: T): Promise { const context = await this.executionContext(); assert( - handle.executionContext() !== context, + (handle as unknown as CDPJSHandle).executionContext() !== context, 'Cannot adopt handle that already belongs to this execution context' ); const nodeInfo = await this.#client.send('DOM.describeNode', { @@ -511,7 +512,9 @@ export class IsolatedWorld implements Realm { async transferHandle>(handle: T): Promise { const context = await this.executionContext(); - if (handle.executionContext() === context) { + if ( + (handle as unknown as CDPJSHandle).executionContext() === context + ) { return handle; } const info = await this.#client.send('DOM.describeNode', { diff --git a/packages/puppeteer-core/src/common/JSHandle.ts b/packages/puppeteer-core/src/common/JSHandle.ts index a4a9e588d32..a54fb74eca4 100644 --- a/packages/puppeteer-core/src/common/JSHandle.ts +++ b/packages/puppeteer-core/src/common/JSHandle.ts @@ -51,11 +51,11 @@ export class CDPJSHandle extends JSHandle { this.#remoteObject = remoteObject; } - override executionContext(): ExecutionContext { + executionContext(): ExecutionContext { return this.#context; } - override get client(): CDPSession { + get client(): CDPSession { return this.#context._client; } diff --git a/packages/puppeteer-core/src/common/bidi/ElementHandle.ts b/packages/puppeteer-core/src/common/bidi/ElementHandle.ts index 8fd4bbc8619..f74283d66fe 100644 --- a/packages/puppeteer-core/src/common/bidi/ElementHandle.ts +++ b/packages/puppeteer-core/src/common/bidi/ElementHandle.ts @@ -67,7 +67,7 @@ export class ElementHandle< /** * @internal */ - override assertElementHasWorld(): asserts this { + assertElementHasWorld(): asserts this { // TODO: Should assert element has a Sandbox return; } diff --git a/packages/puppeteer-core/src/common/bidi/JSHandle.ts b/packages/puppeteer-core/src/common/bidi/JSHandle.ts index ed6b0322f0f..f0cd61b249b 100644 --- a/packages/puppeteer-core/src/common/bidi/JSHandle.ts +++ b/packages/puppeteer-core/src/common/bidi/JSHandle.ts @@ -15,6 +15,7 @@ */ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; +import Protocol from 'devtools-protocol'; import {ElementHandle} from '../../api/ElementHandle.js'; import {JSHandle as BaseJSHandle} from '../../api/JSHandle.js'; @@ -167,4 +168,8 @@ export class JSHandle extends BaseJSHandle { remoteValue(): Bidi.Script.RemoteValue { return this.#remoteValue; } + + override remoteObject(): Protocol.Runtime.RemoteObject { + throw new Error('Not available in WebDriver BiDi'); + } }